Repository: istio/istio
File: tools/docker-builder/types.go (Go)

Code before:
	Targets []string `json:"targets"`
	// Base indicates if this is a base image or not
	Base bool `json:"base"`
	// EmulationRequired indicates if emulation is required when cross-compiling. It typically is not,
	// as most building in Istio is done outside of docker.
	// When this is set, cross-compile is disabled for components unless emulation is epxlicitly specified
	EmulationRequired bool `json:"emulationRequired"`
	// Platforms for which this image can be built.
	Platforms []string `json:"platforms"`
}

func (p ImagePlan) Dependencies() []string {
	v := []string{p.Dockerfile}
	v = append(v, p.Files...)
	v = append(v, p.Targets...)
	return v
}

func (p ImagePlan) CanBuildForPlatform(t string) bool {
	for _, platform := range p.Platforms {
		if platform == t {
			return true
		}
	}
	return false
}

type BuildPlan struct {
	Images []ImagePlan `json:"images"`
}

func (p BuildPlan) Targets() []string {
	tgts := sets.New("init") // All targets depend on init
	for _, img := range p.Images {
		tgts.InsertAll(img.Targets...)
	}
	return sets.SortedList(tgts)
}

func (p BuildPlan) Find(n string) *ImagePlan {
	for _, i := range p.Images {
		if i.Name == n {
			return &i
		}
	}
	return nil
}

// Define variants, which control the base image of an image.
// Tags will have the variant append (like 1.0-distroless).
// The DefaultVariant is a special variant that has no explicit tag (like 1.0); it

Review comment (suggestion):
This can be simplified

```suggestion
func (p ImagePlan) CanBuildForPlatform(t string) bool {
	return slices.Contains(p.Platforms, t)
}
```

Code after:
	// Targets list make targets that are ran and then copied into the image
	Targets []string `json:"targets"`
	// Base indicates if this is a base image or not
	Base bool `json:"base"`
	// EmulationRequired indicates if emulation is required when cross-compiling. It typically is not,
	// as most building in Istio is done outside of docker.
	// When this is set, cross-compile is disabled for components unless emulation is epxlicitly specified
	EmulationRequired bool `json:"emulationRequired"`
	// Platforms for which this image can be built.
	Platforms []string `json:"platforms"`
}

func (p ImagePlan) Dependencies() []string {
	v := []string{p.Dockerfile}
	v = append(v, p.Files...)
	v = append(v, p.Targets...)
	return v
}

func (p ImagePlan) CanBuildForPlatform(t string) bool {
	return slices.Contains(p.Platforms, t)
}

type BuildPlan struct {
	Images []ImagePlan `json:"images"`
}

func (p BuildPlan) Targets() []string {
	tgts := sets.New("init") // All targets depend on init
	for _, img := range p.Images {
		tgts.InsertAll(img.Targets...)
	}
	return sets.SortedList(tgts)
}

func (p BuildPlan) Find(n string) *ImagePlan {
	for _, i := range p.Images {
		if i.Name == n {
			return &i
		}
	}
	return nil
}

// Define variants, which control the base image of an image.
// Tags will have the variant append (like 1.0-distroless).
// The DefaultVariant is a special variant that has no explicit tag (like 1.0); it
// is not a unique variant though. Currently, it represents DebugVariant.
// If both DebugVariant and DefaultVariant are built, there will be a single build but multiple tags
const (
	// PrimaryVariant is the variant that DefaultVariant actually builds