-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go: unclear error when 'go mod vendor' is run with no packages to vendor #36580
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
I've been learning go for the last year or so. I'd love to learn more about the toolchain compiler and thought I might look around here for some beginner issues as an opportunity to learn. I've repro'd this bug locally so maybe I can offer a fix. Looks like lines 122 -- 128 of src/cmd/go/internal/modcmd/vendor.go Shall I take a stab at this one? |
Actually, I'm not 100% sure I understand the desired behavior. Do we want to create the vendor directory so that modules.txt can get the ## explicit line? Or do we simply not want to create the vendor dir yet (nor modules.txt) since there are no package to vendor? If the latter, it seems like we can just check len(modpkgs) instead of the write buffer for modules.txt. If the former, since we can no longer rely on vendor dir being created by a call to vendorPkg, I just need to call MkdirAll on vdir before we try to write "modules.txt" into it. |
Now that ## explicit lines may appear in modules.txt, the presence of bytes in the modules.txt buffer doesn't indicate that we have created a vendor/ directory, nor that we need a modules.txt. Updates: golang#36580
Probably we should create the |
+1 to creating @jcrowgey You are very welcome to work on this. Make sure to test the new behavior. A small change in I'm going to remove the Go1.14 milestone from this issue. The 1.14 branch will be cut very soon (maybe today?), so this should probably go into 1.15. (@bcmills let me know if you disagree though). |
Thanks to both of you!
Following that logic, that running |
Even an an empty build list merits a vendor/modules.txt. Updates: golang#36580
Maybe? It's not clear to me what should happen if the module has no dependencies whatsoever, since we won't hit the network even with |
`go mod vendor` should create vendor/modules.txt even when the only deps in go.mod are unused. Updates: golang#36580
Ok, perhaps this is on the right track: It -relies on os.MkdirAll's idempotency (and, hopefully, efficiently doing nothing on a second call) to- ensures the creation of vdir whenever we process an explicit line from the go.mod file which isn't actually used as a dependency. I added a regression test based on the use case described in the OP here. It's not clear to me if that regression test invokes unnecessary network bandwith if that particular tools version isn't in the local pkg/cache. EDIT: This second commit updates to use sync.Once instead of potentially calling os.MkdirAll many times. Anyway, if this is on the right track, I can go ahead and do the CLA thing and open a PR with a branch. Cheers. |
`go mod vendor` should create vendor/modules.txt even when the only deps in go.mod are unused. Updates: golang#36580
`go mod vendor` should create vendor/modules.txt even when the only deps in go.mod are unused. Fixes: golang#36580
Change https://golang.org/cl/217135 mentions this issue: |
`go mod vendor` now attempts to create vendor/modules.txt even when the only dependencies in go.mod are unused. This change ensures that vendor/ is created whenever there is any text to be written into modules txt. The previous approach relied on a side effect of a call to vendorPkg to create the directory. Since the change described in [1], this is no longer fully reliable, resolving [2]. [1]: https://golang.org/issue/33848#issuecomment-537222782 [2]: Fixes: golang#36580
'go mod vendor' now attempts to create vendor/modules.txt even when the only dependencies in go.mod are unused. This change ensures that vendor/ is created whenever there is any text to be written into modules txt. The previous approach relied on a side effect of a call to vendorPkg to create the directory. Since the change described in [1], this is no longer fully reliable, resolving [2]. [1]: https://golang.org/issue/33848#issuecomment-537222782 [2]: Fixes golang#36580
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
no, only tip
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
In an empty directory:
What did you expect to see?
This is the error message from 1.13.6. This message is also printed at tip if there are no module requirements.
What did you see instead?
This message is printed when
go mod vendor
tries to writemodules.txt
after copying packages into the vendor directory. There are no packages to vendor, so it hasn't actually created the vendor directory, and the write fails.The text was updated successfully, but these errors were encountered: