golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.24k stars 17.7k forks source link

cmd/go: misleading 'use of internal package not allowed' in GOPATH mode when a subtree vendors its own package #34558

Open srinivas-kandula opened 5 years ago

srinivas-kandula commented 5 years ago

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

$ go version
go version go1.12.7 linux/amd64

Does this issue reproduce with the latest release?

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

RHEL 8 (Ootpa)

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/srinivas/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/srinivas/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build192096706=/tmp/go-build -gno-record-gcc-switches"

Dep version
dep:
 version     : v0.5.4
 build date  :
 git hash    :
 go version  : go1.12.7
 go compiler : gc
 platform    : linux/amd64
 features    : ImportDuringSolve=false

What did you do?

git clone https://github.com/wavefrontHQ/wavefront-kubernetes-collector.git
cd wavefrontHQ/wavefront-kubernetes-collector
dep ensure
make

What did you expect to see?

I was expecting the build to be successful

What did you see instead?

go vet -composites=false ./...
cmd/test-driver/main.go:13:2: use of internal package github.com/wavefrontHQ/wavefront-kubernetes-collector/vendor/github.com/wavefronthq/wavefront-kubernetes-collector/internal/options not allowed
cmd/wavefront-collector/main.go:21:2: use of internal package github.com/wavefrontHQ/wavefront-kubernetes-collector/vendor/github.com/wavefronthq/wavefront-kubernetes-collector/internal/agent not allowed
cmd/wavefront-collector/main.go:22:2: use of internal package github.com/wavefrontHQ/wavefront-kubernetes-collector/vendor/github.com/wavefronthq/wavefront-kubernetes-collector/internal/configuration not allowed
bcmills commented 5 years ago

dep ensure is not part of the go command.

It sounds like dep ensure is for some reason copying packages already within your repo into its own vendor directory. If that is the case, then the go command could perhaps give a better error message, although since it likely only occurs in GOPATH mode we're unlikely to prioritize a fix.

Have you tried it with the latest Go release (1.13.1)? Does it still reproduce, and if so is the error message any more useful?

srinivas-kandula commented 5 years ago

Getting same error message with go version go1.13.1 linux/amd64

go vet -composites=false ./...
cmd/test-driver/main.go:13:2: use of internal package github.com/wavefrontHQ/wavefront-kubernetes-collector/vendor/github.com/wavefronthq/wavefront-kubernetes-collector/internal/options not allowed
cmd/wavefront-collector/main.go:21:2: use of internal package github.com/wavefrontHQ/wavefront-kubernetes-collector/vendor/github.com/wavefronthq/wavefront-kubernetes-collector/internal/agent not allowed

bcmills commented 5 years ago

@srinivas-kandula, can you confirm whether your repo's top-level vendor directory contains copies of packages defined within that repo?

srinivas-kandula commented 5 years ago

@bcmills Appreciate your quick replies.. yup it contains those directories. My top level dir:

$ ls
cmd  deploy  docs  Gopkg.lock  Gopkg.toml  internal  LICENSE  Makefile  open_source_licenes.txt  plugins  README.md  vendor

Vendor directory /go/src/github.com/wavefrontHQ/wavefront-kubernetes-collector/vendor/github.com/wavefronthq/wavefront-kubernetes-collector

 $ls
internal  LICENSE  plugins
bcmills commented 5 years ago

The fix on the go side is a better diagnostic. modload.AmbiguousImportError seems appropriate, except that it's not obvious to me that the package in a position to detect this error has access to that declaration and there are not actually any modules involved.

(Probably this will just be closed when GOPATH mode is deprecated, but you're welcome to close it earlier if you like, or contribute a short-lived fix if it is not too invasive.)

srinivas-kandula commented 5 years ago

I think the real issue is with dep, i am fine to close this issue. Kindly let me know if you have any workarounds/suggestions to overcome this issue?

bcmills commented 5 years ago

As a workaround, you could rm -r vendor/github.com/wavefronthq/wavefront-kubernetes-collector after you run dep ensure.