// ValidatePlatform determines if a platform structure is valid.
// TODO This is a temporary function - can be replaced by parsing from
// https://github.com/containerd/containerd/pull/1403/files at a later date.
// @jhowardmsft
347072
func ValidatePlatform(platform *specs.Platform) error {
	platform.Architecture = strings.ToLower(platform.Architecture)
	platform.OS = strings.ToLower(platform.OS)
	// Based on https://github.com/moby/moby/pull/34642#issuecomment-330375350, do
	// not support anything except operating system.
	if platform.Architecture != "" {
		return fmt.Errorf("invalid platform architecture %q", platform.Architecture)
	}
	if platform.OS != "" {
		if !(platform.OS == runtime.GOOS || (LCOWSupported() && platform.OS == "linux")) {
			return fmt.Errorf("invalid platform os %q", platform.OS)
		}
	}
	if len(platform.OSFeatures) != 0 {
		return fmt.Errorf("invalid platform osfeatures %q", platform.OSFeatures)
	}
	if platform.OSVersion != "" {
		return fmt.Errorf("invalid platform osversion %q", platform.OSVersion)
	}
	if platform.Variant != "" {
		return fmt.Errorf("invalid platform variant %q", platform.Variant)
	}
	return nil
}
594670
func (p *PlatformFlag) Platforms(supported []Platform) []Platform {
	// NOTE: Reading this method alone is a bit hard to understand. It
	// is much easier to understand this method if you pair this with the
	// table of test cases it has.

	// Build a list of OS and archs NOT to build
	ignoreArch := make(map[string]struct{})
	includeArch := make(map[string]struct{})
	ignoreOS := make(map[string]struct{})
	includeOS := make(map[string]struct{})
	ignoreOSArch := make(map[string]Platform)
	includeOSArch := make(map[string]Platform)
	for _, v := range p.Arch {
		if v[0] == '!' {
			ignoreArch[v[1:]] = struct{}{}
		} else {
			includeArch[v] = struct{}{}
		}
	}
	for _, v := range p.OS {
		if v[0] == '!' {
			ignoreOS[v[1:]] = struct{}{}
		} else {
			includeOS[v] = struct{}{}
		}
	}
	for _, v := range p.OSArch {
		if v.OS[0] == '!' {
			v = Platform{
				OS:   v.OS[1:],
				Arch: v.Arch,
			}

			ignoreOSArch[v.String()] = v
		} else {
			includeOSArch[v.String()] = v
		}
	}

	// We're building a list of new platforms, so build the list
	// based only on the configured OS/arch pairs.
	var prefilter []Platform = nil
	if len(includeOSArch) > 0 {
		prefilter = make([]Platform, 0, len(p.Arch)*len(p.OS)+len(includeOSArch))
		for _, v := range includeOSArch {
			prefilter = append(prefilter, v)
		}
	}

	if len(includeOS) > 0 && len(includeArch) > 0 {
		// Build up the list of prefiltered by what is specified
		if prefilter == nil {
			prefilter = make([]Platform, 0, len(p.Arch)*len(p.OS))
		}

		for _, os := range p.OS {
			if _, ok := includeOS[os]; !ok {
				continue
			}

			for _, arch := range p.Arch {
				if _, ok := includeArch[arch]; !ok {
					continue
				}

				prefilter = append(prefilter, Platform{
					OS:   os,
					Arch: arch,
				})
			}
		}
	} else if len(includeOS) > 0 {
		// Build up the list of prefiltered by what is specified
		if prefilter == nil {
			prefilter = make([]Platform, 0, len(p.Arch)*len(p.OS))
		}

		for _, os := range p.OS {
			for _, platform := range supported {
				if platform.OS == os {
					prefilter = append(prefilter, platform)
				}
			}
		}
	}

	if prefilter != nil {
		// Remove any that aren't supported
		result := make([]Platform, 0, len(prefilter))
		for _, pending := range prefilter {
			found := false
			for _, platform := range supported {
				if pending.String() == platform.String() {
					found = true
					break
				}
			}

			if found {
				add := pending
				add.Default = false
				result = append(result, add)
			}
		}

		prefilter = result
	}

	if prefilter == nil {
		prefilter = make([]Platform, 0, len(supported))
		for _, v := range supported {
			if v.Default {
				add := v
				add.Default = false
				prefilter = append(prefilter, add)
			}
		}
	}

	// Go through each default platform and filter out the bad ones
	result := make([]Platform, 0, len(prefilter))
	for _, platform := range prefilter {
		if len(ignoreOSArch) > 0 {
			if _, ok := ignoreOSArch[platform.String()]; ok {
				continue
			}
		}

		// We only want to check the components (OS and Arch) if we didn't
		// specifically ask to include it via the osarch.
		checkComponents := true
		if len(includeOSArch) > 0 {
			if _, ok := includeOSArch[platform.String()]; ok {
				checkComponents = false
			}
		}

		if checkComponents {
			if len(ignoreArch) > 0 {
				if _, ok := ignoreArch[platform.Arch]; ok {
					continue
				}
			}
			if len(ignoreOS) > 0 {
				if _, ok := ignoreOS[platform.OS]; ok {
					continue
				}
			}
			if len(includeArch) > 0 {
				if _, ok := includeArch[platform.Arch]; !ok {
					continue
				}
			}
			if len(includeOS) > 0 {
				if _, ok := includeOS[platform.OS]; !ok {
					continue
				}
			}
		}

		result = append(result, platform)
	}

	return result
}
597966
func (s *ListSigningPlatformsOutput) SetPlatforms(v []*SigningPlatform) *ListSigningPlatformsOutput {
	s.Platforms = v
	return s
}
1183930
func (s *CreateEnvironmentInput) SetPlatformArn(v string) *CreateEnvironmentInput {
	s.PlatformArn = &v
	return s
}
162682
func FilterPlatforms(f HandlerFunc, m platforms.Matcher) HandlerFunc {
	return func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
		children, err := f(ctx, desc)
		if err != nil {
			return children, err
		}

		var descs []ocispec.Descriptor

		if m == nil {
			descs = children
		} else {
			for _, d := range children {
				if d.Platform == nil || m.Match(*d.Platform) {
					descs = append(descs, d)
				}
			}
		}

		return descs, nil
	}
}
989636
func validatePlatforms(c *validation.Context, cfg *configPB.Platforms) {
	// Platform names must be unique.
	// Keep records of ones we've already seen.
	names := stringset.New(len(cfg.Platform))
	for _, p := range cfg.Platform {
		switch {
		case p.Name == "":
			c.Errorf("platform names are required and must be non-empty")
		case !names.Add(p.Name):
			c.Errorf("duplicate platform %q", p.Name)
		}
	}
}
1068552
func (s *SegmentDemographics) SetPlatform(v *SetDimension) *SegmentDemographics {
	s.Platform = v
	return s
}
1229657
func (s *UpdateEnvironmentInput) SetPlatformArn(v string) *UpdateEnvironmentInput {
	s.PlatformArn = &v
	return s
}
126784
func (strategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
	return validation.ValidateBuild(obj.(*buildapi.Build))
}
1058259
func (s *Deployment) SetPlatformVersion(v string) *Deployment {
	s.PlatformVersion = &v
	return s
}
765980
func (s *EventDescription) SetPlatformArn(v string) *EventDescription {
	s.PlatformArn = &v
	return s
}
1235371
func (s *Service) initPlatform() error {
	if s.platform != nil {
		return nil
	}
	epoller, err := console.NewEpoller()
	if err != nil {
		return errors.Wrap(err, "failed to initialize epoller")
	}
	s.platform = &linuxPlatform{
		epoller: epoller,
	}
	go epoller.Wait()
	return nil
}
1074182
func EnsurePlatforms(c context.Context, cfgs []*config.Platform) (map[string]int64, error) {
	t := &PlatformsTable{}
	if err := t.fetch(c); err != nil {
		return nil, errors.Annotate(err, "failed to fetch platforms").Err()
	}
	t.computeChanges(c, cfgs)
	if err := t.add(c); err != nil {
		return nil, errors.Annotate(err, "failed to add platforms").Err()
	}
	if err := t.remove(c); err != nil {
		return nil, errors.Annotate(err, "failed to remove platforms").Err()
	}
	if err := t.update(c); err != nil {
		return nil, errors.Annotate(err, "failed to update platforms").Err()
	}
	return t.ids(c), nil
}
372190
func (s *systemInfo) Platform() (string, error) {
	err := s.collectPlatformInfo()
	if err != nil {
		return "", err
	}
	return s.platform, nil
}
723500
func (s *App) SetPlatform(v string) *App {
	s.Platform = &v
	return s
}
1036112
func (s *InstanceDetails) SetPlatform(v string) *InstanceDetails {
	s.Platform = &v
	return s
}
18808
func (o *APIResourceOptions) Validate() error {
	supportedOutputTypes := sets.NewString("", "wide", "name")
	if !supportedOutputTypes.Has(o.Output) {
		return fmt.Errorf("--output %v is not available", o.Output)
	}
	return nil
}