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

go/build: Import does not allow passing -mod=vendor to go list #27690

Closed
davidben opened this issue Sep 14, 2018 · 2 comments
Closed

go/build: Import does not allow passing -mod=vendor to go list #27690

davidben opened this issue Sep 14, 2018 · 2 comments
Labels
FrozenDueToAge modules WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@davidben
Copy link
Contributor

Please answer these questions before submitting your issue. Thanks!

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/davidben/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/davidben/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/davidben/boringssl/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/qc/s_xgz3dj7_70mlmvt00ttg6m003f5q/T/go-build943187859=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

It's possible I'm just using this wrong and should be doing something else instead, so I'll describe the context: We use Go in BoringSSL for testing and various tools in our build. But we're a C/C++ library, so living in GOPATH doesn't make much sense. But living outside of GOPATH gets awkward when we want to use multiple packages.

Go modules seemed a good way to reuse Go code more idiomatically within our own tools and also reuse occasional external code. (We've currently vendored a bit of golang.org/x/crypto.)

I played with this a bit, and the former seems to work great. I then tried pulling in golang.org/x/crypto more normally. That too works great standalone, but our CI currently avoids depending on random external servers. (Though that particular module is hosted on googlesource.com too, so maybe that's actually fine?) Still, https://golang.org/cmd/go/#hdr-Modules_and_vendoring suggested go mod vendor plus passing -mod=vendor was the solution for this scenario, so I looked at that.

However, the go/build package (which I used to generate a depfile for integration into our buildsystem) shells out to go list but doesn't provide a way to pass -mod=vendor in, which means querying file lists internally fetches the module.
https://golang.org/src/go/build/build.go#L1008

What did you expect to see?

Some ImportMode, Context setting, or environment variable corresponding to -mod=vendor.

What did you see instead?

Passing defaults in causes go list to hit the network if the dependency is uncached, with no way to change the setting.

@myitcv
Copy link
Member

myitcv commented Sep 17, 2018

@davidben

I suspect (given the brief details you provided) you'll want to switch to go/packages instead of go/build. go/build has very limited module support; go/packages has extensive module awareness and support go -mod=vendor as you describe.

cc @ianthehat as an FYI

@myitcv myitcv added modules WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Sep 17, 2018
@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Oct 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants