blob: dd2b1e097d3a3ae20797f5d8c53c68201699be0a [file] [log] [blame]
Lorenz Brund13c1c62022-03-30 19:58:58 +02001From bf6362aa01dd00c82996dcabfb1cb20d7919c552 Mon Sep 17 00:00:00 2001
2From: Lorenz Brun <lorenz@nexantic.com>
3Date: Wed, 22 Jul 2020 09:46:56 +0200
Lorenz Brunefb028f2020-07-28 17:04:49 +02004Subject: [PATCH] Add support for prepatching
5
6---
Serge Bazanskif12bedf2021-01-15 16:58:50 +01007 internal/go_repository.bzl | 14 +++++++++++---
8 1 file changed, 11 insertions(+), 3 deletions(-)
Lorenz Brunefb028f2020-07-28 17:04:49 +02009
10diff --git a/internal/go_repository.bzl b/internal/go_repository.bzl
Lorenz Brund13c1c62022-03-30 19:58:58 +020011index 9928fa8..a3af13d 100644
Lorenz Brunefb028f2020-07-28 17:04:49 +020012--- a/internal/go_repository.bzl
13+++ b/internal/go_repository.bzl
Lorenz Brund13c1c62022-03-30 19:58:58 +020014@@ -213,6 +213,8 @@ def _go_repository_impl(ctx):
15 if ctx.attr.debug_mode and result.stderr:
Lorenz Brunefb028f2020-07-28 17:04:49 +020016 print("fetch_repo: " + result.stderr)
17
18+ patch(ctx, True)
19+
20 # Repositories are fetched. Determine if build file generation is needed.
21 build_file_names = ctx.attr.build_file_name.split(",")
22 existing_build_file = ""
Lorenz Brund13c1c62022-03-30 19:58:58 +020023@@ -474,6 +476,10 @@ go_repository = repository_rule(
24 Gazelle directives.""",
25 ),
Lorenz Brunefb028f2020-07-28 17:04:49 +020026
27+ # Patches to apply before running gazelle.
28+ "pre_patches": attr.label_list(),
29+ "pre_patch_cmds": attr.string_list(default = []),
30+
31 # Patches to apply after running gazelle.
Lorenz Brund13c1c62022-03-30 19:58:58 +020032 "patches": attr.label_list(
33 doc = "A list of patches to apply to the repository after gazelle runs.",
34@@ -504,10 +510,11 @@ go_repository = repository_rule(
35 """See repository.md#go-repository for full documentation."""
Lorenz Brunefb028f2020-07-28 17:04:49 +020036
37 # Copied from @bazel_tools//tools/build_defs/repo:utils.bzl
38-def patch(ctx):
39+def patch(ctx, pre_mode = False):
40 """Implementation of patching an already extracted repository"""
41 bash_exe = ctx.os.environ["BAZEL_SH"] if "BAZEL_SH" in ctx.os.environ else "bash"
42- for patchfile in ctx.attr.patches:
43+ patches = ctx.attr.patches if not pre_mode else ctx.attr.pre_patches
44+ for patchfile in patches:
45 command = "{patchtool} {patch_args} < {patchfile}".format(
46 patchtool = ctx.attr.patch_tool,
47 patchfile = ctx.path(patchfile),
Lorenz Brund13c1c62022-03-30 19:58:58 +020048@@ -520,7 +527,8 @@ def patch(ctx):
Lorenz Brunefb028f2020-07-28 17:04:49 +020049 if st.return_code:
50 fail("Error applying patch %s:\n%s%s" %
51 (str(patchfile), st.stderr, st.stdout))
52- for cmd in ctx.attr.patch_cmds:
53+ patch_cmds = ctx.attr.patch_cmds if not pre_mode else ctx.attr.pre_patch_cmds
54+ for cmd in patch_cmds:
55 st = ctx.execute([bash_exe, "-c", cmd])
56 if st.return_code:
57 fail("Error applying patch command %s:\n%s%s" %
58--
Lorenz Brund13c1c62022-03-30 19:58:58 +0200592.25.1
Lorenz Brunefb028f2020-07-28 17:04:49 +020060