-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go: "mod tidy" erroneously labels imports from within normally-ignored directories as direct #37376
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 cannot reproduce the observed instability using I see only one diff, but that diff is produced identically for both subcommands: mattermost-server$ git status
On branch tidygomod
Your branch is up to date with 'origin/tidygomod'.
nothing to commit, working tree clean
mattermost-server$ go1.14rc1 mod tidy
mattermost-server$ git diff
diff --git i/go.mod w/go.mod
index 410361d74..2ba38df44 100644
--- i/go.mod
+++ w/go.mod
@@ -67,7 +67,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.4.0
github.com/rs/cors v1.7.0
- github.com/russellhaering/goxmldsig v0.0.0-20180430223755-7acd5e4a6ef7
+ github.com/russellhaering/goxmldsig v0.0.0-20180430223755-7acd5e4a6ef7 // indirect
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd
github.com/segmentio/analytics-go v3.1.0+incompatible
github.com/segmentio/backo-go v0.0.0-20160424052352-204274ad699c // indirect
mattermost-server$ git reset --hard
HEAD is now at eb3f7be36 Merge branch 'master' into tidygomod
mattermost-server$ go1.14rc1 mod vendor
gi
mattermost-server$ git diff
diff --git i/go.mod w/go.mod
index 410361d74..2ba38df44 100644
--- i/go.mod
+++ w/go.mod
@@ -67,7 +67,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.4.0
github.com/rs/cors v1.7.0
- github.com/russellhaering/goxmldsig v0.0.0-20180430223755-7acd5e4a6ef7
+ github.com/russellhaering/goxmldsig v0.0.0-20180430223755-7acd5e4a6ef7 // indirect
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd
github.com/segmentio/analytics-go v3.1.0+incompatible
github.com/segmentio/backo-go v0.0.0-20160424052352-204274ad699c // indirect I wonder if this is a platform-specific bug — what is the output of your |
Just updated to 1.14 and didn't see any difference. But I think I know where's the difference here. We use an enterprise layer which is a bundle of packages linked with a symlink. Both of them share this go.mod. You don't have that, I do. The Go toolchain does say "ignoring symlink", but that's how I could see your "goxmldsig" change, if I delete the enterprise repo. Now that I can't share the code with you, any pointers on how do I resolve this ? go env
This is exactly what I am seeing. (Ignore the untracked files) 22:47:35-~/mattermost/mattermost-server$git st
On branch tidygomod
Untracked files:
(use "git add <file>..." to include in what will be committed)
config/config.json.bak
loadtestbulkload.json
logrus
testfiles/
nothing added to commit but untracked files present (use "git add" to track)
22:47:36-~/mattermost/mattermost-server$go version
go version go1.14 linux/amd64
22:47:38-~/mattermost/mattermost-server$go mod tidy
warning: ignoring symlink /home/agniva/mattermost/mattermost-server/client
warning: ignoring symlink /home/agniva/mattermost/mattermost-server/enterprise
22:47:45-~/mattermost/mattermost-server$git diff
diff --git a/go.mod b/go.mod
index 410361d74..c50747e82 100644
--- a/go.mod
+++ b/go.mod
@@ -41,7 +41,7 @@ require (
github.com/icrowley/fake v0.0.0-20180203215853-4178557ae428
github.com/jaytaylor/html2text v0.0.0-20190408195923-01ec452cbe43
github.com/jmoiron/sqlx v1.2.0
- github.com/jonboulle/clockwork v0.1.0 // indirect
+ github.com/jonboulle/clockwork v0.1.0
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/lib/pq v1.3.0
github.com/magiconair/properties v1.8.1 // indirect
@@ -66,6 +66,7 @@ require (
github.com/pelletier/go-toml v1.6.0 // indirect
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.4.0
+ github.com/prometheus/client_model v0.2.0
github.com/rs/cors v1.7.0
github.com/russellhaering/goxmldsig v0.0.0-20180430223755-7acd5e4a6ef7
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd
22:47:46-~/mattermost/mattermost-server$go mod vendor
warning: ignoring symlink /home/agniva/mattermost/mattermost-server/client
warning: ignoring symlink /home/agniva/mattermost/mattermost-server/enterprise
22:47:49-~/mattermost/mattermost-server$git diff
diff --git a/go.mod b/go.mod
index 410361d74..35f3652e7 100644
--- a/go.mod
+++ b/go.mod
@@ -66,6 +66,7 @@ require (
github.com/pelletier/go-toml v1.6.0 // indirect
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.4.0
+ github.com/prometheus/client_model v0.2.0 // indirect
github.com/rs/cors v1.7.0
github.com/russellhaering/goxmldsig v0.0.0-20180430223755-7acd5e4a6ef7
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd |
I would probably start with The differences between |
Update:
So ideally, it should be a direct dependency. And it seems like Same for The issue goes away if I replace the symlink by the actual directory. Needless to say, I am well-aware of the fact that symlinks aren't recommended to be used. But unfortunately, we are stuck with it for now. I will create a reproducer and update the ticket shortly. Should be fairly straightforward. |
Ok, here's the branch - https://github.com/mattermost/mattermost-server/tree/syncgomod. I made some custom changes to add some files. After cloning the branch, create a directory called package enterprise
import (
"testing"
_ "github.com/jonboulle/clockwork"
_ "github.com/prometheus/client_model/go"
)
func TestDummy(t *testing.T) {
} Then come to the root directory and create a symlink to that directory: The structure should be
That's all. You should see the behavior. Let me know if you have any issues. The |
The key to this instability is having a package within the main module that is by default not included in the pattern Symlinks are normally skipped, as are directories named Then when we go to compute “directness”, the extraneous package contributes to the “direct” markings, even though that package is technically an indirect dependency of go/src/cmd/go/internal/modload/load.go Lines 736 to 746 in 24343cb
|
Here is a much smaller reproducer that does not involve a symlink at all:
|
I think the fix is to widen this check to cover only non-ignored packages in the main module: go/src/cmd/go/internal/modload/load.go Line 739 in 24343cb
|
(The reason |
@bcmills - Thanks for looking into this ! I guess this is not a regression right ? Would have been great to have this backported. Nothing too major, but it would have helped us enforce a "go mod tidy" check in our CI. |
Does not appear to be a regression, no. I'm doing some refactoring in the package and module loader for #36460 anyway, though, so I can probably knock it out incidentally in 1.15. I'm curious about the use-case, though: why not treat github.com/mattermost/mattermost-server/enterprise as a separate module? You could publish a module containing a dummy package (with just a bunch of blank-imports) for |
Heh .. well you are not the first person to raise this. AFAIU, it's mostly due to legal+legacy reasons than technical. But the replace directive is an interesting solution. Let me look into it. |
There is a race between go mod tidy and go mod vendor due to golang/go#37376. However, if we give priority to go mod vendor, then gopls complains of inconsistent vendoring. We make go mod tidy happy as it's a more commonly used command than go mod vendor, and is a common problem faced by other devs too
There is a race between go mod tidy and go mod vendor due to golang/go#37376. However, if we give priority to go mod vendor, then gopls complains of inconsistent vendoring. We make go mod tidy happy as it's a more commonly used command than go mod vendor, and is a common problem faced by other devs too
FWIW, I experienced this as well in Go 1.16 |
This no longer reproduces. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What did you do?
Please fetch this branch of mine: https://github.com/mattermost/mattermost-server/tree/tidygomod
???
Things I tried:
What did you expect to see?
I expect no changes to go.mod in whatever order I run those commands.
What did you see instead?
go.mod changed.
/cc @bcmills @jayconrod
The text was updated successfully, but these errors were encountered: