jmhodges / bazel_gomock

Code to create Go mocks for bazel targets using mockgen
MIT License
58 stars 30 forks source link

Support source mode without go.mod file #18

Closed linzhp closed 4 years ago

linzhp commented 5 years ago

Debugging #17, after setting export GOPACKAGESPRINTGOLISTERRORS=true, I got the following message:

GOROOT=/private/var/tmp/_bazel_zplin/1b23f78923ad6c0028e8aab1a0a6d5fb/sandbox/darwin-sandbox/1/execroot/__main__/external/go_sdk GOPATH= GO111MODULE= PWD=/private/var/tmp/_bazel_zplin/1b23f78923ad6c0028e8aab1a0a6d5fb/sandbox/darwin-sandbox/1/execroot/__main__ go [list -f {{context.GOARCH}} {{context.Compiler}} -- unsafe] stderr: <<build cache is disabled by GOCACHE=off, but required as of Go 1.12
>>
2019/05/30 22:50:09 Loading input failed: could not determine GOARCH and Go compiler

Setting GOCACHE fixed the error. Then both go list and go env complained about missing $GOPATH, similar to https://github.com/golang/go/issues/27468#issuecomment-455358031. Since we no longer have GOPATH, we need to set HOME instead. Then mockgen complained about Loading input failed: loading package failed. Creating a go.mod file if it doesn't exist fixed that error.

Together with https://github.com/golang/mock/pull/299, I am finally able to build https://github.com/linzhp/bazel_examples/tree/af8f36c2d268f510d423bd8ea0410266da0da224/gomock

linzhp commented 4 years ago

superseded by #23