@@ -42,10 +42,10 @@ var (
42
42
ModBinDir func () string // return effective bin directory
43
43
ModLookup func (parentPath string , parentIsStd bool , path string ) (dir , realPath string , err error ) // lookup effective meaning of import
44
44
ModPackageModuleInfo func (path string ) * modinfo.ModulePublic // return module info for Package struct
45
- ModImportPaths func (args []string ) []* search.Match // expand import paths
45
+ ModImportPaths func (ctx context. Context , args []string ) []* search.Match // expand import paths
46
46
ModPackageBuildInfo func (main string , deps []string ) string // return module info to embed in binary
47
47
ModInfoProg func (info string , isgccgo bool ) []byte // wrap module info in .go code for binary
48
- ModImportFromFiles func ([]string ) // update go.mod to add modules for imports in these files
48
+ ModImportFromFiles func (context. Context , []string ) // update go.mod to add modules for imports in these files
49
49
ModDirImportPath func (string ) string // return effective import path for directory
50
50
)
51
51
@@ -553,7 +553,7 @@ func ReloadPackageNoFlags(arg string, stk *ImportStack) *Package {
553
553
})
554
554
packageDataCache .Delete (p .ImportPath )
555
555
}
556
- return LoadImport (arg , base .Cwd , nil , stk , nil , 0 )
556
+ return LoadImport (context . TODO (), arg , base .Cwd , nil , stk , nil , 0 )
557
557
}
558
558
559
559
// dirToImportPath returns the pseudo-import path we use for a package
@@ -605,11 +605,11 @@ const (
605
605
// LoadImport does not set tool flags and should only be used by
606
606
// this package, as part of a bigger load operation, and by GOPATH-based "go get".
607
607
// TODO(rsc): When GOPATH-based "go get" is removed, unexport this function.
608
- func LoadImport (path , srcDir string , parent * Package , stk * ImportStack , importPos []token.Position , mode int ) * Package {
609
- return loadImport (nil , path , srcDir , parent , stk , importPos , mode )
608
+ func LoadImport (ctx context. Context , path , srcDir string , parent * Package , stk * ImportStack , importPos []token.Position , mode int ) * Package {
609
+ return loadImport (ctx , nil , path , srcDir , parent , stk , importPos , mode )
610
610
}
611
611
612
- func loadImport (pre * preload , path , srcDir string , parent * Package , stk * ImportStack , importPos []token.Position , mode int ) * Package {
612
+ func loadImport (ctx context. Context , pre * preload , path , srcDir string , parent * Package , stk * ImportStack , importPos []token.Position , mode int ) * Package {
613
613
if path == "" {
614
614
panic ("LoadImport called with empty package path" )
615
615
}
@@ -657,7 +657,7 @@ func loadImport(pre *preload, path, srcDir string, parent *Package, stk *ImportS
657
657
// Load package.
658
658
// loadPackageData may return bp != nil even if an error occurs,
659
659
// in order to return partial information.
660
- p .load (path , stk , importPos , bp , err )
660
+ p .load (ctx , path , stk , importPos , bp , err )
661
661
662
662
if ! cfg .ModulesEnabled && path != cleanImport (path ) {
663
663
p .Error = & PackageError {
@@ -1591,7 +1591,7 @@ func (p *Package) DefaultExecName() string {
1591
1591
// load populates p using information from bp, err, which should
1592
1592
// be the result of calling build.Context.Import.
1593
1593
// stk contains the import stack, not including path itself.
1594
- func (p * Package ) load (path string , stk * ImportStack , importPos []token.Position , bp * build.Package , err error ) {
1594
+ func (p * Package ) load (ctx context. Context , path string , stk * ImportStack , importPos []token.Position , bp * build.Package , err error ) {
1595
1595
p .copyBuild (bp )
1596
1596
1597
1597
// The localPrefix is the path we interpret ./ imports relative to.
@@ -1800,7 +1800,7 @@ func (p *Package) load(path string, stk *ImportStack, importPos []token.Position
1800
1800
if path == "C" {
1801
1801
continue
1802
1802
}
1803
- p1 := LoadImport (path , p .Dir , p , stk , p .Internal .Build .ImportPos [path ], ResolveImport )
1803
+ p1 := LoadImport (ctx , path , p .Dir , p , stk , p .Internal .Build .ImportPos [path ], ResolveImport )
1804
1804
1805
1805
path = p1 .ImportPath
1806
1806
importPaths [i ] = path
@@ -2073,7 +2073,7 @@ func PackageList(roots []*Package) []*Package {
2073
2073
// TestPackageList returns the list of packages in the dag rooted at roots
2074
2074
// as visited in a depth-first post-order traversal, including the test
2075
2075
// imports of the roots. This ignores errors in test packages.
2076
- func TestPackageList (roots []* Package ) []* Package {
2076
+ func TestPackageList (ctx context. Context , roots []* Package ) []* Package {
2077
2077
seen := map [* Package ]bool {}
2078
2078
all := []* Package {}
2079
2079
var walk func (* Package )
@@ -2089,7 +2089,7 @@ func TestPackageList(roots []*Package) []*Package {
2089
2089
}
2090
2090
walkTest := func (root * Package , path string ) {
2091
2091
var stk ImportStack
2092
- p1 := LoadImport (path , root .Dir , root , & stk , root .Internal .Build .TestImportPos [path ], ResolveImport )
2092
+ p1 := LoadImport (ctx , path , root .Dir , root , & stk , root .Internal .Build .TestImportPos [path ], ResolveImport )
2093
2093
if p1 .Error == nil {
2094
2094
walk (p1 )
2095
2095
}
@@ -2112,7 +2112,7 @@ func TestPackageList(roots []*Package) []*Package {
2112
2112
// TODO(jayconrod): delete this function and set flags automatically
2113
2113
// in LoadImport instead.
2114
2114
func LoadImportWithFlags (path , srcDir string , parent * Package , stk * ImportStack , importPos []token.Position , mode int ) * Package {
2115
- p := LoadImport (path , srcDir , parent , stk , importPos , mode )
2115
+ p := LoadImport (context . TODO (), path , srcDir , parent , stk , importPos , mode )
2116
2116
setToolFlags (p )
2117
2117
return p
2118
2118
}
@@ -2153,12 +2153,12 @@ func PackagesAndErrors(ctx context.Context, patterns []string) []*Package {
2153
2153
// We need to test whether the path is an actual Go file and not a
2154
2154
// package path or pattern ending in '.go' (see golang.org/issue/34653).
2155
2155
if fi , err := os .Stat (p ); err == nil && ! fi .IsDir () {
2156
- return []* Package {GoFilesPackage (patterns )}
2156
+ return []* Package {GoFilesPackage (ctx , patterns )}
2157
2157
}
2158
2158
}
2159
2159
}
2160
2160
2161
- matches := ImportPaths (patterns )
2161
+ matches := ImportPaths (ctx , patterns )
2162
2162
var (
2163
2163
pkgs []* Package
2164
2164
stk ImportStack
@@ -2174,7 +2174,7 @@ func PackagesAndErrors(ctx context.Context, patterns []string) []*Package {
2174
2174
if pkg == "" {
2175
2175
panic (fmt .Sprintf ("ImportPaths returned empty package for pattern %s" , m .Pattern ()))
2176
2176
}
2177
- p := loadImport (pre , pkg , base .Cwd , nil , & stk , nil , 0 )
2177
+ p := loadImport (ctx , pre , pkg , base .Cwd , nil , & stk , nil , 0 )
2178
2178
p .Match = append (p .Match , m .Pattern ())
2179
2179
p .Internal .CmdlinePkg = true
2180
2180
if m .IsLiteral () {
@@ -2228,9 +2228,9 @@ func setToolFlags(pkgs ...*Package) {
2228
2228
}
2229
2229
}
2230
2230
2231
- func ImportPaths (args []string ) []* search.Match {
2231
+ func ImportPaths (ctx context. Context , args []string ) []* search.Match {
2232
2232
if ModInit (); cfg .ModulesEnabled {
2233
- return ModImportPaths (args )
2233
+ return ModImportPaths (ctx , args )
2234
2234
}
2235
2235
return search .ImportPaths (args )
2236
2236
}
@@ -2281,7 +2281,7 @@ func PackagesForBuild(ctx context.Context, args []string) []*Package {
2281
2281
// GoFilesPackage creates a package for building a collection of Go files
2282
2282
// (typically named on the command line). The target is named p.a for
2283
2283
// package p or named after the first Go file for package main.
2284
- func GoFilesPackage (gofiles []string ) * Package {
2284
+ func GoFilesPackage (ctx context. Context , gofiles []string ) * Package {
2285
2285
ModInit ()
2286
2286
2287
2287
for _ , f := range gofiles {
@@ -2329,7 +2329,7 @@ func GoFilesPackage(gofiles []string) *Package {
2329
2329
ctxt .ReadDir = func (string ) ([]os.FileInfo , error ) { return dirent , nil }
2330
2330
2331
2331
if cfg .ModulesEnabled {
2332
- ModImportFromFiles (gofiles )
2332
+ ModImportFromFiles (ctx , gofiles )
2333
2333
}
2334
2334
2335
2335
var err error
@@ -2345,7 +2345,7 @@ func GoFilesPackage(gofiles []string) *Package {
2345
2345
pkg := new (Package )
2346
2346
pkg .Internal .Local = true
2347
2347
pkg .Internal .CmdlineFiles = true
2348
- pkg .load ("command-line-arguments" , & stk , nil , bp , err )
2348
+ pkg .load (ctx , "command-line-arguments" , & stk , nil , bp , err )
2349
2349
pkg .Internal .LocalPrefix = dirToImportPath (dir )
2350
2350
pkg .ImportPath = "command-line-arguments"
2351
2351
pkg .Target = ""
0 commit comments