aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/cfg/cfg.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2018-07-20 10:59:57 -0400
committerRuss Cox <rsc@golang.org>2018-07-28 01:14:39 +0000
commitf85125345cc5d3eb054c90bfca4bda3544d7fcab (patch)
treed7e972a71c2d4961ea2267a8c5dbf4444c59c1b9 /src/cmd/go/internal/cfg/cfg.go
parent8450fd96779cc9e269f8a083a7f163bb1d7dbd39 (diff)
downloadgo-f85125345cc5d3eb054c90bfca4bda3544d7fcab.tar.gz
go-f85125345cc5d3eb054c90bfca4bda3544d7fcab.zip
go/build: invoke go command to find modules during Import, Context.Import
The introduction of modules has broken (intentionally) the rule that the source code for a package x/y/z is in GOPATH/src/x/y/z (or GOROOT/src/x/y/z). This breaks the code in go/build.Import, which uses that rule to find the directory for a package. In the long term, the fix is to move programs that load packages off of go/build and onto golang.org/x/tools/go/packages, which we hope will eventually become go/packages. That code invokes the go command to learn what it needs to know about where packages are. In the short term, though, there are lots of programs that use go/build and will not be able to find code in module dependencies. To help those programs, go/build now runs the go command to ask where a package's source code can be found, if it sees that modules are in use. (If modules are not in use, it falls back to the usual lookup code and does not invoke the go command, so that existing uses are unaffected and not slowed down.) Helps #24661. Fixes #26504. Change-Id: I0dac68854cf5011005c3b2272810245d81b7cc5a Reviewed-on: https://go-review.googlesource.com/125296 Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/cfg/cfg.go')
-rw-r--r--src/cmd/go/internal/cfg/cfg.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/cmd/go/internal/cfg/cfg.go b/src/cmd/go/internal/cfg/cfg.go
index 9dd90ee871..c7746b6912 100644
--- a/src/cmd/go/internal/cfg/cfg.go
+++ b/src/cmd/go/internal/cfg/cfg.go
@@ -20,7 +20,7 @@ import (
var (
BuildA bool // -a flag
BuildBuildmode string // -buildmode flag
- BuildContext = build.Default
+ BuildContext = defaultContext()
BuildGetmode string // -getmode flag
BuildI bool // -i flag
BuildLinkshared bool // -linkshared flag
@@ -43,6 +43,12 @@ var (
DebugActiongraph string // -debug-actiongraph flag (undocumented, unstable)
)
+func defaultContext() build.Context {
+ ctxt := build.Default
+ ctxt.JoinPath = filepath.Join // back door to say "do not use go command"
+ return ctxt
+}
+
func init() {
BuildToolchainCompiler = func() string { return "missing-compiler" }
BuildToolchainLinker = func() string { return "missing-linker" }