mirror of
https://github.com/golang/go
synced 2024-11-17 23:54:51 -07:00
go/build: bypass importGo if srcDir is in GOROOT/src
This fixes the builder flake observed in https://build.golang.org/log/84fe80f8f091b9cef639b3ae2422a673f1462810, which could be replicated by running GOPROXY=off GOPATH=$(mktemp -d) go test go/internal/srcimporter Updates #30228 Fixes #30760 Change-Id: Ibf8b7a2e211611960b074b74af91acd4f0196edb Reviewed-on: https://go-review.googlesource.com/c/go/+/166977 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
parent
8b2a2d0394
commit
9fedec79ed
@ -1002,6 +1002,7 @@ func (ctxt *Context) importGo(p *Package, path, srcDir string, mode ImportMode,
|
||||
}
|
||||
|
||||
// If modules are not enabled, then the in-process code works fine and we should keep using it.
|
||||
// TODO(bcmills): This assumes that the default is "auto" instead of "on".
|
||||
switch os.Getenv("GO111MODULE") {
|
||||
case "off":
|
||||
return errNoModules
|
||||
@ -1017,6 +1018,13 @@ func (ctxt *Context) importGo(p *Package, path, srcDir string, mode ImportMode,
|
||||
}
|
||||
}
|
||||
|
||||
// If the source directory is in GOROOT, then the in-process code works fine
|
||||
// and we should keep using it. Moreover, the 'go list' approach below doesn't
|
||||
// take standard-library vendoring into account and will fail.
|
||||
if _, ok := ctxt.hasSubdir(filepath.Join(ctxt.GOROOT, "src"), srcDir); ok {
|
||||
return errNoModules
|
||||
}
|
||||
|
||||
// For efficiency, if path is a standard library package, let the usual lookup code handle it.
|
||||
if ctxt.GOROOT != "" {
|
||||
dir := ctxt.joinPath(ctxt.GOROOT, "src", path)
|
||||
@ -1043,7 +1051,12 @@ func (ctxt *Context) importGo(p *Package, path, srcDir string, mode ImportMode,
|
||||
}
|
||||
|
||||
cmd := exec.Command("go", "list", "-compiler="+ctxt.Compiler, "-tags="+strings.Join(ctxt.BuildTags, ","), "-installsuffix="+ctxt.InstallSuffix, "-f={{.Dir}}\n{{.ImportPath}}\n{{.Root}}\n{{.Goroot}}\n", path)
|
||||
|
||||
// TODO(bcmills): This is wrong if srcDir is in a vendor directory, or if
|
||||
// srcDir is in some module dependency of the main module. The main module
|
||||
// chooses what the import paths mean: individual packages don't.
|
||||
cmd.Dir = srcDir
|
||||
|
||||
var stdout, stderr strings.Builder
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
|
Loading…
Reference in New Issue
Block a user