Skip to content
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

proposal: cmd/go: discover module from package being built #68059

Closed
rittneje opened this issue Jun 18, 2024 · 5 comments
Closed

proposal: cmd/go: discover module from package being built #68059

rittneje opened this issue Jun 18, 2024 · 5 comments
Milestone

Comments

@rittneje
Copy link

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 (if GO111MODULE=on) or fall back to non-module mode (if GO111MODULE=auto). In the latter case, this also means it will build with the wrong DefaultGODEBUG.

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.

@gopherbot gopherbot added this to the Proposal milestone Jun 18, 2024
@bjorndm
Copy link

bjorndm commented Jun 19, 2024

This will be difficult for backwards compatibility reasons. A go.work file might help, or perhaps a new environment variable could be added.

@rittneje
Copy link
Author

@bjorndm What backwards compatibility reasons?

@seankhliao seankhliao added the GoCommand cmd/go label Jul 19, 2024
@matloob
Copy link
Contributor

matloob commented Jul 23, 2024

@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 matloob closed this as not planned Won't fix, can't repro, duplicate, stale Jul 23, 2024
@rittneje
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Incoming
Development

No branches or pull requests

6 participants