-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go: TOOLEXEC_IMPORTPATH is ambiguous for test packages #44963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It's unfortunate that the I think the orthogonal basis of these names is:
That gives:
I wonder if it would make sense to provide those as separate variables. (Perhaps |
I have mixed feelings about your suggestion. On one hand, I agree that On the other hand, if you make that refactor, then Maybe simplify In any case, though, I think that's a separate cleanup that should happen for all of cmd/go at once. Right now, |
To clarify, when I say "uniquely and globally identify a package", I mean within a single build list. For example, to build a |
To be clear: I don't think we should change the contents of the (I wouldn't be opposed to adding a new field for the actual import path, though.) |
Ah, gotcha, I may have misunderstood. Do you agree with just making I don't object to other env vars like |
I'm not sure that I really understand what use-cases That said, I really don't like the behavior of |
The use case is uniquely identifying a package. I use that to be able to locate it in the output of
The alternative is more env vars like |
We dicussed this with @rsc recently, and concluded:
|
Great, thank you :) The unclear documentation is partly on me. I'll send a CL soon, also documenting how it works. |
Change https://golang.org/cl/313770 mentions this issue: |
#15677 was fixed, so now tools called via commands like
go build -toolexec=
can easily find out what package is currently being assembled/compiled/linked. That's great, and I'm already using it in a tool with great success.There's just one exception; for test packages, it's ambiguous, as it contains less information than
go list -test
. Let me show an example, run with cmd/testscript:https://play.golang.org/p/A4UaS8kkVdI
Here are the output lines I care about, from the stderr of
go test -toolexec=mytool
when running liketestscript -v repro.txt
:Note that we compile three packages at the root, excluding the
foo.test
main package. Those are:foo
, the regular packagefoo [foo.test]
, the regular package built with test files, built forfoo.test
foo_test [foo.test]
, the externalfoo_test
package, built forfoo.test
All these three show up in
go list -test
, too:Now, the problem is that
TOOLEXEC_IMPORTPATH
is lacking the components in brackets, so it's ambiguous. For example, ignoring the external test package for a second:If
mytool
seesTOOLEXEC_IMPORTPATH=foo
, it can't possibly know which of the two packages is actually being compiled. Another way to say that is that, if it builds an index of packages fromgo list -json -test -deps
, using theImportMap
field as the key, it will incorrectly think that it's buildingfoo
twice, instead of each of the two packages once.There's currently one workaround; since this generally only happens for the compiler,
mytool
can check the arguments to see if any Go file arguments are test files, and then add the required bracket suffix. This is the kind of hack I'm doing in a tool right now: https://github.com/burrowers/garble/blob/06a7a21e17a79c6d6717434207fa40b65ea1fe47/main.go#L284-L308I think we should fix this in cmd/go. Whatever package import path it writes in lines like
# foo [foo.test]
, which is also whatgo list -f {{.ImportPath}}
reports, it should also include inTOOLEXEC_IMPORTPATH
. Right now, there's this ambiguity and inconsistency with test packages.I'm happy to attempt a fix. I would argue that this is worth backporting; there's a workaround, but it's very hacky and it only sort of works for toolexec-wrapped calls to the compiler. The other option is to admit that
TOOLEXEC_IMPORTPATH
is broken in 1.16.x forgo test -toolexec=
, and fix it for 1.17.cc @bcmills @jayconrod @matloob @bradfitz @josharian
The text was updated successfully, but these errors were encountered: