go: cmd/go: can't load package when GOPATH is under GOROOT
The go command seems to have trouble parsing the package name when it’s under $GOROOT/src. The error is obvious with gccgo (so also with version 1.12). However, I’m not sure if the error from TIP is related or not.
$ go env
GOPATH="/opt/freeware/src/packages/BUILD/go-path"
GOROOT="/opt/freeware"
$ cd $GOPATH/src/golang.org/x/sys/unix/
WITH GCCGO
$ go.gcc version
go version go1.12.2 gccgo (GCC) 9.1.0 aix/ppc64
$ go.gcc build
can't load package: package packages/BUILD/go-path/src/golang.org/x/sys/unix: cannot find package "packages/BUILD/go-path/src/golang.org/x/sys/unix" in any of:
/opt/freeware/src/packages/BUILD/go-path/src/golang.org/x/sys/unix (from $GOROOT)
/opt/freeware/src/packages/BUILD/go-path/src/packages/BUILD/go-path/src/golang.org/x/sys/unix (from $GOPATH)
WITH GO 1.12
$ go version
go version go1.12.5 aix/ppc64
$ go.golang build
can't load package: package packages/BUILD/go-path/src/golang.org/x/sys/unix: code in directory /opt/freeware/src/packages/BUILD/go-path/src/golang.org/x/sys/unix expects import "golang.org/x/sys/unix"
WITH TIP
$ go version
go version devel +d2f0628430 Thu Jun 13 09:51:55 2019 -0500 aix/ppc64
$ go build
go: inconsistent vendoring in /opt/freeware/src/packages/BUILD/go-path/src/golang.org/x/sys:
go.mod requires golang.org/x/sys but vendor/modules.txt does not include it.
run 'go mod tidy; go mod vendor' to sync
This alos happen on Fedora 30 (at least with gccgo). I do agree that having GOPATH under GOROOT isn’t the best idea ever. But this is sometime the case on AIX (and maybe Fedora), because default GOROOT is “/opt/freeware” and the RPM are built under “/opt/freeware/src/packages/BUILD”.
Therefore, is it a true bug in go command or a problem related to how Go RPMs are delivered ?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 21 (18 by maintainers)
@Helflym Thank you the patience 😃 I understand now that you are trying to build the golang.org/x/sys/unix package. I was able to reproduce the issue when building this package. I am continuing analysis now.
To reproduce:
@FiloSottile Should we just add a warning about this unsupported configuration (and fix the GCC default prefix) or try to find the root cause?
The gccgo default for
GOROOT
is definitely problematic. See https://gcc.gnu.org/PR89171. I’ve been intending to take a look at it before the next GCC release.