Skip to content

cmd/go: go generate fails silently when run on a package in a nested workspace module #56098

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

Closed
findleyr opened this issue Oct 7, 2022 · 7 comments
Labels
FrozenDueToAge GoCommand cmd/go modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@findleyr
Copy link
Member

findleyr commented Oct 7, 2022

I noticed the following while working on https://go.dev/cl/440181. I have a go.work file using both x/tools and x/tools/gopls. When running go generate on a package in x/tools/gopls, the command exits with status 0 without doing anything.

When run from the gopls module, the go generate command works as expected. This can be seen from the following shell history, where I start from a clean workspace (at patchset 2 of the above CL), make an arbitrary edit in one of the generated files, and run go generate expecting it to revert the diff.

$ git status
On branch accessdenied
Your branch is ahead of 'origin/master' by 1 commit.

nothing to commit, working tree clean
$ echo "// arbitrary edit" >> gopls/internal/robustio/robustio.go
$ git status
On branch accessdenied
Your branch is ahead of 'origin/master' by 1 commit.

Changes not staged for commit:
        modified:   gopls/internal/robustio/robustio.go

no changes added to commit
$ go generate ./gopls/internal/robustio
$ echo $?
0
$ git status
On branch accessdenied
Your branch is ahead of 'origin/master' by 1 commit.

Changes not staged for commit:
        modified:   gopls/internal/robustio/robustio.go

no changes added to commit
$ cd gopls && go generate ./internal/robustio
$ git status
On branch accessdenied
Your branch is ahead of 'origin/master' by 1 commit.

nothing to commit, working tree clean
@bcmills bcmills added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. modules GoCommand cmd/go labels Oct 7, 2022
@bcmills bcmills added this to the Backlog milestone Oct 7, 2022
@bcmills
Copy link
Contributor

bcmills commented Oct 7, 2022

Duplicate of #29751

@bcmills bcmills marked this as a duplicate of #29751 Oct 7, 2022
@bcmills bcmills closed this as not planned Won't fix, can't repro, duplicate, stale Oct 7, 2022
@bcmills
Copy link
Contributor

bcmills commented Oct 7, 2022

Hmm, not quite a duplicate (because of workspace mode). But #29751 is definitely closely related.

@bcmills bcmills reopened this Oct 7, 2022
@bcmills bcmills marked this as not a duplicate of #29751 Oct 7, 2022
@bcmills bcmills modified the milestones: Backlog, Go1.23 Jan 29, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/559195 mentions this issue: cmd/go/internal/generate: call modload.InitWorkFile

@matloob
Copy link
Contributor

matloob commented Jan 29, 2024

@gopherbot please backport to 1.21 and 1.22. go generate doesn't work in workspace mode and it's a one-line fix

@gopherbot
Copy link
Contributor

Backport issue(s) opened: #65351 (for 1.21), #65352 (for 1.22).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/559235 mentions this issue: cmd/go/internal/generate: call modload.InitWorkFile

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/559236 mentions this issue: cmd/go/internal/generate: call modload.InitWorkFile

gopherbot pushed a commit that referenced this issue Feb 1, 2024
…rkFile

This is necessary for go generate to enter workspace mode for
recognizing package paths in the workspace.

For #56098
Fixes #65351

Change-Id: I25f68de24f4189259353f63194823516e9d3d505
Reviewed-on: https://go-review.googlesource.com/c/go/+/559195
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Bryan Mills <[email protected]>
(cherry picked from commit b91bad7)
Reviewed-on: https://go-review.googlesource.com/c/go/+/559235
gopherbot pushed a commit that referenced this issue Feb 2, 2024
…rkFile

This is necessary for go generate to enter workspace mode for
recognizing package paths in the workspace.

For #56098
Fixes #65352

Change-Id: I25f68de24f4189259353f63194823516e9d3d505
Reviewed-on: https://go-review.googlesource.com/c/go/+/559195
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Bryan Mills <[email protected]>
(cherry picked from commit b91bad7)
Reviewed-on: https://go-review.googlesource.com/c/go/+/559236
ezz-no pushed a commit to ezz-no/go-ezzno that referenced this issue Feb 18, 2024
This is necessary for go generate to enter workspace mode for
recognizing package paths in the workspace.

Fixes golang#56098

Change-Id: I25f68de24f4189259353f63194823516e9d3d505
Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest
Reviewed-on: https://go-review.googlesource.com/c/go/+/559195
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Bryan Mills <[email protected]>
@golang golang locked and limited conversation to collaborators Jan 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants