]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modload: embed PackageOpts in loaderParams
authorBryan C. Mills <bcmills@google.com>
Tue, 13 Oct 2020 14:58:13 +0000 (10:58 -0400)
committerBryan C. Mills <bcmills@google.com>
Tue, 27 Oct 2020 06:32:35 +0000 (06:32 +0000)
Instead of duplicating PackageOpts fields in the loaderParams struct,
embed the PackageOpts directly. Many of the fields are duplicated, and
further fields that would also be duplicated will be added in
subsequent changes.

For #36460

Change-Id: I3b0770d162e901d23ec1643183eb07c413d51e0a
Reviewed-on: https://go-review.googlesource.com/c/go/+/263138
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
src/cmd/go/internal/modload/buildlist.go
src/cmd/go/internal/modload/load.go

index 76e5fe01734fc319074987a5757c5237d628049a..4a183d6881be67c617f445f7bc6cfc6446283266 100644 (file)
@@ -78,7 +78,9 @@ func SetBuildList(list []module.Version) {
 // the build list set in SetBuildList.
 func ReloadBuildList() []module.Version {
        loaded = loadFromRoots(loaderParams{
-               tags:               imports.Tags(),
+               PackageOpts: PackageOpts{
+                       Tags: imports.Tags(),
+               },
                listRoots:          func() []string { return nil },
                allClosesOverTests: index.allPatternClosesOverTests(), // but doesn't matter because the root list is empty.
        })
index b770c19c7c8f6350fc6e42ea1fe6930acb7993e4..f9c468c8b2c32e291d71eeadf4555d970abf2c55 100644 (file)
@@ -250,9 +250,7 @@ func LoadPackages(ctx context.Context, opts PackageOpts, patterns ...string) (ma
        }
 
        loaded = loadFromRoots(loaderParams{
-               tags:           opts.Tags,
-               loadTests:      opts.LoadTests,
-               resolveMissing: opts.ResolveMissingImports,
+               PackageOpts: opts,
 
                allClosesOverTests: index.allPatternClosesOverTests() && !opts.UseVendorAll,
                allPatternIsRoot:   allPatternIsRoot,
@@ -505,8 +503,10 @@ func ImportFromFiles(ctx context.Context, gofiles []string) {
        }
 
        loaded = loadFromRoots(loaderParams{
-               tags:               tags,
-               resolveMissing:     true,
+               PackageOpts: PackageOpts{
+                       Tags:                  tags,
+                       ResolveMissingImports: true,
+               },
                allClosesOverTests: index.allPatternClosesOverTests(),
                listRoots: func() (roots []string) {
                        roots = append(roots, imports...)
@@ -659,10 +659,10 @@ type loader struct {
        direct map[string]bool // imported directly by main module
 }
 
+// loaderParams configure the packages loaded by, and the properties reported
+// by, a loader instance.
 type loaderParams struct {
-       tags           map[string]bool // tags for scanDir
-       loadTests      bool
-       resolveMissing bool
+       PackageOpts
 
        allClosesOverTests bool // Does the "all" pattern include the transitive closure of tests of packages in "all"?
        allPatternIsRoot   bool // Is the "all" pattern an additional root?
@@ -821,7 +821,7 @@ func loadFromRoots(params loaderParams) *loader {
 
                ld.buildStacks()
 
-               if !ld.resolveMissing || (!HasModRoot() && !allowMissingModuleImports) {
+               if !ld.ResolveMissingImports || (!HasModRoot() && !allowMissingModuleImports) {
                        // We've loaded as much as we can without resolving missing imports.
                        break
                }
@@ -864,7 +864,7 @@ func loadFromRoots(params loaderParams) *loader {
        // contributes “direct” imports — so we can't safely mark existing
        // dependencies as indirect-only.
        // Conservatively mark those dependencies as direct.
-       if modFile != nil && (!ld.allPatternIsRoot || !reflect.DeepEqual(ld.tags, imports.AnyTags())) {
+       if modFile != nil && (!ld.allPatternIsRoot || !reflect.DeepEqual(ld.Tags, imports.AnyTags())) {
                for _, r := range modFile.Require {
                        if !r.Indirect {
                                ld.direct[r.Mod.Path] = true
@@ -995,7 +995,7 @@ func (ld *loader) applyPkgFlags(pkg *loadPkg, flags loadPkgFlags) {
                        // also in "all" (as above).
                        wantTest = true
 
-               case ld.loadTests && new.has(pkgIsRoot):
+               case ld.LoadTests && new.has(pkgIsRoot):
                        // LoadTest explicitly requests tests of “the root packages”.
                        wantTest = true
                }
@@ -1058,7 +1058,7 @@ func (ld *loader) load(pkg *loadPkg) {
                ld.applyPkgFlags(pkg, pkgInAll)
        }
 
-       imports, testImports, err := scanDir(pkg.dir, ld.tags)
+       imports, testImports, err := scanDir(pkg.dir, ld.Tags)
        if err != nil {
                pkg.err = err
                return