-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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,x/tools/gopls: confusing behavior of go mod when go.work is in play #60430
Comments
actually this also raises a question: how should versions be managed if we could build the module_a without requiring module_b? or is this "undefined behavior"? Is this some legacy from the GOPATH era? |
also related: #53502 |
Slotted this for gopls@v0.13.0, when we are revisiting UX of modules/workspaces/etc. |
This should have been fixed by #57979. Now gopls should just do the right thing when you open a Go file, auto-detecting the applicable workspace. Please comment if that is not the case. |
@findleyr so the behavior of go build and go install is expected? may I ask for an explanation? |
@frankli0324 sorry, let me make sure I understand: you are asking about the behavior of In general, go.work files are only used for development: for example they are not used by CC @bcmills @matloob for the go.work behavior, though as far as I understand it, this is working as intended. I agree that the behavior of gopls was confusing, since gopls should be able to figure out how to build your workspace with and without a go.work file. That is what was fixed by #57979. |
Yes, from what I've read it seems like it's working as intended. |
however this(wrong branch previously, updated) builds without errors with or without a ➜ ~ go install github.com/frankli0324/workspace_demo/module_a@remove-go-work
go: downloading github.com/frankli0324/workspace_demo v0.0.0-20230525143326-5f566b988c3e
go: downloading github.com/frankli0324/workspace_demo/module_a v0.0.0-20230525143326-5f566b988c3e
go: finding module for package github.com/frankli0324/workspace_demo/module_b
go: downloading github.com/frankli0324/workspace_demo/module_b v0.0.0-20230525151631-f91535a39128
go: downloading github.com/frankli0324/workspace_demo v0.0.0-20230525151631-f91535a39128
go: found github.com/frankli0324/workspace_demo/module_b in github.com/frankli0324/workspace_demo/module_b v0.0.0-20230525151631-f91535a39128
➜ ~ module_a
test So this is a seperate issue then? |
also, as a matter of fact, CI actions and workflows build the release builds with |
See also #53502. We could have clearer documentation about best practices for go.work, such as whether they should be checked in to VCS. |
What version of Go are you using (
go version
)?What did you do?
with a go workspace https://github.com/frankli0324/workspace_demo (I committed the go.work file for demonstration purposes)
module_a can be compiled
now remove go.work, compilation fails with:
also note that
go install github.com/frankli0324/workspace_demo/module_a
succeeds, andgo install github.com/frankli0324/workspace_demo/module_b@remove-go-work
also succeeds.the
remove-go-work
branch doesn't have a go.work file and module_a doesn't require module_bWhat did you expect to see?/What did you see instead?
I expect either gopls to stop complaining about missing modules in go.mod and "you must go mod tidy" or go build/install fail to build the module if go.mod is incorrectly constructed (missing require)
Conclusion
From what I observe, I believe the essence of
go work
is forcing submodules to build as if there's anreplace $declared_module_name => ./$local_path
in each of the usedgo.mod
s:in persudo-code:
However, normally if module_a doesn't require module_b, if module_b is replaced anyway, go build still fails:
this is where I think is inconsistent and erroneous.
I'm aware that #52962 raised the issue already, but I believe it's not a duplicate. Also the issue seems wasted since no one is getting anywhere closer to an answer.
The text was updated successfully, but these errors were encountered: