go 1.5 vendoring not working in bazel sandbox

200 views
Skip to first unread message

linux...@gmail.com

unread,
Aug 31, 2015, 4:41:32 PM8/31/15
to golang-nuts
Hi, all

I am testing a custom bazel build rule which call "go install pkg" which relies on a vendor directory. I found that when sandboxing is enabled (by default, to disable it I had to modify bazel source code), the build failed:

cannot find package "github.com/lib/pq" in any of:
        /usr/local/go/src/github.com/lib/pq (from $GOROOT)
        /home/user/.cache/bazel/_bazel_user/3b02491ddc53c52212e2a2141d5f6409/bazel-demo/src/github.com/lib/pq
(from $GOPATH)


Of course GO15VENDOREXPERIMENT has been set and the vendor code has been available in /home/user/.cache/bazel/_bazel_user/3b02491ddc53c52212e2a2141d5f6409/bazel-demo/src/demo/vendor/github.com/lib/pq (which is a synlink to project directory)

And "go env" in the bazel run shows the correct env vars:

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/user/.cache/bazel/_bazel_advisory/3b02491ddc53c52212e2a2141d5f6409/bazel-demo"
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"


The same code passes if sandboxing was disabled.

So it looks like go tool tried to find $GOPATH/src/github.com/lib/pq instead of $GOPATH/src/bazel-demo/vendor/github.com/lib/pq in sandbox.


I found it's caused by sandboxing because the same code compiles well under a machine which has an older linux kernel so sandboxing is not available, but failed on a machine with newer kernel.  It also passed on newer kernel machine when sandboxing was manually disabled.

Any suggestions?

Thanks!

Tamás Gulácsi

unread,
Aug 31, 2015, 4:45:08 PM8/31/15
to golang-nuts
Don't use symlinks.

linux...@gmail.com

unread,
Aug 31, 2015, 5:35:43 PM8/31/15
to golang-nuts
The problem is not about using symlinks (and the symlink is created by bazel, not me).  With sandboxing turned off the code can be built without problem.



On Monday, August 31, 2015 at 1:45:08 PM UTC-7, Tamás Gulácsi wrote:
Don't use symlinks.

Matt Farina

unread,
Aug 31, 2015, 9:09:30 PM8/31/15
to golang-nuts
Can you check the version of go your using? It should look in the vendor directory, the GOPATH, and finally the GOROOT. It doesn't appear to be looking in the vendor directory first. Are you using go 1.5?

linux...@gmail.com

unread,
Aug 31, 2015, 9:39:46 PM8/31/15
to golang-nuts
Yes, I am pretty sure, I have only one version of go installed.  The "go env" output above is printed from the bazel execution (at run-time), which has the correct GO15VENDOREXPERIMENT variable set.  Another fact is that the same code can be built successfully with Bazel if the sandbox was turned off (I have to change isSupported() to return false in this file: https://github.com/google/bazel/blob/a60b01b7a031b29e3410fd98e54fed55c07f853c/src/main/java/com/google/devtools/build/lib/sandbox/NamespaceSandboxRunner.java and then rebuilt bazel).

Thanks!

linux...@gmail.com

unread,
Sep 1, 2015, 2:23:53 AM9/1/15
to golang-nuts, linux...@gmail.com
I figured out that this is not an issue of golang, but a general problem with bazel for golang.  The issue is that bazel dynamically add symlinks for packages (not golang packages), and the the go pkg is not symlink-ed.  Seemed we have to wait for bazel to officially add go support.
Reply all
Reply to author
Forward
0 new messages