]> Cypherpunks repositories - gostls13.git/commit
go/build: invoke go command to find modules during Import, Context.Import
authorRuss Cox <rsc@golang.org>
Fri, 20 Jul 2018 14:59:57 +0000 (10:59 -0400)
committerRuss Cox <rsc@golang.org>
Sat, 28 Jul 2018 01:14:39 +0000 (01:14 +0000)
commitf85125345cc5d3eb054c90bfca4bda3544d7fcab
treed7e972a71c2d4961ea2267a8c5dbf4444c59c1b9
parent8450fd96779cc9e269f8a083a7f163bb1d7dbd39
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>
src/cmd/go/go_test.go
src/cmd/go/internal/cfg/cfg.go
src/cmd/go/internal/modload/init.go
src/cmd/go/script_test.go
src/cmd/go/testdata/script/mod_gobuild_import.txt [new file with mode: 0644]
src/go/build/build.go