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)

Most upvoted comments

@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:

$ mkdir /tmp/issue-32621
$ cd /tmp/issue-32621
$ export GOROOT=$(pwd)
$ export GOPATH=$GOROOT/src/gopath
$ mkdir -p $GOPATH
$ go get golang.org/x/sys/unix
package bytes: unrecognized import path "bytes" (import path does not begin with hostname)
package encoding/binary: unrecognized import path "encoding/binary" (import path does not begin with hostname)
package runtime: unrecognized import path "runtime" (import path does not begin with hostname)
package sort: unrecognized import path "sort" (import path does not begin with hostname)
package strings: unrecognized import path "strings" (import path does not begin with hostname)
package sync: unrecognized import path "sync" (import path does not begin with hostname)
package syscall: unrecognized import path "syscall" (import path does not begin with hostname)
package time: unrecognized import path "time" (import path does not begin with hostname)
package unsafe: unrecognized import path "unsafe" (import path does not begin with hostname)
$ cd src/gopath/src/golang.org/x/sys/unix/
$ go build
can't load package: package gopath/src/golang.org/x/sys/unix: code in directory /tmp/issue-32621/src/gopath/src/golang.org/x/sys/unix expects import "golang.org/x/sys/unix"

@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.