diff options
author | Jay Conrod <jayconrod@google.com> | 2019-05-31 14:14:00 -0400 |
---|---|---|
committer | Jay Conrod <jayconrod@google.com> | 2019-05-31 23:00:43 +0000 |
commit | 6f7542e4cb6914e8b8d888f16d440feeb8e631d2 (patch) | |
tree | edb490d9208d53c74270f2371e563353c76f168d /src/cmd/go/internal/modload/load.go | |
parent | 64c134f90f0cf6d0e55fca93c433b68810d12f12 (diff) | |
download | go-6f7542e4cb6914e8b8d888f16d440feeb8e631d2.tar.gz go-6f7542e4cb6914e8b8d888f16d440feeb8e631d2.zip |
cmd/go: ignore build tags when 'go get' modifies build list
In module mode, 'go get' should not consider build constraints when
loading packages in order to modify the module graph. With this
change, 'go get' considers all build tags to be true except for
"ignore" and malformed build constraint expressions.
When 'go get' builds packages, it still applies build constraints for
the target platform.
Fixes #32345
Change-Id: I6dceae6f10a5185870537de730b36292271ad124
Reviewed-on: https://go-review.googlesource.com/c/go/+/179898
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/modload/load.go')
-rw-r--r-- | src/cmd/go/internal/modload/load.go | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go index 022b3f3a4f..f05975d331 100644 --- a/src/cmd/go/internal/modload/load.go +++ b/src/cmd/go/internal/modload/load.go @@ -51,15 +51,19 @@ var buildList []module.Version var loaded *loader // ImportPaths returns the set of packages matching the args (patterns), -// adding modules to the build list as needed to satisfy new imports. +// on the target platform. Modules may be added to the build list +// to satisfy new imports. func ImportPaths(patterns []string) []*search.Match { - matches := ImportPathsQuiet(patterns) + matches := ImportPathsQuiet(patterns, imports.Tags()) search.WarnUnmatched(matches) return matches } -// ImportPathsQuiet is like ImportPaths but does not warn about patterns with no matches. -func ImportPathsQuiet(patterns []string) []*search.Match { +// ImportPathsQuiet is like ImportPaths but does not warn about patterns with +// no matches. It also lets the caller specify a set of build tags to match +// packages. The build tags should typically be imports.Tags() or +// imports.AnyTags(); a nil map has no special meaning. +func ImportPathsQuiet(patterns []string, tags map[string]bool) []*search.Match { var fsDirs [][]string updateMatches := func(matches []*search.Match, iterating bool) { for i, m := range matches { @@ -179,7 +183,7 @@ func ImportPathsQuiet(patterns []string) []*search.Match { }) } - loaded = newLoader() + loaded = newLoader(tags) loaded.load(func() []string { var roots []string updateMatches(matches, true) @@ -258,12 +262,13 @@ func warnPattern(pattern string, list []string) []string { func ImportFromFiles(gofiles []string) { InitMod() - imports, testImports, err := imports.ScanFiles(gofiles, imports.Tags()) + tags := imports.Tags() + imports, testImports, err := imports.ScanFiles(gofiles, tags) if err != nil { base.Fatalf("go: %v", err) } - loaded = newLoader() + loaded = newLoader(tags) loaded.load(func() []string { var roots []string roots = append(roots, imports...) @@ -312,7 +317,7 @@ func LoadBuildList() []module.Version { } func ReloadBuildList() []module.Version { - loaded = newLoader() + loaded = newLoader(imports.Tags()) loaded.load(func() []string { return nil }) return buildList } @@ -338,9 +343,8 @@ func LoadVendor() []string { func loadAll(testAll bool) []string { InitMod() - loaded = newLoader() + loaded = newLoader(imports.AnyTags()) loaded.isALL = true - loaded.tags = anyTags loaded.testAll = testAll if !testAll { loaded.testRoots = true @@ -359,15 +363,11 @@ func loadAll(testAll bool) []string { return paths } -// anyTags is a special tags map that satisfies nearly all build tag expressions. -// Only "ignore" and malformed build tag requirements are considered false. -var anyTags = map[string]bool{"*": true} - // TargetPackages returns the list of packages in the target (top-level) module // matching pattern, which may be relative to the working directory, under all // build tag settings. func TargetPackages(pattern string) []string { - return matchPackages(pattern, anyTags, false, []module.Version{Target}) + return matchPackages(pattern, imports.AnyTags(), false, []module.Version{Target}) } // BuildList returns the module build list, @@ -510,9 +510,9 @@ type loader struct { // LoadTests controls whether the loaders load tests of the root packages. var LoadTests bool -func newLoader() *loader { +func newLoader(tags map[string]bool) *loader { ld := new(loader) - ld.tags = imports.Tags() + ld.tags = tags ld.testRoots = LoadTests // Inside the "std" and "cmd" modules, we prefer to use the vendor directory |