Skip to content

Commit

Permalink
clarify SelectedPackageTypes meaning and improve its usage (#30142)
Browse files Browse the repository at this point in the history
- document SelectedPackageTypes meaning
- simplify isPackageTypeSelected
  • Loading branch information
AndersonQ authored Feb 16, 2022
1 parent 2571b52 commit 18f1e2b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
5 changes: 3 additions & 2 deletions dev-tools/mage/crossbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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.
Expand Down
18 changes: 10 additions & 8 deletions dev-tools/mage/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,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 {
Expand Down

0 comments on commit 18f1e2b

Please sign in to comment.