Importing package present outside $GOPATH

148 views
Skip to first unread message

Nipun sehrawat

unread,
Dec 23, 2013, 2:25:49 PM12/23/13
to golan...@googlegroups.com
Hi, I want to port parts of an existing system written mainly in C++ and Python to Go. It depends on Protobuf and Thrift and I would like to keep the generated Go files outside $GOPATH, so that I don't have to check them into Git. For example, if GOPATH is /code/project/go, I'd like to output the generates go files in /code/project/gen-go/... and include it as a search directory for imports present in $GOPATH.

I tried go build -gcflags '-I /code/project/gen-go' - but it failed to find the package. Looking at the error message, it seems that -I didn't help and only $GOROOT and $GOPATH were searched:

a/b/simple.go:11:8: cannot find package "a/b/test_pb" in any of:
        /usr/local/go/src/pkg/a/b/test_pb (from $GOROOT)
        /code/project/go/src/a/b/test_pb (from $GOPATH)

where a/b/test_pb is present under /code/project/gen-go. Any suggestions on how to achieve this? Or is it not the advisable way to organize Go code?

Thanks,
Nipun
Message has been deleted

Nipun sehrawat

unread,
Dec 23, 2013, 2:52:52 PM12/23/13
to golan...@googlegroups.com
Thanks Islan, I don't want to use .gitignore as the generated files will be intermingled with source files due to similarities in directory structure. Having multiple entries in GOPATH seems reasonable, but will require me to set environment (involving temporary directories) in a complex build environment, which I am trying to avoid.

The -I option seems an elegant (and similar to C/C++) way of specifying include directories. go tool 6g -h says:
  -I dir
        add dir to import search path

 Any insights as to why -I didn't work? What's its intended use?

Thanks,
Nipun

On Monday, December 23, 2013 11:32:16 AM UTC-8, Islan Dberry wrote:
Here are a couple of options:

1. Use .gitignore to ignore the generated files.

2. Specify two directories in GOPATH:

    export GOPATH=/code/project/go:/code/project/gen-go
Reply all
Reply to author
Forward
Message has been deleted
0 new messages