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: second parameter of replace is a network package, it behavior needs to be like require #26648

Closed
yesuu opened this issue Jul 27, 2018 · 4 comments
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@yesuu
Copy link

yesuu commented Jul 27, 2018

What version of Go are you using (go version)?

go version go1.11beta2 linux/amd64
go version devel +6b9c782f9f Wed Aug 1 00:57:00 2018 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What did you do?

this is go.mod:

module project/deploy

require (
    github.com/gin-gonic/gin v1.1.4
    golang.org/x/net/context v0.0.0 // indirect
)

replace (
    golang.org/x/net/context => github.com/golang/net/context v0.0.0-20180724234803-3673e40ba22
)

execute the command go build:

go: finding github.com/golang/net/context v0.0.0-20180724234803-3673e40ba225
go: github.com/golang/net/context@v0.0.0-20180724234803-3673e40ba225: missing github.com/golang/net/context/go.mod at revision 3673e40ba225
go: error loading module requirements

if the version of the second parameter is write as v0.0.0:

module project/deploy

require (
    github.com/gin-gonic/gin v1.1.4
    golang.org/x/net/context v0.0.0 // indirect
)

replace (
    golang.org/x/net/context => github.com/golang/net/context v0.0.0
)

it's actually trying to find v0.0.0:

go: finding github.com/golang/net/context v0.0.0
go: github.com/golang/net/context@v0.0.0: unknown revision context/v0.0.0
go: error loading module requirements

As the title says, it's a bug.

@oiooj oiooj added the modules label Jul 27, 2018
@yesuu yesuu changed the title cmd/go: second parameters of replace is a network package must also have go.mod? cmd/go: second parameter of replace is a network package must also have go.mod? Jul 27, 2018
@yesuu yesuu changed the title cmd/go: second parameter of replace is a network package must also have go.mod? cmd/go: second parameter of replace is a network package, it behavior needs to be like require Aug 1, 2018
@yesuu
Copy link
Author

yesuu commented Aug 2, 2018

When retesting this problem, I found out if:

module project/deploy
require (
    github.com/gin-gonic/gin/binding v0.0.0-20180720165255-220e8d34538f
)

the go build output:

go: finding github.com/gin-gonic/gin/binding v0.0.0-20180720165255-220e8d34538f
go: github.com/gin-gonic/gin/binding@v0.0.0-20180720165255-220e8d34538f: missing github.com/gin-gonic/gin/binding/go.mod at revision 220e8d34538f
go: error loading module requirements

Obviously the second parameter of replace is same with the behavior of require.

The real problem is go.mod only supports module and don't support package. Because if I write module path, it works fine:

module project/deploy
require (
    github.com/gin-gonic/gin v0.0.0-20180720165255-220e8d34538f
)

even if I import github.com/gin-gonic/gin/binding, it still can use the module path github.com/gin-gonic/gin.

When I try use this conclusion on replace, I was frustrated again:

module project/deploy
require (
    golang.org/x/net v0.0.0
)
replace (
    golang.org/x/net => github.com/golang/net v0.0.0-20180724234803-3673e40ba22
)

try go build -v:

Fetching https://golang.org/x/net?go-get=1

The replace do not take effect.

Can anyone tell me the true usage?

@ianlancetaylor
Copy link
Contributor

CC @bcmills

@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 3, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.11 milestone Aug 3, 2018
@bcmills
Copy link
Contributor

bcmills commented Aug 3, 2018

github.com/golang/net/context is a package path, not a module path. (The corresponding module path is just github.com/golang/net.)

If you use go get to construct the go.mod file rather than writing it by hand, you should find that go get github.com/golang/net/context@v0.0.0-20180724234803-3673e40ba22 actually resolves that to a go.mod line like:

require github.com/golang/net v0.0.0-20180724234803-3673e40ba22

(#26602 notwithstanding)

The same is true for your replace directive: it must use module paths, not package paths.

replace (
	golang.org/x/net => github.com/golang/net v0.0.0-20180724234803-3673e40ba22
)

@bcmills
Copy link
Contributor

bcmills commented Aug 3, 2018

The fact that we attempt a network fetch despite the replacement is #26241.

With the issue of module path vs. package path cleared up, I believe that this issue is a duplicate of that one. Please let me know if there are any remaining issues reported here that I've missed.

@bcmills bcmills closed this as completed Aug 3, 2018
@golang golang locked and limited conversation to collaborators Aug 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants