proteus icon indicating copy to clipboard operation
proteus copied to clipboard

could not import fmt

Open foolusion opened this issue 7 years ago • 5 comments

I'm getting an error when I run proteus on a very basic example package.

[aoneill@foolxps blah]$ proteus proto -f $HOME/src/aponeill.com/blah/blahpb -p aponeill.com/blah
error scanning package "aponeill.com/blah": /home/aoneill/src/aponeill.com/blah/blah.go:3:8: could not import fmt (/home/aoneill/go-tip/src/fmt/format.go:8:2: could not import strconv (/home/aoneill/go-tip/src/strconv/atof.go:13:8: could not import math (/home/aoneill/go-tip/src/map

the blah package just includes

package blah // import "aponeill.com/blah"

import "fmt"

//proteus:generate
type Blah struct {
        Name string
}

//proteus:generate
func (b *Blah) Blaher() {
        fmt.Println("blah")
}

any idea what is going on here?

foolusion avatar Sep 25 '18 00:09 foolusion

Looks like something is wrong with GOPATH/GOROOT. What is an output of go env?

dennwc avatar Sep 25 '18 13:09 dennwc

[aoneill@foolxps blah]$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/aoneill/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/aoneill"
GOPROXY=""
GORACE=""
GOROOT="/home/aoneill/go-tip"
GOTMPDIR=""
GOTOOLDIR="/home/aoneill/go-tip/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-build401827573=/tmp/go-build -gno-record-gcc-switches"

[aoneill@foolxps blah]$ go version
go version go1.11 linux/amd64

[aoneill@foolxps blah]$ proteus --version
proteus version 1.0.0

foolusion avatar Sep 25 '18 14:09 foolusion

The setup is a bit unusual (GOROOT inside GOPATH). It might force proteus to think that package go-tip/src/fmt is some kind of external library, not an fmt package from stdlib. Can you please test if moving GOPATH to a different location (and the project, of course) solves the problem?

dennwc avatar Sep 25 '18 15:09 dennwc

I moved my GOPATH ~/workspace and kept GOROOT ~/go-tip. That fixed it. It seems strange to me since I've been using this set up for years. Should proteus only search $GOPATH/{src,pkg}?

foolusion avatar Sep 25 '18 15:09 foolusion

It looks like a bug in https://github.com/src-d/go-parse-utils, since it has a custom import resolver. Filed an issue there: https://github.com/src-d/go-parse-utils/issues/13

dennwc avatar Sep 25 '18 15:09 dennwc