Skip to content
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: 'go list -mod=readonly' erroneously resolves imports from replaced modules #41577

Open
bcmills opened this issue Sep 23, 2020 · 2 comments
Open
Assignees
Milestone

Comments

@bcmills
Copy link
Member

@bcmills bcmills commented Sep 23, 2020

When -mod=readonly is set, go list should refuse to resolve missing dependencies, and normally does.

However, if the dependency can be satisfied by adding a requirement on a module mentioned in a replace directive, the usual lookup disabled error message is suppressed, and go list instead fails with updates to go.mod needed:

example.com$ go version
go version devel +150bd4ff Wed Sep 23 07:51:17 2020 +0000 linux/amd64

example.com$ go list -mod=readonly example.com/x
cannot find module providing package example.com/x: import lookup disabled by -mod=readonly

example.com$ go mod edit -replace=example.com/x@v0.1.0=./x

example.com$ go list -mod=readonly example.com/x
go: found example.com/x in example.com/x v0.1.0
go: updates to go.mod needed, disabled by -mod=readonly

-- go.mod --
module example.com

go 1.16
-- x/go.mod --
module example.com/x

go 1.16
-- x/x.go --
package x
@bcmills bcmills added this to the Go1.16 milestone Sep 23, 2020
@bcmills bcmills self-assigned this Sep 23, 2020
@gopherbot
Copy link

@gopherbot gopherbot commented Sep 29, 2020

Change https://golang.org/cl/258220 mentions this issue: cmd/go/internal/modload: rework replacements in the Query functions

gopherbot pushed a commit that referenced this issue Oct 16, 2020
'go mod tidy' has been able to use replaced versions since CL 152739,
but 'go get' failed for many of the same paths. Now that we are
recommending 'go get' more aggressively due to #40728, we should make
that work too.

In the future, we might consider factoring out the new replacementRepo
type so that 'go list' can report the new versions as well.

For #41577
For #41416
For #37438
Updates #26241

Change-Id: I9140c556424b584fdd9bdd0a747842774664a7d8
Reviewed-on: https://go-review.googlesource.com/c/go/+/258220
Trust: Bryan C. Mills <bcmills@google.com>
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
@gopherbot
Copy link

@gopherbot gopherbot commented Oct 17, 2020

Change https://golang.org/cl/263266 mentions this issue: cmd/go/internal/modload: fix sort condition in (*replacementRepo).Versions

gopherbot pushed a commit that referenced this issue Oct 17, 2020
…sions

In CL 258220 I added replacement versions to the repo versions used in
the modload.Query functions. The versions are computed from a map in
the modfile index, which has a nondeterministic iteration order.

I added a short-circuit condition to skip sorting in the (vastly
common) case where no replacement versions are added. However, while
cleaning up the change I accidentally deleted the line of code that
sets that condition. As a result, the test of that functionality
(mod_get_replaced) has been failing nondeterministically.

This change fixes the condition by comparing the slices before and
after adding versions, rather than by setting a separate variable.
The test now passes reliably (tested with -count=200).

Updates #41577
Updates #41416
Updates #37438
Updates #26241

Change-Id: I49a66a3a5510da00ef42b47f20a168de66100db6
Reviewed-on: https://go-review.googlesource.com/c/go/+/263266
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.