aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/list/list.go
diff options
context:
space:
mode:
authorDaniel Martí <mvdan@mvdan.cc>2021-04-26 23:06:53 +0100
committerDaniel Martí <mvdan@mvdan.cc>2021-04-28 13:49:52 +0000
commit4fe324dd0f3497f6bf4f46ba39921d7855dbc29b (patch)
tree70926e3d02fb42e7397f07cb93621a14eb51d8ad /src/cmd/go/internal/list/list.go
parentf68878f0fc542708bbe1dc4f131d32b21fac0d3c (diff)
downloadgo-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/list/list.go')
-rw-r--r--src/cmd/go/internal/list/list.go2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/cmd/go/internal/list/list.go b/src/cmd/go/internal/list/list.go
index 53bf75e27e..53aaf311ec 100644
--- a/src/cmd/go/internal/list/list.go
+++ b/src/cmd/go/internal/list/list.go
@@ -628,7 +628,7 @@ func runList(ctx context.Context, cmd *base.Command, args []string) {
old := make(map[string]string)
for _, p := range all {
if p.ForTest != "" {
- new := p.ImportPath + " [" + p.ForTest + ".test]"
+ new := p.Desc()
old[new] = p.ImportPath
p.ImportPath = new
}