@@ -355,14 +355,14 @@ func (p *Package) setLoadPackageDataError(err error, path string, stk *ImportSta
355355// can produce better error messages if it starts with the original paths.
356356// The initial load of p loads all the non-test imports and rewrites
357357// the vendored paths, so nothing should ever call p.vendored(p.Imports).
358- func (p * Package ) Resolve (loaderstate * modload.State , imports []string ) []string {
358+ func (p * Package ) Resolve (s * modload.State , imports []string ) []string {
359359 if len (imports ) > 0 && len (p .Imports ) > 0 && & imports [0 ] == & p .Imports [0 ] {
360360 panic ("internal error: p.Resolve(p.Imports) called" )
361361 }
362362 seen := make (map [string ]bool )
363363 var all []string
364364 for _ , path := range imports {
365- path = ResolveImportPath (loaderstate , p , path )
365+ path = ResolveImportPath (s , p , path )
366366 if ! seen [path ] {
367367 seen [path ] = true
368368 all = append (all , path )
@@ -1151,7 +1151,7 @@ func isDir(path string) bool {
11511151// First, there is Go 1.5 vendoring (golang.org/s/go15vendor).
11521152// If vendor expansion doesn't trigger, then the path is also subject to
11531153// Go 1.11 module legacy conversion (golang.org/issue/25069).
1154- func ResolveImportPath (loaderstate * modload.State , parent * Package , path string ) (found string ) {
1154+ func ResolveImportPath (s * modload.State , parent * Package , path string ) (found string ) {
11551155 var parentPath , parentDir , parentRoot string
11561156 parentIsStd := false
11571157 if parent != nil {
@@ -1160,12 +1160,12 @@ func ResolveImportPath(loaderstate *modload.State, parent *Package, path string)
11601160 parentRoot = parent .Root
11611161 parentIsStd = parent .Standard
11621162 }
1163- return resolveImportPath (loaderstate , path , parentPath , parentDir , parentRoot , parentIsStd )
1163+ return resolveImportPath (s , path , parentPath , parentDir , parentRoot , parentIsStd )
11641164}
11651165
1166- func resolveImportPath (loaderstate * modload.State , path , parentPath , parentDir , parentRoot string , parentIsStd bool ) (found string ) {
1166+ func resolveImportPath (s * modload.State , path , parentPath , parentDir , parentRoot string , parentIsStd bool ) (found string ) {
11671167 if cfg .ModulesEnabled {
1168- if _ , p , e := modload .Lookup (loaderstate , parentPath , parentIsStd , path ); e == nil {
1168+ if _ , p , e := modload .Lookup (s , parentPath , parentIsStd , path ); e == nil {
11691169 return p
11701170 }
11711171 return path
@@ -1935,7 +1935,7 @@ func (p *Package) load(loaderstate *modload.State, ctx context.Context, opts Pac
19351935
19361936 // The linker loads implicit dependencies.
19371937 if p .Name == "main" && ! p .Internal .ForceLibrary {
1938- ldDeps , err := LinkerDeps (p )
1938+ ldDeps , err := LinkerDeps (loaderstate , p )
19391939 if err != nil {
19401940 setError (err )
19411941 return
@@ -2635,12 +2635,12 @@ func SafeArg(name string) bool {
26352635}
26362636
26372637// LinkerDeps returns the list of linker-induced dependencies for main package p.
2638- func LinkerDeps (p * Package ) ([]string , error ) {
2638+ func LinkerDeps (s * modload. State , p * Package ) ([]string , error ) {
26392639 // Everything links runtime.
26402640 deps := []string {"runtime" }
26412641
26422642 // External linking mode forces an import of runtime/cgo.
2643- if what := externalLinkingReason (p ); what != "" && cfg .BuildContext .Compiler != "gccgo" {
2643+ if what := externalLinkingReason (s , p ); what != "" && cfg .BuildContext .Compiler != "gccgo" {
26442644 if ! cfg .BuildContext .CgoEnabled {
26452645 return nil , fmt .Errorf ("%s requires external (cgo) linking, but cgo is not enabled" , what )
26462646 }
@@ -2673,7 +2673,7 @@ func LinkerDeps(p *Package) ([]string, error) {
26732673// externalLinkingReason reports the reason external linking is required
26742674// even for programs that do not use cgo, or the empty string if external
26752675// linking is not required.
2676- func externalLinkingReason (p * Package ) (what string ) {
2676+ func externalLinkingReason (s * modload. State , p * Package ) (what string ) {
26772677 // Some targets must use external linking even inside GOROOT.
26782678 if platform .MustLinkExternal (cfg .Goos , cfg .Goarch , false ) {
26792679 return cfg .Goos + "/" + cfg .Goarch
@@ -2716,7 +2716,7 @@ func externalLinkingReason(p *Package) (what string) {
27162716 // Using -ldflags=-linkmode=external forces external linking.
27172717 // If there are multiple -linkmode options, the last one wins.
27182718 if p != nil {
2719- ldflags := BuildLdflags .For (p )
2719+ ldflags := BuildLdflags .For (s , p )
27202720 for i := len (ldflags ) - 1 ; i >= 0 ; i -- {
27212721 a := ldflags [i ]
27222722 if a == "-linkmode=external" ||
@@ -2842,15 +2842,15 @@ func TestPackageList(loaderstate *modload.State, ctx context.Context, opts Packa
28422842// in LoadImport instead.
28432843func LoadImportWithFlags (loaderstate * modload.State , path , srcDir string , parent * Package , stk * ImportStack , importPos []token.Position , mode int ) (* Package , * PackageError ) {
28442844 p , err := loadImport (loaderstate , context .TODO (), PackageOpts {}, nil , path , srcDir , parent , stk , importPos , mode )
2845- setToolFlags (p )
2845+ setToolFlags (loaderstate , p )
28462846 return p , err
28472847}
28482848
28492849// LoadPackageWithFlags is the same as LoadImportWithFlags but without a parent.
28502850// It's then guaranteed to not return an error
28512851func LoadPackageWithFlags (loaderstate * modload.State , path , srcDir string , stk * ImportStack , importPos []token.Position , mode int ) * Package {
28522852 p := LoadPackage (loaderstate , context .TODO (), PackageOpts {}, path , srcDir , stk , importPos , mode )
2853- setToolFlags (p )
2853+ setToolFlags (loaderstate , p )
28542854 return p
28552855}
28562856
@@ -2992,7 +2992,7 @@ func PackagesAndErrors(loaderstate *modload.State, ctx context.Context, opts Pac
29922992 // compute the effective flags for all loaded packages
29932993 // (not just the ones matching the patterns but also
29942994 // their dependencies).
2995- setToolFlags (pkgs ... )
2995+ setToolFlags (loaderstate , pkgs ... )
29962996
29972997 setPGOProfilePath (pkgs )
29982998
@@ -3231,12 +3231,12 @@ func (e *mainPackageError) ImportPath() string {
32313231 return e .importPath
32323232}
32333233
3234- func setToolFlags (pkgs ... * Package ) {
3234+ func setToolFlags (loaderstate * modload. State , pkgs ... * Package ) {
32353235 for _ , p := range PackageList (pkgs ) {
3236- p .Internal .Asmflags = BuildAsmflags .For (p )
3237- p .Internal .Gcflags = BuildGcflags .For (p )
3238- p .Internal .Ldflags = BuildLdflags .For (p )
3239- p .Internal .Gccgoflags = BuildGccgoflags .For (p )
3236+ p .Internal .Asmflags = BuildAsmflags .For (loaderstate , p )
3237+ p .Internal .Gcflags = BuildGcflags .For (loaderstate , p )
3238+ p .Internal .Ldflags = BuildLdflags .For (loaderstate , p )
3239+ p .Internal .Gccgoflags = BuildGccgoflags .For (loaderstate , p )
32403240 }
32413241}
32423242
@@ -3327,7 +3327,7 @@ func GoFilesPackage(loaderstate *modload.State, ctx context.Context, opts Packag
33273327 pkg .Error = & PackageError {Err : & mainPackageError {importPath : pkg .ImportPath }}
33283328 pkg .Incomplete = true
33293329 }
3330- setToolFlags (pkg )
3330+ setToolFlags (loaderstate , pkg )
33313331
33323332 return pkg
33333333}
@@ -3471,14 +3471,14 @@ func PackagesAndErrorsOutsideModule(loaderstate *modload.State, ctx context.Cont
34713471}
34723472
34733473// EnsureImport ensures that package p imports the named package.
3474- func EnsureImport (loaderstate * modload.State , p * Package , pkg string ) {
3474+ func EnsureImport (s * modload.State , p * Package , pkg string ) {
34753475 for _ , d := range p .Internal .Imports {
34763476 if d .Name == pkg {
34773477 return
34783478 }
34793479 }
34803480
3481- p1 , err := LoadImportWithFlags (loaderstate , pkg , p .Dir , p , & ImportStack {}, nil , 0 )
3481+ p1 , err := LoadImportWithFlags (s , pkg , p .Dir , p , & ImportStack {}, nil , 0 )
34823482 if err != nil {
34833483 base .Fatalf ("load %s: %v" , pkg , err )
34843484 }
@@ -3494,35 +3494,35 @@ func EnsureImport(loaderstate *modload.State, p *Package, pkg string) {
34943494// "go test -cover"). It walks through the packages being built (and
34953495// dependencies) and marks them for coverage instrumentation when
34963496// appropriate, and possibly adding additional deps where needed.
3497- func PrepareForCoverageBuild (loaderstate * modload.State , pkgs []* Package ) {
3498- var match []func (* Package ) bool
3497+ func PrepareForCoverageBuild (s * modload.State , pkgs []* Package ) {
3498+ var match []func (* modload. State , * Package ) bool
34993499
3500- matchMainModAndCommandLine := func (p * Package ) bool {
3500+ matchMainModAndCommandLine := func (_ * modload. State , p * Package ) bool {
35013501 // note that p.Standard implies p.Module == nil below.
35023502 return p .Internal .CmdlineFiles || p .Internal .CmdlinePkg || (p .Module != nil && p .Module .Main )
35033503 }
35043504
35053505 if len (cfg .BuildCoverPkg ) != 0 {
35063506 // If -coverpkg has been specified, then we instrument only
35073507 // the specific packages selected by the user-specified pattern(s).
3508- match = make ([]func (* Package ) bool , len (cfg .BuildCoverPkg ))
3508+ match = make ([]func (* modload. State , * Package ) bool , len (cfg .BuildCoverPkg ))
35093509 for i := range cfg .BuildCoverPkg {
3510- match [i ] = MatchPackage (loaderstate , cfg .BuildCoverPkg [i ], base .Cwd ())
3510+ match [i ] = MatchPackage (cfg .BuildCoverPkg [i ], base .Cwd ())
35113511 }
35123512 } else {
35133513 // Without -coverpkg, instrument only packages in the main module
35143514 // (if any), as well as packages/files specifically named on the
35153515 // command line.
3516- match = []func (* Package ) bool {matchMainModAndCommandLine }
3516+ match = []func (* modload. State , * Package ) bool {matchMainModAndCommandLine }
35173517 }
35183518
35193519 // Visit the packages being built or installed, along with all of
35203520 // their dependencies, and mark them to be instrumented, taking
35213521 // into account the matchers we've set up in the sequence above.
3522- SelectCoverPackages (loaderstate , PackageList (pkgs ), match , "build" )
3522+ SelectCoverPackages (s , PackageList (pkgs ), match , "build" )
35233523}
35243524
3525- func SelectCoverPackages (loaderstate * modload.State , roots []* Package , match []func (* Package ) bool , op string ) []* Package {
3525+ func SelectCoverPackages (s * modload.State , roots []* Package , match []func (* modload. State , * Package ) bool , op string ) []* Package {
35263526 var warntag string
35273527 var includeMain bool
35283528 switch op {
@@ -3540,7 +3540,7 @@ func SelectCoverPackages(loaderstate *modload.State, roots []*Package, match []f
35403540 for _ , p := range roots {
35413541 haveMatch := false
35423542 for i := range match {
3543- if match [i ](p ) {
3543+ if match [i ](s , p ) {
35443544 matched [i ] = true
35453545 haveMatch = true
35463546 }
@@ -3602,7 +3602,7 @@ func SelectCoverPackages(loaderstate *modload.State, roots []*Package, match []f
36023602
36033603 // Force import of sync/atomic into package if atomic mode.
36043604 if cfg .BuildCoverMode == "atomic" {
3605- EnsureImport (loaderstate , p , "sync/atomic" )
3605+ EnsureImport (s , p , "sync/atomic" )
36063606 }
36073607 }
36083608
0 commit comments