Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

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

Closed
linzhp opened this issue May 22, 2019 · 7 comments · Fixed by #23
Closed

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

linzhp opened this issue May 22, 2019 · 7 comments · Fixed by #23

Comments

@linzhp
Copy link
Contributor

linzhp commented May 22, 2019

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: e4a4d7d

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
Copy link
Owner

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
Copy link
Owner

jmhodges commented May 25, 2019

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

@jmhodges
Copy link
Owner

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? golang/go#30355

Could you post a reproduction for me?

@linzhp
Copy link
Contributor Author

linzhp commented May 31, 2019

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
Copy link
Owner

What happens if you try ec2e84d ?

@linzhp
Copy link
Contributor Author

linzhp commented Jul 17, 2019

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
Copy link
Owner

Thanks! Mind rebasing on to HEAD now?

robbertvanginkel added a commit to robbertvanginkel/bazel_gomock that referenced this issue Jul 31, 2019
Fixes jmhodges#17. Investigating a bit, golang's module mode seems to trigger when using source mode with a fake  module file, resulting in downloading modules  while doing codegen. This can be avoided by prefixing the path passed  to `-source` with `$GOPATH`, so `go/packages` recognizes the source file as being in the GOPATH.

This also removes the `_go_tool_run_shell_stdout`, which  was only  called from one place. Seemed better to remove as compared having to pass the gopath around to prefix the source flag.
jmhodges pushed a commit that referenced this issue Aug 5, 2019
Fixes #17. Investigating a bit, golang's module mode seems to trigger when using source mode with a fake  module file, resulting in downloading modules  while doing codegen. This can be avoided by prefixing the path passed  to `-source` with `$GOPATH`, so `go/packages` recognizes the source file as being in the GOPATH.

This also removes the `_go_tool_run_shell_stdout`, which  was only  called from one place. Seemed better to remove as compared having to pass the gopath around to prefix the source flag.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants