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

Comments

Projects
None yet
4 participants
@yesuu
Copy link

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

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link
Contributor

commented Aug 3, 2018

@ianlancetaylor ianlancetaylor added this to the Go1.11 milestone Aug 3, 2018

@bcmills

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

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 Aug 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.