question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

go vendor_path doesn't work

See original GitHub issue

The doc of vendor_path says “Packages in these directories are allowed to be imported given just the relative path to the package”. However, when I tried to import a third-party package in the vendor/ directory configured by vendor_path, buck couldn’t import the package.

This is my .buckconfig file:

[go]
  vendor_path = ./vendor

This is my BUCK file:

go_test(
  name='command_test',
  srcs=['command_test.go']
)

This is the command_test.go file:

package main

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestName(t *testing.T) {
	assert.Equal(t, "name", "name")
}

When I ran buck test //:command_test, buck said:

command_test.go:6:2: can't find import: "github.com/stretchr/testify/assert"

However, the package exists in vendor/github.com/stretchr/testify/assert/

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
linzhpcommented, Jan 3, 2018

Now I see the reason. I have package_name='github.com/stretchr/testify/assert' in the BUCK file. So it overrides the vendor_path. Thanks for the help!

0reactions
nemithcommented, Jan 3, 2018

If you turn on verbose output you can see exactly what Buck is doing.

NO_BUCKD=1 buck build //gobin/... -v 3 
Guessing 2645680beb2bdbbb4cef865a248234eb96102568 as the last one used version.
2018-01-03 10:10:41,181 [WARNING][buck_tool.py:469] Not using buckd because NO_BUCKD is set.
PARSING BUCK FILES... 1.3s (100%)
CREATING ACTION GRAPH: FINISHED IN 0.1s
verify_symlink_tree
verify_symlink_tree
verify_symlink_tree
rm -f -r buck-out/bin/gobin/__gobin#transitive-symlink-tree__tree
rm -f -r buck-out/bin/third-party/go/github.com/pkg/errors/__errors#linux_amd64,symlink-tree__tree
rm -f -r buck-out/bin/gobin/__gobin#compile,linux_amd64,symlink-tree__tree
mkdir -p buck-out/bin/gobin/__gobin#compile,linux_amd64,symlink-tree__tree
mkdir -p buck-out/bin/gobin/__gobin#transitive-symlink-tree__tree
mkdir -p buck-out/bin/third-party/go/github.com/pkg/errors/__errors#linux_amd64,symlink-tree__tree
link tree @ buck-out/bin/gobin/__gobin#compile,linux_amd64,symlink-tree__tree
link tree @ buck-out/bin/gobin/__gobin#transitive-symlink-tree__tree
link tree @ buck-out/bin/third-party/go/github.com/pkg/errors/__errors#linux_amd64,symlink-tree__tree
mkdir -p buck-out/gen/third-party/go/github.com/pkg/errors/errors#linux_amd64
BUILT 1/7 JOBS 0.1s //gobin:gobin#transitive-symlink-tree
(cd /home/bbennett/bucktest && GOROOT=/usr/lib/golang GOOS=linux GOARCH=amd64 /usr/lib/golang/pkg/tool/linux_amd64/compile -p third-party/go/github.com/pkg/errors -pack -trimpath /home/bbennett/bucktest -nolocalimports -o buck-out/gen/third-party/go/github.com/pkg/errors/errors#linux_amd64/errors.a -I /home/bbennett/bucktest/buck-out/bin/third-party/go/github.com/pkg/errors/__errors#linux_amd64,symlink-tree__tree -complete /home/bbennett/bucktest/third-party/go/github.com/pkg/errors/errors.go /home/bbennett/bucktest/third-party/go/github.com/pkg/errors/stack.go)
BUILT 2/7 JOBS 0.1s //third-party/go/github.com/pkg/errors:errors
BUILT 3/7 JOBS 0.1s //gobin:gobin#compile,linux_amd64,symlink-tree
BUILT 4/7 JOBS 0.1s //third-party/go/github.com/pkg/errors:errors#linux_amd64,symlink-tree
mkdir -p buck-out/gen/gobin/gobin#compile,linux_amd64
(cd /home/bbennett/bucktest && GOROOT=/usr/lib/golang GOOS=linux GOARCH=amd64 /usr/lib/golang/pkg/tool/linux_amd64/compile -p main -pack -trimpath /home/bbennett/bucktest -nolocalimports -o buck-out/gen/gobin/gobin#compile,linux_amd64/gobin.a -I /home/bbennett/bucktest/buck-out/bin/gobin/__gobin#compile,linux_amd64,symlink-tree__tree -importmap 'github.com/pkg/errors=third-party/go/github.com/pkg/errors' -complete /home/bbennett/bucktest/gobin/main.go)
mkdir -p buck-out/gen/gobin/gobin
(cd /home/bbennett/bucktest && GOROOT=/usr/lib/golang GOOS=linux GOARCH=amd64 /usr/lib/golang/pkg/tool/linux_amd64/link -o buck-out/gen/gobin/gobin/gobin -buildmode exe -L /home/bbennett/bucktest/buck-out/bin/gobin/__gobin#transitive-symlink-tree__tree -extld /bin/g++ buck-out/gen/gobin/gobin#compile,linux_amd64/gobin.a)
BUILT 5/7 JOBS 0.1s //gobin:gobin#compile,linux_amd64
BUILT 6/7 JOBS 0.3s //third-party/go/github.com/pkg/errors:errors#linux_amd64
BUILT 7/7 JOBS 0.3s //gobin:gobin
DOWNLOADED 0 ARTIFACTS, 0.00 BYTES
BUILDING: FINISHED IN 2.8s (100%) 7/7 JOBS, 7 UPDATED, 42.9% CACHE MISS
BUILD SUCCEEDED

Specifically the compile command has imports mapped.

(cd /home/bbennett/bucktest && GOROOT=/usr/lib/golang GOOS=linux GOARCH=amd64 /usr/lib/golang/pkg/tool/linux_amd64/compile -p main -pack -trimpath /home/bbennett/bucktest -nolocalimports -o buck-out/gen/gobin/gobin#compile,linux_amd64/gobin.a -I /home/bbennett/bucktest/buck-out/bin/gobin/__gobin#compile,linux_amd64,symlink-tree__tree -importmap 'github.com/pkg/errors=third-party/go/github.com/pkg/errors' -complete /home/bbennett/bucktest/gobin/main.go)

Since it’s still hard to see -importmap 'github.com/pkg/errors=third-party/go/github.com/pkg/errors' which does the mapping to make the compiler happy. It’s not a really big feature but useful for us.

Read more comments on GitHub >

github_iconTop Results From Across the Web

golang vendor path cannot find package - Stack Overflow
The solution: Move the current working directory into GOPATH/src/ and the problem is solved. Not only the ./vendor can be used, but also...
Read more >
go/build: vendor directories are ignored when outside ... - GitHub
The project gets clone on the build machine in /build/project, which is not inside the go path. The build fails due to import...
Read more >
Go 1.5 Vendor Experiment - Google Git
The short form must always be used: no import path can contain “/vendor/” explicitly. Import comments are ignored in vendored packages. The interpretation...
Read more >
Go | IntelliJ IDEA Documentation - JetBrains
Working with Go modules. In the Project tool window (View | Tool Windows | Project), Go modules are displayed with their full import...
Read more >
Vendoring + submodules: go get error - Google Groups
I am trying to get vendoring working with submodules. While the building part works fine the "go get" ... `go get` doesn't operate...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found