-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: cmd/go: add ignore directive to go.mod to drop files from module #37724
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
Have you seen #29987? It seems like dropping a |
@mvdan I have. I mentioned this workaround. I consider it a less than ideal hack though. Adding an empty go.mod to non-go source code to exclude it is the kind of behavior that should not be relied on. You also pay a cost when go traverses the entire directory tree. It doesn't exclude directories per se, it excludes individual files that share a prefix with a go.mod file, which means that it does a comparison against every single file. For a sufficiently large number of files, there is a non-trivial performance cost. |
My bad - I misread part of your original issue. I still think that an extra |
In most cases I'd agree. But this functionality is needed for a few different tools now (x/tools/gopls and x/mod, at least), and I think the complexity of an explicit configuration option is lower than relying on an unintended side effect of x/mod. Putting an empty go.mod file in with source code that's not related to go is definitely not a pretty or intuitive solution. |
@jniedrauer, the use of If it is “not a pretty […] solution”, well, that's unfortunate — but we don't generally change Go tooling (or add redundant features) for purely aesthetic reasons. If it is “not [an] intuitive solution”, that may be a matter of improving documentation and/or user education. (I think it's too early to tell one way or another, given that large projects especially have only been adopting modules for a year or so, and in small projects this sort of repository division is not necessary.) |
cc @matloob I somewhat agree that adding a It's not clear to me that an |
Any mechanism that can be used to exclude (non-go source) directory trees as the intended behavior will solve the problem. I do think an empty go.mod is a bit of a hack. The presence of a go.mod is supposed to communicate "this is a Go module" but in this case it actually means "this is not a Go module". If a file requires a comment to explain why it exists, then it's not ergonomic. But if it's documented and compatibility is maintained in future versions, then it works for me. I'm in favor of putting it in go.mod because it's better from a discoverability standpoint. Magic files like dockerignore have bitten me many times in the past. They are not immediately obvious, especially if they start with a |
Wondering if this ignore concept could be extended to monorepos with I would love to be able to add something in my go.mod so it knows to always run in mod mode. I would settle for:
|
Even if we wanted to do this, I don't see any viable path forward. There are already two ways to do this: a dummy go.mod or putting |
This proposal has been added to the active column of the proposals project |
@rsc Don't we have the Go version directive at the beginning of the |
@clausecker Unfortunately, that's not sufficient. Suppose a developer uses Go 1.15 and fetches a module with |
Based on the discussion above, this proposal seems like a likely decline. |
@clausecker, varying the module's contents based on the |
No change in consensus, so declined. |
Now that this proposal has been rejected, is there any movement to create a .goignore file? I am only interested in this because of problems with my IDE: #37697
|
x/mod hardcodes the max size of a module, zipped or extracted, at 500M. There is no (sane) way to exclude files from a module. This means that if you have a mixed repo with vendored assets and go source code with a go.mod at the root of the repo, you are effectively restricted to a max repo size of 500M.
#37697 suggests respecting the .gitignore file for x/tools/gopls, however this would not be a good solution to the go module max size restriction.
A solution to both problems would be to add an ignore section to the go.mod file. For example:
(As a temporary workaround to the hardcoded module size, you can create an empty
go.mod
file in any subdirectory you want to exclude, which causes it to be flagged as a submodule and excluded from the module zip.)The text was updated successfully, but these errors were encountered: