diff options
author | Daniel Martí <mvdan@mvdan.cc> | 2021-04-26 23:06:53 +0100 |
---|---|---|
committer | Daniel Martí <mvdan@mvdan.cc> | 2021-04-28 13:49:52 +0000 |
commit | 4fe324dd0f3497f6bf4f46ba39921d7855dbc29b (patch) | |
tree | 70926e3d02fb42e7397f07cb93621a14eb51d8ad /src/cmd/go/internal/work/build.go | |
parent | f68878f0fc542708bbe1dc4f131d32b21fac0d3c (diff) | |
download | go-4fe324dd0f3497f6bf4f46ba39921d7855dbc29b.tar.gz go-4fe324dd0f3497f6bf4f46ba39921d7855dbc29b.zip |
cmd/go: make TOOLEXEC_IMPORTPATH consistent with 'go list -f {{.ImportPath}}'
TOOLEXEC_IMPORTPATH is useful for the toolexec program to know what
package is currently being built. This is otherwise tricky to figure out.
Unfortunately, for test packages it was lacking. In the added test case,
we have a total of four packages in 'go list -test':
test/main
test/main.test
test/main [test/main.test]
test/main_test [test/main.test]
And, when running with -toolexec, one would get the following values:
# test/main_test [test/main.test]
compile TOOLEXEC_IMPORTPATH="test/main_test"
# test/main [test/main.test]
compile TOOLEXEC_IMPORTPATH="test/main"
# test/main.test
compile TOOLEXEC_IMPORTPATH="test/main.test"
Note how the " [test/main.test]" suffixes are missing. Because of that,
when one sees TOOLEXEC_IMPORTPATH="test/main", it is ambiguous whether
the regular "test/main" package is meant, or its test variant, otherwise
known as "test/main [test/main.test]" and including foo_test.go
To fix this, we need unambiguous strings to identify the packages
involved, just like one can do with "go list -test". "go list" already
has such a field, ImportPath, which is also used when printing output
from each build "action" as seen above.
That string is not really an import path - internally, it's
load.Package.Desc, and called a "description". However, it makes sense
to be consistent with "go list -json", because it's the source of truth
for practically all tools interacting with the Go toolchain.
To keep cmd/go more consistent, "go list -f {{.ImportPath}}" now calls
Package.Desc as well, instead of having its own copy of the string
concatenation for ForTest.
Fixes #44963.
Change-Id: Ibce7fbb5549209dac50526043c0c7daa0beebc08
Reviewed-on: https://go-review.googlesource.com/c/go/+/313770
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Daniel Martí <mvdan@mvdan.cc>
Diffstat (limited to 'src/cmd/go/internal/work/build.go')
-rw-r--r-- | src/cmd/go/internal/work/build.go | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go index a75ace7d4e..1babbda889 100644 --- a/src/cmd/go/internal/work/build.go +++ b/src/cmd/go/internal/work/build.go @@ -152,6 +152,8 @@ and test commands: a program to use to invoke toolchain programs like vet and asm. For example, instead of running asm, the go command will run 'cmd args /path/to/asm <arguments for asm>'. + The TOOLEXEC_IMPORTPATH environment variable will be set, + matching 'go list -f {{.ImportPath}}' for the package being built. The -asmflags, -gccgoflags, -gcflags, and -ldflags flags accept a space-separated list of arguments to pass to an underlying tool |