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' in module mode reports GOPATH Root and Target fields when the main module is in GOPATH/src #37015

Open
perillo opened this issue Feb 4, 2020 · 2 comments

Comments

@perillo
Copy link

@perillo perillo commented Feb 4, 2020

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

$ go version
go version go1.14beta1 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/home/manlio/.local/bin"
GOCACHE="/home/manlio/.cache/go-build"
GOENV="/home/manlio/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY="github.com/perillo"
GONOSUMDB="github.com/perillo"
GOOS="linux"
GOPATH="/home/manlio/.local/lib/go:/home/manlio/src/go"
GOPRIVATE="github.com/perillo"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/manlio/sdk/go1.14beta1"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/manlio/sdk/go1.14beta1/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build892397541=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version go1.14beta1 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.14beta1
uname -sr: Linux 5.5.1-arch1-1
/usr/lib/libc.so.6: GNU C Library (GNU libc) stable release version 2.30.
gdb --version: GNU gdb (GDB) 8.3.1

What did you do?

From inside a module root directory, where pkg is a non main package.

go list -f 'Target: {{ .Target }}, Root: {{ .Root }}' ./pkg

What did you expect to see?

An empty Target, since with GO111MODULE=on the package archives are no more installed in $GOPATH.

What did you see instead?

Target: /home/manlio/src/go/pkg/linux_amd64/github.com/perillo/gocmd/pkglist.a, Root: /home/manlio/src/go

NOTE: if it is decided that Target will be left empty, I hope that Root will remain.

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Feb 4, 2020

Hmm, interesting.

In a module root outside of GOPATH, I get:

example.com$ go1.14beta1 list -f '{{.ImportPath}}: {{.Target}} (from {{.Root}})' ./foo
example.com/foo:  (from /tmp/tmp.x68zurPJpH/example.com)

And go install is a no-op.

However, in a module contained within GOPATH, I get:

~/src/golang.org/x/mod$ go1.14beta1 list -f '{{.ImportPath}}: {{.Target}} {{.Root}}' ./zip
golang.org/x/mod/zip: /usr/local/google/home/bcmills/pkg/linux_amd64/golang.org/x/mod/zip.a /usr/local/google/home/bcmills

~/src/golang.org/x/mod$ ls ~/pkg/linux_amd64/golang.org/x/mod/zip.a
ls: cannot access '/usr/local/google/home/bcmills/pkg/linux_amd64/golang.org/x/mod/zip.a': No such file or directory

~/src/golang.org/x/mod$ go1.14beta1 install ./zip

~/src/golang.org/x/mod$ ls ~/pkg/linux_amd64/golang.org/x/mod/zip.a
/usr/local/google/home/bcmills/pkg/linux_amd64/golang.org/x/mod/zip.a

So it appears that we are still computing (and using) the GOPATH-mode Root and Target even in module mode. I suspect this is related to #34860 and/or #29111.

CC @jayconrod @matloob

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Feb 4, 2020

The relevant branch seems to be here:

if IsLocalImport(path) {

p.Root = root

We probably should not be following the IsLocalImport branch in module mode at all.

@bcmills bcmills added this to the Backlog milestone Feb 4, 2020
@bcmills bcmills changed the title cmd/go: go list still reports a non empty Target for a non main package in module mode cmd/go: 'go list' reports GOPATH Root and Target fields in module mode when the main module is in GOPATH/src Feb 4, 2020
@bcmills bcmills changed the title cmd/go: 'go list' reports GOPATH Root and Target fields in module mode when the main module is in GOPATH/src cmd/go: 'go list' in module mode reports GOPATH Root and Target fields when the main module is in GOPATH/src Feb 4, 2020
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.