aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/load/pkg.go
diff options
context:
space:
mode:
authorKatie Hockman <katie@golang.org>2019-09-03 17:04:59 -0400
committerKatie Hockman <katie@golang.org>2019-09-03 17:05:23 -0400
commitff197f326fe607bba27a0b53e47b7a565601569d (patch)
tree231057ea72e8320005a0df17363b284777967451 /src/cmd/go/internal/load/pkg.go
parent5a1705286e8ec116645244978d9c54c5ba6dc448 (diff)
parent2ebc3d8157fedba633ce90c5454827512734a793 (diff)
downloadgo-ff197f326fe607bba27a0b53e47b7a565601569d.tar.gz
go-ff197f326fe607bba27a0b53e47b7a565601569d.zip
[dev.boringcrypto] all: merge master into dev.boringcrypto
Change-Id: I3cd94be655e5374b52494f756ff087352705da6d
Diffstat (limited to 'src/cmd/go/internal/load/pkg.go')
-rw-r--r--src/cmd/go/internal/load/pkg.go26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go
index 12bf0e1f7a..64267a4a46 100644
--- a/src/cmd/go/internal/load/pkg.go
+++ b/src/cmd/go/internal/load/pkg.go
@@ -64,7 +64,7 @@ type PackagePublic struct {
Doc string `json:",omitempty"` // package documentation string
Target string `json:",omitempty"` // installed target for this package (may be executable)
Shlib string `json:",omitempty"` // the shared library that contains this package (only set when -linkshared)
- Root string `json:",omitempty"` // Go root or Go path dir containing this package
+ Root string `json:",omitempty"` // Go root, Go path dir, or module root dir containing this package
ConflictDir string `json:",omitempty"` // Dir is hidden by this other directory
ForTest string `json:",omitempty"` // package is only for use in named test
Export string `json:",omitempty"` // file containing export data (set by go list -export)
@@ -177,8 +177,7 @@ type PackageInternal struct {
OmitDebug bool // tell linker not to write debug information
GobinSubdir bool // install target would be subdir of GOBIN
BuildInfo string // add this info to package main
- TestinginitGo []byte // content for _testinginit.go
- TestmainGo []byte // content for _testmain.go
+ TestmainGo *[]byte // content for _testmain.go
Asmflags []string // -asmflags for this package
Gcflags []string // -gcflags for this package
@@ -653,9 +652,14 @@ func loadPackageData(path, parentPath, parentDir, parentRoot string, parentIsStd
buildMode = build.ImportComment
}
data.p, data.err = cfg.BuildContext.ImportDir(r.dir, buildMode)
+ if data.p.Root == "" && cfg.ModulesEnabled {
+ if info := ModPackageModuleInfo(path); info != nil {
+ data.p.Root = info.Dir
+ }
+ }
} else if r.err != nil {
data.p = new(build.Package)
- data.err = fmt.Errorf("unknown import path %q: %v", r.path, r.err)
+ data.err = r.err
} else if cfg.ModulesEnabled && path != "unsafe" {
data.p = new(build.Package)
data.err = fmt.Errorf("unknown import path %q: internal error: module loader did not resolve import", r.path)
@@ -668,11 +672,17 @@ func loadPackageData(path, parentPath, parentDir, parentRoot string, parentIsStd
data.p, data.err = cfg.BuildContext.Import(r.path, parentDir, buildMode)
}
data.p.ImportPath = r.path
- if cfg.GOBIN != "" {
- data.p.BinDir = cfg.GOBIN
- } else if cfg.ModulesEnabled && !data.p.Goroot {
- data.p.BinDir = ModBinDir()
+
+ // Set data.p.BinDir in cases where go/build.Context.Import
+ // may give us a path we don't want.
+ if !data.p.Goroot {
+ if cfg.GOBIN != "" {
+ data.p.BinDir = cfg.GOBIN
+ } else if cfg.ModulesEnabled {
+ data.p.BinDir = ModBinDir()
+ }
}
+
if !cfg.ModulesEnabled && data.err == nil &&
data.p.ImportComment != "" && data.p.ImportComment != path &&
!strings.Contains(path, "/vendor/") && !strings.HasPrefix(path, "vendor/") {