Skip to content

x/tools/cmd/goimports: GOPATH not honored with absolute file paths #16458

@akavel

Description

@akavel

Please answer these questions before submitting your issue. Thanks!

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

go version go1.5.4 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="/home/akavel/gopath/src/zpaslab.com/lockerbox/_vendor:/home/akavel/gopath"
GORACE=""
GOROOT="/home/akavel/go"
GOTOOLDIR="/home/akavel/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT=""
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

  1. What did you do?
    If possible, provide a recipe for reproducing the error.
    A complete runnable program is good.
    A link on play.golang.org is best.

I've upgraded goimports, following the recent "it's now faster" announcement. I retained the old binary, and now I have 2 binaries:

$ LC_ALL=C ll ~/gopath/bin/goimports*
-rwxr-xr-x 1 akavel akavel 5509320 Jul 21 13:59 /home/akavel/gopath/bin/goimports*
-rwxr-xr-x 1 akavel akavel 5323816 Apr 27 14:49 /home/akavel/gopath/bin/goimports.old1*
-rwxr-xr-x 1 akavel akavel 5509320 Jul 21 13:59 /home/akavel/gopath/bin/goimports.old2*
$ LC_ALL=C date -Isec
2016-07-21T14:21:05+0200                                            

Depending whether I run the new one with relative or absolute path to source file, import gets found or not:

$ goimports.old2 /home/akavel/gopath/src/zpaslab.com/lockerbox/overmind/collector_rest_test.go | grep protobuf
$ goimports.old1 /home/akavel/gopath/src/zpaslab.com/lockerbox/overmind/collector_rest_test.go | grep protobuf
        "github.com/golang/protobuf/proto"
$ goimports.old2 ./overmind/collector_rest_test.go | grep protobuf
        "github.com/golang/protobuf/proto"
$ goimports.old1 ./overmind/collector_rest_test.go | grep protobuf
        "github.com/golang/protobuf/proto"

Additional notes:

  • exactly the same behavior happens for packages not in _vendor/, e.g. "zpaslab.com/lockerbox/db"
  • standard library packages are found OK (e.g. "testing")
  • the same seems to happen when using -srcdir (i.e. in vim-go)
  1. What did you expect to see?

All versions would find the import:

$ goimports.old2 /home/akavel/gopath/src/zpaslab.com/lockerbox/overmind/collector_rest_test.go | grep protobuf
        "github.com/golang/protobuf/proto"
$ goimports.old1 /home/akavel/gopath/src/zpaslab.com/lockerbox/overmind/collector_rest_test.go | grep protobuf
        "github.com/golang/protobuf/proto"
$ goimports.old2 ./overmind/collector_rest_test.go | grep protobuf
        "github.com/golang/protobuf/proto"
$ goimports.old1 ./overmind/collector_rest_test.go | grep protobuf
        "github.com/golang/protobuf/proto"
  1. What did you see instead?
$ goimports.old2 /home/akavel/gopath/src/zpaslab.com/lockerbox/overmind/collector_rest_test.go | grep protobuf
$ goimports.old1 /home/akavel/gopath/src/zpaslab.com/lockerbox/overmind/collector_rest_test.go | grep protobuf
        "github.com/golang/protobuf/proto"
$ goimports.old2 ./overmind/collector_rest_test.go | grep protobuf
        "github.com/golang/protobuf/proto"
$ goimports.old1 ./overmind/collector_rest_test.go | grep protobuf
        "github.com/golang/protobuf/proto"

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions