-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: cmd/go: discover module from package being built #68059
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
This will be difficult for backwards compatibility reasons. A go.work file might help, or perhaps a new environment variable could be added. |
@bjorndm What backwards compatibility reasons? |
@rittneje This would be a big change from the behavior of the Go command users are familiar with and it would introduce a lot of confusion. While this might seem appealing if you only look at relative package paths, in general for a full package path we wouldn't easily be able to figure out what module it belongs to. Also, users often pass in the paths to packages in dependency modules. In those cases they want to build/test/list the package as a module dependency rather than from its module. |
@matloob I think it is very unfortunate that you won't consider this change. The current behavior is clearly incorrect, and easily leads to production issues that may go unnoticed. |
Proposal Details
I am filing this proposal as a followup to #68043.
Currently the go command discovers the module based upon the working directory it is executed from. This results in confusing and unexpected behavior when you do for example
go build ./path/to/module/package
, since in that case it will either fail (ifGO111MODULE=on
) or fall back to non-module mode (ifGO111MODULE=auto
). In the latter case, this also means it will build with the wrongDefaultGODEBUG
.I propose that instead of discovering the module based on the current working directory, the go command instead discovers it based upon the location of the package you are building. So in the example of
go build ./path/to/module/package
, it will use the module rooted at./path/to/module
, assuming that./path/to/module/go.mod
exists.The text was updated successfully, but these errors were encountered: