-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
cmd/go: PWD not honored in "go list -m" with explicit GOWORK #51823
Comments
Change https://go.dev/cl/394054 mentions this issue: |
It should be, provided that you run This doesn't look like a |
Apologies, I should have explained that better. Another example (in linux, for readability): $ cd /tmp && mkdir -p real/mymod
$ ln -s real symlink
$ cd symlink/mymod && go mod init mymod
$ pushd .. && go work init mymod/ && popd Now from Plain $ go list -json mymod/... | jq .Module
{
"Path": "mymod",
"Main": true,
"Dir": "/tmp/symlink/mymod",
"GoMod": "/tmp/symlink/mymod/go.mod",
"GoVersion": "1.19"
} Setting $ PWD=/tmp/real/mymod go list -json mymod/... | jq .Module
{
"Path": "mymod",
"Main": true,
"Dir": "/tmp/real/mymod",
"GoMod": "/tmp/real/mymod/go.mod",
"GoVersion": "1.19"
} Setting both $ PWD=/tmp/real/mymod GOMOD=/tmp/symlink/mymod/go.mod go list -json mymod/... | jq .Module
{
"Path": "mymod",
"Main": true,
"Dir": "/tmp/real/mymod",
"GoMod": "/tmp/real/mymod/go.mod",
"GoVersion": "1.19"
} But setting
I would expect $ PWD=/tmp/real/mymod GOWORK=/tmp/symlink/go.work go list -json mymod/... | jq .Module
{
"Path": "mymod",
"Main": true,
"Dir": "/tmp/symlink/mymod",
"GoMod": "/tmp/symlink/mymod/go.mod",
"GoVersion": "1.19"
} |
Setting |
Gotcha, I incorrectly assumed that you could set The current situation, if I understand it correctly, is that paths is shown based on the The difference between setting |
The difference you're seeing is that when |
Yeah, I understand that the inferred value of The part that seems odd is that directories provided by Ok, just to make sure I understand how this suppose to work:
Am I missing something? |
Yes, that's exactly it. When you set When you set |
Adding this to the Go 1.19 milestone until we can understand what the desired behavior is and what we should do about it (I didn't fully follow the conversation, but I also only skimmed it). Feel free to move it. |
When using gopls remote, existing go env vars are injected in the initialize message. Setting GOWORK explicitly will impact cmd/go invocations, for example "go list" during package load. The reason it impacts is that gopls manually sets PWD to fix paths returned by cmd/go if the working directory is inside a symlinked directory. By only propagate GOWORK when it is explicitly set we will ensure that the behavior is the same when running with or without remote. See golang/go#51823. Fixes golang/go#51825 Change-Id: I6280aa7d8208e5aee269f19356668c7713e9f0a4 Reviewed-on: https://go-review.googlesource.com/c/tools/+/394054 Trust: Pontus Leitzler <leitzler@gmail.com> Run-TryBot: Pontus Leitzler <leitzler@gmail.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
I don't think there is anything to change here. The If Overall, my advice is: keep |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
A simple reproducable is to create a workspace within the temporary directory on darwin:
The temp dir on macOS is a symlink where the real path has a
/private
prefix, e.g.:x/tools relies on cmd/go returning resolved paths as per: https://github.com/golang/tools/blob/5ea13d0d89f92d5ca5468e282dd4ba2ad7503564/internal/gocommand/invoke.go#L216-L221
When running
go list
, the directories works as expected:Until I explicitly set
GOWORK
(before PWD sincego env
otherwise picks up the resolved dir):What did you expect to see?
I would expect that PWD is honored when running
go list
regardless of ifGOWORK
is set or not. Essentially I would expectGOWORK=$(go env GOWORK)
here to be a no-op without side effects.What did you see instead?
go list
returning non-resolved paths when PWD is set.The text was updated successfully, but these errors were encountered: