@@ -51,15 +51,19 @@ var buildList []module.Version
5151var loaded * loader
5252
5353// ImportPaths returns the set of packages matching the args (patterns),
54- // adding modules to the build list as needed to satisfy new imports.
54+ // on the target platform. Modules may be added to the build list
55+ // to satisfy new imports.
5556func ImportPaths (patterns []string ) []* search.Match {
56- matches := ImportPathsQuiet (patterns )
57+ matches := ImportPathsQuiet (patterns , imports . Tags () )
5758 search .WarnUnmatched (matches )
5859 return matches
5960}
6061
61- // ImportPathsQuiet is like ImportPaths but does not warn about patterns with no matches.
62- func ImportPathsQuiet (patterns []string ) []* search.Match {
62+ // ImportPathsQuiet is like ImportPaths but does not warn about patterns with
63+ // no matches. It also lets the caller specify a set of build tags to match
64+ // packages. The build tags should typically be imports.Tags() or
65+ // imports.AnyTags(); a nil map has no special meaning.
66+ func ImportPathsQuiet (patterns []string , tags map [string ]bool ) []* search.Match {
6367 var fsDirs [][]string
6468 updateMatches := func (matches []* search.Match , iterating bool ) {
6569 for i , m := range matches {
@@ -179,7 +183,7 @@ func ImportPathsQuiet(patterns []string) []*search.Match {
179183 })
180184 }
181185
182- loaded = newLoader ()
186+ loaded = newLoader (tags )
183187 loaded .load (func () []string {
184188 var roots []string
185189 updateMatches (matches , true )
@@ -258,12 +262,13 @@ func warnPattern(pattern string, list []string) []string {
258262func ImportFromFiles (gofiles []string ) {
259263 InitMod ()
260264
261- imports , testImports , err := imports .ScanFiles (gofiles , imports .Tags ())
265+ tags := imports .Tags ()
266+ imports , testImports , err := imports .ScanFiles (gofiles , tags )
262267 if err != nil {
263268 base .Fatalf ("go: %v" , err )
264269 }
265270
266- loaded = newLoader ()
271+ loaded = newLoader (tags )
267272 loaded .load (func () []string {
268273 var roots []string
269274 roots = append (roots , imports ... )
@@ -312,7 +317,7 @@ func LoadBuildList() []module.Version {
312317}
313318
314319func ReloadBuildList () []module.Version {
315- loaded = newLoader ()
320+ loaded = newLoader (imports . Tags () )
316321 loaded .load (func () []string { return nil })
317322 return buildList
318323}
@@ -338,9 +343,8 @@ func LoadVendor() []string {
338343func loadAll (testAll bool ) []string {
339344 InitMod ()
340345
341- loaded = newLoader ()
346+ loaded = newLoader (imports . AnyTags () )
342347 loaded .isALL = true
343- loaded .tags = anyTags
344348 loaded .testAll = testAll
345349 if ! testAll {
346350 loaded .testRoots = true
@@ -359,15 +363,11 @@ func loadAll(testAll bool) []string {
359363 return paths
360364}
361365
362- // anyTags is a special tags map that satisfies nearly all build tag expressions.
363- // Only "ignore" and malformed build tag requirements are considered false.
364- var anyTags = map [string ]bool {"*" : true }
365-
366366// TargetPackages returns the list of packages in the target (top-level) module
367367// matching pattern, which may be relative to the working directory, under all
368368// build tag settings.
369369func TargetPackages (pattern string ) []string {
370- return matchPackages (pattern , anyTags , false , []module.Version {Target })
370+ return matchPackages (pattern , imports . AnyTags () , false , []module.Version {Target })
371371}
372372
373373// BuildList returns the module build list,
@@ -510,9 +510,9 @@ type loader struct {
510510// LoadTests controls whether the loaders load tests of the root packages.
511511var LoadTests bool
512512
513- func newLoader () * loader {
513+ func newLoader (tags map [ string ] bool ) * loader {
514514 ld := new (loader )
515- ld .tags = imports . Tags ()
515+ ld .tags = tags
516516 ld .testRoots = LoadTests
517517
518518 // Inside the "std" and "cmd" modules, we prefer to use the vendor directory
0 commit comments