This issue is happening on https://github.com/pyspa/ogp-app/tree/feature/gazelle
v0.22.1
http_archive(
name = "io_bazel_rules_go",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.22.1/rules_go-v0.22.1.tar.gz",
"https://github.com/bazelbuild/rules_go/releases/download/v0.22.1/rules_go-v0.22.1.tar.gz",
],
sha256 = "e6a6c016b0663e06fa5fccf1cd8152eab8aa8180c583ec20c872f4f9953a7ac5",
)
v0.20.0
http_archive(
name = "bazel_gazelle",
urls = [
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/bazel-gazelle/releases/download/v0.20.0/bazel-gaze
lle-v0.20.0.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.20.0/bazel-gazelle-v0.20.0.tar.gz",
],
sha256 = "d8c45ee70ec39a57e7a05e5027c32b1576cc7f16d9dd37135b0eddde45cf1b10",
)
2.2.0
$ bazel version
Build label: 2.2.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue Mar 3 09:26:12 2020 (1583227572)
Build timestamp: 1583227572
Build timestamp as int: 1583227572
All of them are the latest at the timing of this issue.
OS: Linux (Debian)
Arch: amd64
I tried to build a simple Go project with gazelle. In the repository above, I tried the following commands
$ bazel clean
$ go mod tidy
$ bazel run :gazelle -- update-repos -from_file=go.mod
$ bazel build :ogpapp_binary
The build log without error and obtaining the executable binary.
The following error message:
$ bazel build :ogpapp_binary
INFO: Call stack for the definition of repository 'go_googleapis' which is a http_archive (rule definition at /home/yoshifumi/.cache/bazel/_bazel_yoshifumi/f894632a927ea0d624267a6fda09cc9b/external/bazel_tools/tools/build_defs/repo/http.bzl:296:16):
- <builtin>
- /home/yoshifumi/.cache/bazel/_bazel_yoshifumi/f894632a927ea0d624267a6fda09cc9b/external/io_bazel_rules_go/go/private/repositories.bzl:241:9
/home/yoshifumi/.cache/bazel/_bazel_yoshifumi/f894632a927ea0d624267a6fda09cc9b/external/io_bazel_rules_go/go/private/repositories.bzl:209:5
- /home/yoshifumi/.cache/bazel/_bazel_yoshifumi/f894632a927ea0d624267a6fda09cc9b/external/io_bazel_rules_docker/repositories/go_repositories.bzl:33:5
- /home/yoshifumi/.cache/bazel/_bazel_yoshifumi/f894632a927ea0d624267a6fda09cc9b/external/io_bazel_rules_docker/repositories/deps.bzl:34:5
- /home/yoshifumi/personal/ogp-app/WORKSPACE:22:1
INFO: Repository 'go_googleapis' used the following cache hits instead of downloading the corresponding file.
* Hash 'f01a10f3624f078e9d250c9d958f8dc816d29e34cb19709adb5428dea58fb4f2' for https://mirror.bazel.build/github.com/googleapis/googleapis/archive/91ef2d9dd69807b0b79555f22566fb2d81e49ff9.zip
If the definition of 'go_googleapis' was updated, verify that the hashes were also updated.
ERROR: An error occurred during the fetch of repository 'go_googleapis':
Traceback (most recent call last):
File "/home/yoshifumi/.cache/bazel/_bazel_yoshifumi/f894632a927ea0d624267a6fda09cc9b/external/bazel_tools/tools/build_defs/repo/http.bzl", line 84
patch(ctx)
File "/home/yoshifumi/.cache/bazel/_bazel_yoshifumi/f894632a927ea0d624267a6fda09cc9b/external/bazel_tools/tools/build_defs/repo/utils.bzl", line 148, in patch
fail(<1 more arguments>)
Error applying patch @io_bazel_rules_go//third_party:go_googleapis-directives.patch:
patching file BUILD.bazel
patching file WORKSPACE
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file WORKSPACE.rej
patching file google/BUILD.bazel
ERROR: /home/yoshifumi/.cache/bazel/_bazel_yoshifumi/f894632a927ea0d624267a6fda09cc9b/external/com_google_cloud_go/profiler/BUILD.bazel:3:1: @com_google_cloud_go//profiler:go_default_library depends on @go_googleapis//google/devtools/cloudprofiler/v2:cloudprofiler_go_proto in repository @go_googleapis which failed to fetch. no such package '@go_googleapis//google/devtools/cloudprofiler/v2': Traceback (most recent call last):
File "/home/yoshifumi/.cache/bazel/_bazel_yoshifumi/f894632a927ea0d624267a6fda09cc9b/external/bazel_tools/tools/build_defs/repo/http.bzl", line 84
patch(ctx)
File "/home/yoshifumi/.cache/bazel/_bazel_yoshifumi/f894632a927ea0d624267a6fda09cc9b/external/bazel_tools/tools/build_defs/repo/utils.bzl", line 148, in patch
fail(<1 more arguments>)
Error applying patch @io_bazel_rules_go//third_party:go_googleapis-directives.patch:
patching file BUILD.bazel
patching file WORKSPACE
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file WORKSPACE.rej
patching file google/BUILD.bazel
ERROR: Analysis of target '//:ogpapp_binary' failed; build aborted: no such package '@go_googleapis//google/devtools/cloudprofiler/v2': Traceback (most recent call last):
File "/home/yoshifumi/.cache/bazel/_bazel_yoshifumi/f894632a927ea0d624267a6fda09cc9b/external/bazel_tools/tools/build_defs/repo/http.bzl", line 84
patch(ctx)
File "/home/yoshifumi/.cache/bazel/_bazel_yoshifumi/f894632a927ea0d624267a6fda09cc9b/external/bazel_tools/tools/build_defs/repo/utils.bzl", line 148, in patch
fail(<1 more arguments>)
Error applying patch @io_bazel_rules_go//third_party:go_googleapis-directives.patch:
patching file BUILD.bazel
patching file WORKSPACE
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file WORKSPACE.rej
patching file google/BUILD.bazel
INFO: Elapsed time: 0.494s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)
Fetching @org_golang_google_api; fetching
Fetching @com_github_google_pprof; fetching
Not sure exactly what's happening here, but I think some function in your WORKSPACE file is declaring io_bazel_rules_go before your declaration. After a build, when I run grep RULES_GO_VERSION $(bazel info output_base)/external/io_bazel_rules_go/go/def.bzl, it shows you're using v0.21.0.
Try declaring io_bazel_rules_go higher in the file. It's fine for go_rules_dependencies and go_register_toolchains to be called later.
Thank you, @jayconrod, the suggestion solved the issue.
Glad to hear it. Large WORKSPACE files can be difficult to maintain. Unfortunately, I don't think there's much rules_go can do to help in that area.
Most helpful comment
Not sure exactly what's happening here, but I think some function in your
WORKSPACEfile is declaringio_bazel_rules_gobefore your declaration. After a build, when I rungrep RULES_GO_VERSION $(bazel info output_base)/external/io_bazel_rules_go/go/def.bzl, it shows you're usingv0.21.0.Try declaring
io_bazel_rules_gohigher in the file. It's fine forgo_rules_dependenciesandgo_register_toolchainsto be called later.