jmhodges / bazel_gomock

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

source mode: could not determine GOARCH and Go compiler #17

Closed linzhp closed 4 years ago

linzhp commented 5 years ago

gomock rule fails in source mode with error: Loading input failed: could not determine GOARCH and Go compiler.

Versions

OS: macOS 10.14.5 Go: 1.12.5 Bazel: 0.25.2 rules_go: 0.18.5 golang/mock: 1.3.1 jmhodges/bazel_gomock: e4a4d7dce76eedebd85d1bac72a9c02615c80eff

Reproduce

git clone git@github.com:linzhp/bazel_examples.git
cd bazel_examples
git checkout af8f36c2d268f510d423bd8ea0410266da0da224
bazel build gomock:mocks

Note

I notice that GOARCH="" && source <(go env) && echo $GOARCH will print out things like amd64 on Linux, but it will print empty string on Mac. This line may not work on Mac

jmhodges commented 5 years ago

Hm, I suspect I'm not seeing this because I'm running the GNU bash (installed with homebrew) instead of the default BSD bash.

jmhodges commented 5 years ago

Nope, that ain't it. Seems the code misunderstands how exporting would work.

jmhodges commented 5 years ago

That error, however, doesn't seem likely to be caused by the empty GOARCH? I, of course, can't reproduce locally.

What version of gomock are you using? Does any of this debugging info help? https://github.com/golang/go/issues/30355

Could you post a reproduction for me?

linzhp commented 5 years ago

Just updated linzhp/bazel_examples.git to use latest Gazelle@39b19ce92c43c9915d69db5fa68b1772434df2e9, and mockgen 1.3.1. Still get the same error:

~/bazel_examples$ bazel build --verbose_failures gomock:mocks
INFO: SHA256 (https://github.com/bazelbuild/bazel-gazelle/archive/39b19ce92c43c9915d69db5fa68b1772434df2e9.zip) = e12b1b6bd69544ff0e75d79ed2a99d8326ba3fafe97f8eaf88695e7ad6b37e2a
DEBUG: Rule 'bazel_gazelle' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "e12b1b6bd69544ff0e75d79ed2a99d8326ba3fafe97f8eaf88695e7ad6b37e2a"
INFO: Analyzed target //gomock:mocks (32 packages loaded, 6528 targets configured).
INFO: Found 1 target...
ERROR: /home/zplin/bazel_examples/gomock/BUILD.bazel:14:1: error executing shell command: '/bin/bash -c 
           source <($PWD/external/go_sdk/bin/go env) &&
           export PATH=$GOROOT/bin:$PWD/external/go_sdk/bin:$PATH &&
           $(pwd)/bazel-out/host/bin/external/com_github_g...' failed (Exit 1) bash failed: error executing command 
  (cd /home/zplin/.cache/bazel/_bazel_zplin/1341e6c28d7cbbf89cb6e477e4ed8da8/sandbox/linux-sandbox/14/execroot/__main__ && \
  exec env - \
  /bin/bash -c '
           source <($PWD/external/go_sdk/bin/go env) &&
           export PATH=$GOROOT/bin:$PWD/external/go_sdk/bin:$PATH &&
           $(pwd)/bazel-out/host/bin/external/com_github_golang_mock/mockgen/linux_amd64_stripped/mockgen -source gomock/client.go -package gomock sshClient > bazel-out/k8-fastbuild/bin/gomock/mocks.go
        ')
Execution platform: @bazel_tools//platforms:host_platform

Use --sandbox_debug to see verbose messages from the sandbox: bash failed: error executing command 
  (cd /home/zplin/.cache/bazel/_bazel_zplin/1341e6c28d7cbbf89cb6e477e4ed8da8/sandbox/linux-sandbox/14/execroot/__main__ && \
  exec env - \
  /bin/bash -c '
           source <($PWD/external/go_sdk/bin/go env) &&
           export PATH=$GOROOT/bin:$PWD/external/go_sdk/bin:$PATH &&
           $(pwd)/bazel-out/host/bin/external/com_github_golang_mock/mockgen/linux_amd64_stripped/mockgen -source gomock/client.go -package gomock sshClient > bazel-out/k8-fastbuild/bin/gomock/mocks.go
        ')
Execution platform: @bazel_tools//platforms:host_platform

Use --sandbox_debug to see verbose messages from the sandbox
2019/05/31 04:51:58 Loading input failed: could not determine GOARCH and Go compiler
Target //gomock:mocks failed to build
INFO: Elapsed time: 46.706s, Critical Path: 2.50s
INFO: 10 processes: 10 linux-sandbox.
FAILED: Build did NOT complete successfully
jmhodges commented 4 years ago

What happens if you try https://github.com/jmhodges/bazel_gomock/commit/ec2e84d9bf708841b7129ee94e61c06382c8cfda ?

linzhp commented 4 years ago

It needs more fixes than that. See #18 for all fixes needed.

However, I think we should revert #16, see my comment on that thread

jmhodges commented 4 years ago

Thanks! Mind rebasing on to HEAD now?