Bazel fails to patch external repos on macOS 13
See original GitHub issueDescription of the bug:
Bazel uses local patch
command by default to apply patches to external repositories. macOS 13 downgraded the system patch command from 2.5.8 to 2.0, causing many patches in Bazel repositories failed to apply:
On macOS 12:
$ patch --version
patch 2.5.8
Copyright (C) 1988 Larry Wall
Copyright (C) 2002 Free Software Foundation, Inc.
This program comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of this program
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.
written by Larry Wall and Paul Eggert
$ which -a patch
/usr/bin/patch
On macOS 13:
$ patch --version
patch 2.0-12u11-Apple
$ which -a patch
/usr/bin/patch
What’s the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
- Create a workspace with the following files
-- BUILD.bazel --
-- WORKSPACE --
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "io_bazel_rules_go",
sha256 = "099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip",
],
)
http_archive(
name = "bazel_gazelle",
sha256 = "efbbba6ac1a4fd342d5122cbdfdb82aeb2cf2862e35022c752eaddffada7c3f3",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.27.0/bazel-gazelle-v0.27.0.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.27.0/bazel-gazelle-v0.27.0.tar.gz",
],
)
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")
go_rules_dependencies()
go_register_toolchains(version = "1.18.3")
gazelle_dependencies()
go_repository(
name = "com_github_gogo_protobuf",
build_directives = [
"gazelle:go_generate_proto false",
],
importpath = "github.com/gogo/protobuf",
patch_args = ["-p1"],
patches = [
"//patches:gogo-protobuf-exports-files.patch",
],
sum = "h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=",
version = "v1.3.2",
)
-- patches/BUILD.bazel --
-- patches/gogo-protobuf-exports-files.patch --
diff -urN a/gogoproto/BUILD.bazel b/gogoproto/BUILD.bazel
--- a/gogoproto/BUILD.bazel 2020-05-26 15:48:27.000000000 -0700
+++ b/gogoproto/BUILD.bazel 2020-05-26 16:06:33.000000000 -0700
@@ -22,3 +22,5 @@
"//protoc-gen-gogo/descriptor:go_default_library",
],
)
+
+exports_files(["gogo.proto"])
- Run the following command:
bazel build @com_github_gogo_protobuf//gogoproto:go_default_library
INFO: Repository com_github_gogo_protobuf instantiated at:
/private/tmp/patch_example/WORKSPACE:38:14: in <toplevel>
Repository rule go_repository defined at:
/private/var/tmp/_bazel_zplin/16dd8b85f2d87562bbf9b6bf72816565/external/bazel_gazelle/internal/go_repository.bzl:313:32: in <toplevel>
ERROR: An error occurred during the fetch of repository 'com_github_gogo_protobuf':
Traceback (most recent call last):
File "/private/var/tmp/_bazel_zplin/16dd8b85f2d87562bbf9b6bf72816565/external/bazel_gazelle/internal/go_repository.bzl", line 311, column 10, in _go_repository_impl
patch(ctx)
File "/private/var/tmp/_bazel_zplin/16dd8b85f2d87562bbf9b6bf72816565/external/bazel_gazelle/internal/go_repository.bzl", line 563, column 17, in patch
fail("Error applying patch %s:\n%s%s" %
Error in fail: Error applying patch //patches:gogo-protobuf-exports-files.patch:
patching file 'gogoproto/BUILD.bazel'
1 out of 1 hunks failed--saving rejects to 'gogoproto/BUILD.bazel.rej'
ERROR: /private/tmp/patch_example/WORKSPACE:38:14: fetching go_repository rule //external:com_github_gogo_protobuf: Traceback (most recent call last):
File "/private/var/tmp/_bazel_zplin/16dd8b85f2d87562bbf9b6bf72816565/external/bazel_gazelle/internal/go_repository.bzl", line 311, column 10, in _go_repository_impl
patch(ctx)
File "/private/var/tmp/_bazel_zplin/16dd8b85f2d87562bbf9b6bf72816565/external/bazel_gazelle/internal/go_repository.bzl", line 563, column 17, in patch
fail("Error applying patch %s:\n%s%s" %
Error in fail: Error applying patch //patches:gogo-protobuf-exports-files.patch:
patching file 'gogoproto/BUILD.bazel'
1 out of 1 hunks failed--saving rejects to 'gogoproto/BUILD.bazel.rej'
ERROR: Error applying patch //patches:gogo-protobuf-exports-files.patch:
patching file 'gogoproto/BUILD.bazel'
1 out of 1 hunks failed--saving rejects to 'gogoproto/BUILD.bazel.rej'
Which operating system are you running Bazel on?
macOS 13
What is the output of bazel info release
?
release 5.3.1
If bazel info release
returns development version
or (@non-git)
, tell us how you built Bazel.
No response
What’s the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD
?
No response
Have you found anything relevant by searching the web?
No response
Any other information, logs, or outputs that you want to share?
Manually install newer version of gpatch with brew install gpatch
works. However, Bazel should not rely on the locally installed patch
command. Instead, it should download either the source code or binary for GNU patch and use that when users don’t provide patch_tool
: https://github.com/bazelbuild/bazel/blob/b422719f35b1ae5ed5f7f83d05cd778e9c58d793/tools/build_defs/repo/utils.bzl#L139
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
patching sources of external repo - Google Groups
to bazel-discuss. Hi,. I have an external repo downloading and compiling just fine. Problem is I need to apply a patch to it...
Read more >Installing Bazel on Ubuntu
On this page · Step 1: Add Bazel distribution URI as a package source · Using Bazel's apt repository. Step 2: Install and...
Read more >How to run mediapipe with c++ on M1 mac - Stack Overflow
In root repository "mediapipe", fix ".bazelversion" file as following. 4.1.0. Then, retried lesson 6 and the download started. bug.
Read more >MediaPipe install fails on OS X - gr33nonline - WordPress.com
usually indicates that Bazel fails to download necessary dependency repositories that MediaPipe needs. MedaiPipe has several dependency ...
Read more >Bazel build fails with "" errors [126764883] - Visible to Public
[exec] ERROR: /mnt/d/studio-master-dev/tools/base/bazel/repositories.bzl:206:13: //external:android/crosstool depends on @androidndk//:default_crosstool in ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think in general, Bazel should not call local
patch
command. It should download and manage the version ofpatch
command. We also run into some CI containers wherepatch
command is not available at all.Looking at this a bit it seems that macOS 13’s version of patch is just more strict about the patch content than gpatch. The problem is your patch content doesn’t appear to match what is generated in the BUILD file in that example before the patch:
If you update the patch to have less content:
Or to have the new correct content:
Things do work as expected. I’m not sure what bazel should do about this case in general though.