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: reference to v2 module incorrectly using subdirectory of module #28083

Open
hyangah opened this Issue Oct 8, 2018 · 4 comments

Comments

Projects
None yet
4 participants
@hyangah
Contributor

hyangah commented Oct 8, 2018

In the source tree of the queried package (and its module)

$ cd /tmp
$ git clone https://github.com/hyangah/explist2
$ cd explist2
$ go list -f '{{.ImportPath}} in {{.Module.Path}}@{{.Module.Version}}' github.com/hyangah/explist2
github.com/hyangah/explist2 in github.com/hyangah/explist2@

vs.

$ mkdir /tmp/temp
$ cd /tmp/temp
$ go mod init temp
go: creating new go.mod: module temp
$ go get github.com/hyangah/explist2
go: finding github.com/hyangah/explist2 v1.0.0
go: downloading github.com/hyangah/explist2 v1.0.0
$ go list -f '{{.ImportPath}} in {{.Module.Path}}@{{.Module.Version}}' github.com/hyangah/explist2
github.com/hyangah/explist2 in github.com/hyangah/explist2@v1.0.0

@hyangah hyangah added the modules label Oct 8, 2018

@myitcv

This comment has been minimized.

Member

myitcv commented Oct 9, 2018

In the first case you are asking for the version of a module within the source tree for that module. To my mind the version of a module in this situation is undefined.

$ cd /tmp
$ git clone https://github.com/hyangah/explist2
Cloning into 'explist2'...
$ cd explist2
$ go list -f '{{.ImportPath}} in {{.Module.Path}}@{{.Module.Version}} [{{.Module.Dir}}]' github.com/hyangah/explist2
github.com/hyangah/explist2 in github.com/hyangah/explist2@ [/tmp/explist2]

In the second case you are querying a module as a dependency (that is present within the readonly-module cache). In this situation the module has been resolved via MVS and hence has a version associated with it.

$ mkdir /tmp/temp
$ cd /tmp/temp
$ go mod init temp
go: creating new go.mod: module temp
$ go get github.com/hyangah/explist2
go: finding github.com/hyangah/explist2 v1.0.0
go: downloading github.com/hyangah/explist2 v1.0.0
$ go list -f '{{.ImportPath}} in {{.Module.Path}}@{{.Module.Version}} [{{.Module.Dir}}]' github.com/hyangah/explist2
github.com/hyangah/explist2 in github.com/hyangah/explist2@v1.0.0 [/root/pkg/mod/github.com/hyangah/explist2@v1.0.0]

What version would you expect to be returned in the first instance out of interest?

@hyangah

This comment has been minimized.

Contributor

hyangah commented Oct 9, 2018

Thanks for the explanation @myitcv . That makes sense.
I thought the above was a simple repro case for what I originally wanted to report. But clearly, that is not the case.

$ pwd
/tmp/explist2
$ tree
.
├── f.go
├── go.mod
├── go.sum
└── v2
    ├── f.go
    ├── go.mod
    └── go.sum
$ go list -f '{{.ImportPath}} in {{.Module.Path}}@{{.Module.Version}}' github.com/hyangah/explist2/v2
github.com/hyangah/explist2/v2 in github.com/hyangah/explist2@

The v2 is set up following the major subdirectory model. I expect querying v2 from the repo root directory to return the same result as the query outside the repo. But it does not. Moreover, it doesn't seem to recognize the v2 as the major version mark.

If I query from the v2 directory, at list the go list seemed to recognize v2 as a version mark.

$ cd v2
$ go list -f '{{.ImportPath}} in {{.Module.Path}}@{{.Module.Version}}' github.com/hyangah/explist2/v2
github.com/hyangah/explist2/v2 in github.com/hyangah/explist2/v2@
@myitcv

This comment has been minimized.

Member

myitcv commented Oct 9, 2018

If I query from the v2 directory, at list the go list seemed to recognize v2 as a version mark.

I don't think the "v2" in "github.com/hyangah/explist2/v2" can be considered a version per se, rather a convention on import paths. Indeed that import path comes entirely from the go.mod, not the fact that the go.mod is in a directory called v2 within github.com/hyangah/explist2.

cc @bcmills who will undoubtedly be tighter on the wording/definitions here than I am.

@hyangah hyangah changed the title from cmd/go: `go list` without -m gives different answers depending on where the command runs to cmd/go: `go list` without -m does not recognize the go.mod file in its subdirectory Oct 9, 2018

@hyangah

This comment has been minimized.

Contributor

hyangah commented Oct 9, 2018

I should've used better wording.
The confusing part is the go.mod file in the subdirectory is not recognized.
The go list command considers any package under subdirectory to be part of the main module.

Even when I added a dependency on v2 from v1, the result is same.

$ cat f.go
package explist2

import "github.com/hyangah/explist2/v2"

var Name = explist2.Name

$ cat go.mod
module github.com/hyangah/explist2

require github.com/hyangah/explist2/v2 v2.0.1

$ go list -f '{{.ImportPath}} in {{.Module.Path}}@{{.Module.Version}}' github.com/hyangah/explist2/v2
github.com/hyangah/explist2/v2 in github.com/hyangah/explist2@

@bcmills bcmills modified the milestones: Go1.11.2, Go1.12 Oct 9, 2018

@bcmills bcmills added the NeedsFix label Oct 24, 2018

@rsc rsc changed the title from cmd/go: `go list` without -m does not recognize the go.mod file in its subdirectory to cmd/go: reference to v2 module incorrectly using subdirectory of module Oct 24, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment