cmd/go: package is replaced but not required #44529
Comments
Try |
It's also worth considering:
|
I think I misdiagnosed my problem. Still investigating it. I'm seeing strange build times and I assumed it was downloading data, but maybe it's just doing some re-builds I'm not expecting. |
Instead, you can add a requirement on a non-existent version while replacing that version:
Adding a replacement, even one without a version on the left side, doesn't automatically add that module to the build list. If it did, the go command would read its |
If you are not using a proxy for the repo in question, that lookup may involve cloning the upstream repo. So that can be a pretty expensive operation. (Note that the official distributions of the If that network lookup fails, then ¹ go/src/cmd/go/internal/modload/import.go Lines 334 to 351 in 7eb31d9 ² go/src/cmd/go/internal/modload/query.go Lines 987 to 1000 in 7eb31d9 ³ go/src/cmd/go/internal/modload/query.go Lines 1045 to 1062 in 7eb31d9 |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
We have a fairly large repo (go-ethereum), which is a standalone application, but it can also be consumed as a library. We also have a code generator in our command suite which takes some API definitions and generates Go wrappers for them. The generated code relies on our main repository as a library.
The above is nothing special, but we'd like to have a test suite that uses the generator to wrap some APIs an then run them to make sure the generated code is executable and does what we expect. Currently the test uses the generator to create the wrapper Go files and then attempts to build it. Since the build depends on the main repo, we need to tell
go
(orgo mod
) about it.Previously we used
go mod init ...
and thengo mod edit --replace https://github.com/ethereum/go-ethereum=path/to/checkout
to have the tester use the current working code (needed both for local development as well as PRs; that they always test the checked out code, not a pinned upstream version). Up until Go 1.15 this worked fine. Starting from Go 1.16, this setup is rejected.What did you expect to see?
Go mod in 1.16 refuses to accept a replacement directive if the package being replaced isn't already part of the mod file. I could add a call to
go get github.com/ethereum/go-ethereum
orgo mod edit --require github.com/ethereum/go-ethereum@master
to the build, but that would do a network request and download out repo of >500MB. It makes no sense to have a test download external code when it's not even needed at all (the needed code is the checked out working copy the test runs from).I guess my question is how can I convince Go mod to add a
replace
directive to a local copy without having it download an upstream copy first, which just gets discarded anyway.What did you see instead?
The text was updated successfully, but these errors were encountered: