cnst
cnst

Reputation: 27218

Go 1.11 ignores the `vendor` directory, the errors give the impression the directory is never even looked at

I'm having the issue of Go 1.11.4 ignoring the vendor directory of the project I'm in.

When trying to run various commands, I get the following errors, even though the paths referenced are clearly present in the vendor directory. The error message itself appears to indicate that the vendor directory is not even being looked at, at least not for this project that supposedly couldn't be found.

What exactly is going on, and how do I even troubleshoot this?

Below is a straight copy/paste from the terminal, after some pbpaste | sed "s#…#R#g;s#…#M#g;s#…#D#g;s#…#B#g;s#…#example.org#g;s#^#printf \t#g" | pbcopy script to anonymise the repositories.

ubuntu:R {607} go version
go version go1.11.4 linux/amd64
ubuntu:R {608} go build | & head -4
server.go:10:2: cannot find package "example.org/M/B" in any of:
    /usr/local/go/src/example.org/M/B (from $GOROOT)
    /home/ubuntu/go/src/example.org/M/B (from $GOPATH)
R.go:8:2: cannot find package "example.org/M/D" in any of:
ubuntu:R {609} ll vendor/example.org/M/B/
total 28
4 -rw-r--r-- 1 ubuntu ubuntu  156 Jan 10 17:57 .drone.yml
8 -rw-r--r-- 1 ubuntu ubuntu 6207 Jan 10 17:57 Gopkg.lock
4 -rw-r--r-- 1 ubuntu ubuntu  798 Jan 10 17:57 Gopkg.toml
4 -rw-r--r-- 1 ubuntu ubuntu   53 Jan 10 17:57 README.md
8 -rw-r--r-- 1 ubuntu ubuntu 4783 Jan 10 17:57 B.go
ubuntu:R {610} go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ubuntu/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/ubuntu/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build981837178=/tmp/go-build -gno-record-gcc-switches"
ubuntu:R {611} 

Upvotes: 3

Views: 2086

Answers (1)

cnst
cnst

Reputation: 27218

Digging around, it appears that the vendor directory of the project you're working on is magically ignored if the project you're building is not under the src directory within $GOPATH, a requirement which makes absolutely zero sense whatsoever, especially for how difficult it is to troubleshoot this issue, and how unintuitive the whole concept is.

  • One option is to create symlinks within the src in one of the $GOPATH directories back to the actual space on the disc where the project is checked out, and cd through the symlink to compile the project (e.g., cd ~/go/src/R; go build, or pushd ~/go/src/R; go build; popd).

  • Another option is to start checkouts from scratch with the help of the tricks explained over at https://gist.github.com/dmitshur/6927554.

    git config --global url."[email protected]:".insteadOf "https://example.org/"
    go get example.org/M/R
    

Upvotes: 4

Related Questions