go: cmd/go: relative imports do not work with vendoring

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

go version go1.6.1 linux/amd64

  1. What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

Linux serenity 4.3.0-1-amd64 #1 SMP Debian 4.3.5-1 (2016-02-06) x86_64 GNU/Linux Running golang with Docker image, official golang build, latest image from docker hub. Full reproduction script available with ./run

Source files: https://cdn.si/assets/go-gh-issue-vendoring.tgz

  1. What did you do?

I created a small program, using a local subpackage. main.go (using a subpackage + vendor) = experienced problem. main2.go (using vendored import from main) = works as expected.

Subpackage is imported with: import “./apiservice”. Import of vendored package from this subpackage results in a run/build error.

Also included is a test-runner using the official golang docker image. It’s the same environment, that I’m running the example in. The folder vendor was created with gvt fetch github.com/namsral/flag, full source provided.

  1. What did you expect to see?

Expected output with main.go:

# go run main2.go
Hello world! Network port: 8080
  1. What did you see instead?
# go run main.go
apiservice/apiservice.go:4:8: cannot find package "_/go/src/app/vendor/github.com/namsral/flag" in any of:
        /usr/local/go/src/_/go/src/app/vendor/github.com/namsral/flag (from $GOROOT)
        /go/src/_/go/src/app/vendor/github.com/namsral/flag (from $GOPATH)

Problem:

Import path for local subpackage is not honored. The dot gets converted to underscore, and as a consequence, it’s looking for the vendor directory in the wrong path:

Expected path:

        /usr/local/go/src/app/vendor/github.com/namsral/flag (from $GOROOT)

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 6
  • Comments: 17 (9 by maintainers)

Most upvoted comments

If anybody is coming here for a fix, this worked for me:

  1. My app name is ‘app’ (/go/src/app),
  2. instead of importing ./submodule, import app/submodule
  3. Vendoring starts to work, everything works with go run.

I will not close this issue, just because I expect that this should be fixed in a future version. I hope someone agrees and tags/assigns the issue properly. Relative imports should work with vendoring, but I understand the motivations for FQDN imports. Considering that i’m using them from the main package, which is a reasonable “root” of the project, and if I’ll ever reuse it from another package i would use the FQDN import from a VCS/other.

In the current state I would have to rewrite ‘./’ to $(basename $(dirname $0)) before doing go build/go run, which would require some external tooling like gb. Don’t want external tools for something that simple.