-
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
x/vgo: should we allow replace for "old" code? #25739
Comments
Each package needs to be able to compile on its own. To do that it needs to know that the GOPATH looks like. Aside from a possible technical issue to overcome, mixing code without a module file (and thus without a understanding of where it is in GOPATH) and "new" code with a mod file seems like it would increase confusion. Probably I suspect this would be a bad idea. As a counter proposal, maybe make it possible to reference "old code" by referencing the GOPATH like: edit: I'm not advancing the requirement of referencing old code, but if this does turn out to be an issue, I think the GOPATH ref might be a good alternative. |
I'm curious: do you have the same problem if you use I could see a reasonable argument for |
This was my initial feeling. But given Russ' comments in #25662 (comment) I didn't know whether adding
Just to be clear, this is definitely a question, not a proposal. I'm just trying to understand how this "flow" is supported (unless others feel the use case is more an edge case?)
Interesting idea. The reason for containing The alternative would of course be for me to fork the repo, but then I think we're caught short again here. Because imagine I fork the repo to |
I'm probably missing something obvious here, but would |
It's more likely that I'm the one missing something obvious. 🙂 |
I think if you are committing the code to your repo, then you might as well put in an internal folder and git it a go.mod file |
The replacement line must point at a module. If you are preparing a module in a local file system directory, then part of preparing it is having a go.mod. In the future it will be common for your clone of someone's repo to bring in a go.mod. Until then, you need to make it. It is important to know what the replacement module believes its import path base is (the module path) as well as what its requirements are (which may differ from the original, and which will not be consulted anyway). For both these reasons the go.mod must be present and cannot simply be inferred. Now, it's true that if you said to replace some other thing => rsc.io/pdf v0.1.1 then that would work even though the code in github.com/rsc/pdf at tag v0.1.1 has no go.mod file. But that's because the combination "rsc.io/pdf v0.1.1" is going through a resolution process that does in fact construct a synthetic go.mod file as best it can from the sources. But a plain directory full of files does not carry the same context. Re invariants, it is fine to put a module line that says what the code in that directory believes that directory's import path to be. That's what vgo get is doing on download. As for the auto-generated go.mod not being in the $GOPATH/src/v/rsc.io/pdf@v0.1.1 directory, that's true, it's not there. It's in $GOPATH/src/v/cache/rsc.io/pdf/@v/v0.1.1.mod instead. The unpacked source directory is a pristine copy of exactly what is in the zip file ($GOPATH/src/v/cache/rsc.io/pdf/@v/v0.1.1.zip), so that we can compute its hash and expect that hash to be never-changing. In contrast, the details of auto-generating a go.mod from a file tree do change, as we fix bugs and make the conversion more capable. If go.mod lived in that source directory, the hash would change as vgo did, which would not break go.modverify (soon to be go.sum) verification. Instead the mod is kept in the cache directory, alongside the zip file. You'll also notice that it has a comment at the top with a version number:
That version number indicates the version of the converter used to generate the mod file. (Really a made-up number, it didn't need to look like semver.) Each time we make a substantial change to the converter and need to invalidate old conversions, we can bump the number in the vgo source code, and it will treat all those cached files as stale and regenerate them from the original source trees. Bringing things back to the ../pdf directory, it should suffice to do
which will page in whatever rsc.io/pdf needs (nothing, it turns out). I've been wondering about some kind of 'vgo initmod rsc.io/pdf' command but I'm relucant to put something there that will be under significant pressure to grow in scope without bound. |
I think this answers the question in the issue title at least; closing. |
It absolutely does, thank you. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes. Per above
What operating system and processor architecture are you using (
go env
)?What did you do?
Create ourselves a simple module that depends on an "old" Go package (
rsc.io/pdf
atv0.1.1
is"old", non-module code):
Now we get that specific version of
rsc.io/pdf
that is known to be "old" Go code:Now check our code builds and runs:
Create a local copy of
rsc.io/pdf
and add a replace directive to use it:Now check our code still builds:
It doesn't; seems we need to mark that directory as a Go module with a
go.mod
:Now check our code builds and runs:
What did you expect to see?
It's unclear whether we can/want to allow replace directives to apply to "old" (where "old" is the opposite of "new"). Doing so would obviate the need for creating the
go.mod
file in thepdf
directory; but I'm unclear what other "problems" this might introduce.What did you see instead?
Per above.
The text was updated successfully, but these errors were encountered: