Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/imports: does not find imports from go.mod #27865

Closed
jeremyschlatter opened this issue Sep 25, 2018 · 2 comments
Closed

x/tools/imports: does not find imports from go.mod #27865

jeremyschlatter opened this issue Sep 25, 2018 · 2 comments
Labels
FrozenDueToAge modules NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@jeremyschlatter
Copy link
Contributor

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

go version go1.11 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/jeremy/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/jeremy/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/jeremy/example/go.mod"
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=/var/folders/97/k5tw9v055r57p9vv2qdl34wh0000gn/T/go-build069916519=/tmp/go-build -gno-record-gcc-switches -fno-common"

(Though repro instructions are given as a Dockerfile, below)

What did you do?

Here's a minimal Docker example. Place the following three files in an empty directory:

withImport.go:
package main

import (
	"fmt"

	"golang.org/x/image/colornames"
)

func main() {
	fmt.Println(colornames.Blue)
}
withoutImport.go:
package main

import "fmt"

func main() {
	fmt.Println(colornames.Blue)
}
Dockerfile:
FROM golang:1.11

RUN go get golang.org/x/tools/cmd/goimports

WORKDIR /home/example
RUN go mod init example

# Cache golang.org/x/images/colornames and populate go.mod and go.sum.
COPY withImport.go p.go
RUN go run p.go 

# Delete the golang.org/x/images/colornames import statement.
COPY withoutImport.go p.go

Then build the docker container and run goimports in it:

$ docker build -t example .
$ docker run example goimports p.go

What did you expect to see?

I expected goimports to find the colornames package, because the package's repo is listed in go.mod and go.sum, and the package itself is in go's cache. (And in the full example where I encountered this in the wild, the package was also imported elsewhere in my project.)

So I expected the output of goimports to look like this:

package main

import (
	"fmt"

	"golang.org/x/image/colornames"
)

func main() {
	fmt.Println(colornames.Blue)
}

What did you see instead?

Since golang.org/x/image/colornames was not present in my GOPATH, goimports failed to find it:

package main

import "fmt"

func main() {
	fmt.Println(colornames.Blue)
}
@gopherbot gopherbot added this to the Unreleased milestone Sep 25, 2018
@bradfitz
Copy link
Contributor

Related: #27287 (temp fix: https://go-review.googlesource.com/c/tools/+/132598), #24661 (meta modules tools tracking bug), etc.

@bradfitz bradfitz added the NeedsFix The path to resolution is known, but the work has not been done. label Sep 25, 2018
@myitcv
Copy link
Member

myitcv commented Sep 26, 2018

I'm going to close this as a dup of #27287

Both are really "dups" of #24661 which is tracking the fixing of all tools with modules, but I've linked to #27287 as the issue for goimports specifically.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants