-
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: document using -modfile to record tool versions without interfering with main module dependencies #33926
Comments
/cc @bcmills @jayconrod |
Perhaps I'm misunderstanding, but isn't this the expected/designed behavior? The In some sense, I see this as a benefit especially for things that are partially code generators and partially libraries, like something that generates models from a database, because I can always know that the version of the generator I ran matches the library I'm about to use. But, there are certainly cases where mixing things produces a bad result; I had a script which used a single |
@zikaeroh sure, this is working as intended from
Yes, this is already well-known problem of the |
In general we expect dependencies to remain compatible over time, and we expect incompatibilities to be resolved by upgrading past them (rather than pinning to a point before they began). Moreover, tools will tend to build faster if they can reuse dependencies shared with the rest of the main module, which would not be possible if those dependencies are at some other version. In your example with |
For what it's worth, my reading of "ensure that everyone is using the same version of that tool" is that the tool dependencies should be pinned for all people who are actually "working" on the project that uses them, not necessarily that they should match the "upstream versions" to a tee. It's possible to have both (with some new method of managing tools, which could be useful to isolate things and reduce breakage), but if every developer on a project is using the same (Now, that's not entirely true if someone updates a dependency and the behavior changes, but it's going to be much better to have a repo which says "these are my code generators, they produce this output" and committing it, rather than them depending on some external state like what version of |
@bcmills @zikaeroh the problem is that when we report a bug for a tool, e.g. included in |
What do you think about removing or demoting this tool dependency sections from the wiki page? |
A stable module should not import packages from an unstable dependency unless the two modules have a requirement cycle. Otherwise, that's not sound semantic versioning: the API of the dependency could change and break the “stable” dependent. Given sound semantic versioning, it should be fine to mix tool dependencies in with other dependencies, since upgrades to those dependencies should not break anything else. |
Given that the module echo system is still not mature and many legacy modules and tools end up depending on pseudoversions and v0.*, I don't think that's easy to enforce. |
Thinking about this some more: this problem statement is exactly #30515. So my question is, why did you need to add the tool dependency in the first place? (Is the tool run by a test, or in a Would it satisfy your use-case if you could |
If the tool dependency version causes undesirable effects in the main app, you could make a subdirectory with its own go.mod and move tools.go there. You'd need to cd there first before |
Yes.
For example, I want to specify the version used for // go:generate (e.g. gobind, etc).
As we observed,
Yes. I am happy to repurpose this issue to stop suggesting If |
Also, I learned recently - the tool behavior may change depending on the version of |
@bcmills I encountered another tools.go file and remembered this :-) Do you need more info? Relabel it if more info is necessary. |
@hyangah I think this problem is solved by the The idea is this: a module author could maintain a separate I'm hoping |
@jayconrod Yes, #34506 is a more promising approach than I am happy to classify this as a documentation issue (wiki/Modules) - asking for the best practice for tool dependency management -, add a warning in the best practice mentioning #34506, and close this. |
Completely agree that this will need proper docs. |
I don't see how What I've done to isolate tool deps from main deps is to put the tools in a subdir with its own |
I expect that a file used with |
You can also imagine trivial use cases like |
Perhaps you'd need it less often, but when you do want it, there'd be no reasonable way to run it.
It seems to me that would use the product source to discover necessary dependencies -> all tools would get removed, all kinds of non-tool deps would be added. The tools-in-subdir-with-go.mod trick seems to avoid all these downsides... |
I believe this pattern has been superseded by #48429 |
To clarify - Unfortunately #48429 is quite opposite of what this feature request wanted. That interferes with main module's dependencies by design AFAIK. Currently the only reasonable workaround is to use |
What version of Go are you using (
go version
)?What did you do?
Following the tool-dependency best-practice in Module wiki, created tools.go to add the tool dependency. Note: the tool and the main module will share some dependencies, which is a problem.
Then I added some code in the main module that depends on a module the tool (
godoc
) also depends on.The
go build
of the main module picked upgolang.org/x/net@v0.0.0-20190620200207-3b0461eec859
due to the existing requirement on
golang.org/x/tools
.I wanted a newer version of
golang.org/x/net
, so upgraded it usinggo get golang.org/x/net@latest
.This resulted in a side-effect: upgrade the dependency of the tool as well. That produces a different binary. (different version of
golang.org/x/net
).What did you expect to see?
Stable, consistent build of the tools with the dependencies as specified in the tools
go.mod
.What did you see instead?
The dependencies interfere in both ways - the tool dependency affects the version selection choice of the main module, and vice versa.
This can cause confusion - the user would believe the
godoc
was built from the version ofgolang.org/x/tools
module but some of the dependency was actually picked up based on themain module's
go.mod
, instead of the tool's.The text was updated successfully, but these errors were encountered: