diff --git a/dev-tools/mage/crossbuild.go b/dev-tools/mage/crossbuild.go index 7a08a035bc4c..a6bdd9324470 100644 --- a/dev-tools/mage/crossbuild.go +++ b/dev-tools/mage/crossbuild.go @@ -43,7 +43,8 @@ const defaultCrossBuildTarget = "golangCrossBuild" // See NewPlatformList for details about platform filtering expressions. var Platforms = BuildPlatforms.Defaults() -// SelectedPackageTypes is the list of package types +// SelectedPackageTypes is the list of package types. If empty, all packages types +// are considered to be selected (see isPackageTypeSelected). var SelectedPackageTypes []PackageType func init() { @@ -65,7 +66,7 @@ func init() { } } -// CrossBuildOption defines a option to the CrossBuild target. +// CrossBuildOption defines an option to the CrossBuild target. type CrossBuildOption func(params *crossBuildParams) // ImageSelectorFunc returns the name of the builder image. diff --git a/dev-tools/mage/pkg.go b/dev-tools/mage/pkg.go index f4381291cfee..7c8c782857b1 100644 --- a/dev-tools/mage/pkg.go +++ b/dev-tools/mage/pkg.go @@ -117,17 +117,19 @@ func Package() error { return nil } +// isPackageTypeSelected returns true if SelectedPackageTypes is empty or if +// pkgType is present on SelectedPackageTypes. It returns false otherwise. func isPackageTypeSelected(pkgType PackageType) bool { - if SelectedPackageTypes != nil { - selected := false - for _, t := range SelectedPackageTypes { - if t == pkgType { - selected = true - } + if len(SelectedPackageTypes) == 0 { + return true + } + + for _, t := range SelectedPackageTypes { + if t == pkgType { + return true } - return selected } - return true + return false } type packageBuilder struct {