diff options
author | Klaus Aehlig <aehlig@google.com> | 2018-06-13 05:08:16 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-06-13 05:10:15 -0700 |
commit | 348225e4d25b9259489c1ed66eb7eca7612cddcc (patch) | |
tree | f8e6aff632032128fa8d750b4364615c59759d44 /tools | |
parent | 8f5b096c0aeef427c08398e6c3ecf8befec7fded (diff) |
Skylark repositories: support additional arguments for the patch tool
Instead of hard-coding "-p0", allow the arguments for that patch tool
to be overridden. In particular, this supports the use case of patches
generated with `git format-patch` which are to be read as `-p1`.
Improves on #5379.
Closes #4974 as superseded.
Change-Id: I809fde14beab21d8a755ba4f1706b602bae3c1bb
PiperOrigin-RevId: 200373909
Diffstat (limited to 'tools')
-rw-r--r-- | tools/build_defs/repo/git.bzl | 3 | ||||
-rw-r--r-- | tools/build_defs/repo/http.bzl | 2 | ||||
-rw-r--r-- | tools/build_defs/repo/utils.bzl | 6 |
3 files changed, 10 insertions, 1 deletions
diff --git a/tools/build_defs/repo/git.bzl b/tools/build_defs/repo/git.bzl index 1ea5804d56..a46330542c 100644 --- a/tools/build_defs/repo/git.bzl +++ b/tools/build_defs/repo/git.bzl @@ -102,6 +102,7 @@ _common_attrs = { "strip_prefix": attr.string(default = ""), "patches": attr.label_list(default = []), "patch_tool": attr.string(default = "patch"), + "patch_args": attr.string_list(default = ["-p0"]), "patch_cmds": attr.string_list(default = []), } @@ -161,6 +162,7 @@ Args: patches: A list of files that are to be applied as patches after extracting the archive. patch_tool: the patch(1) utility to use. + patch_args: arguments given to the patch tool, defaults to ["-p0"] patch_cmds: sequence of commands to be applied after patches are applied. """ @@ -196,5 +198,6 @@ Args: patches: A list of files that are to be applied as patches after extracting the archive. patch_tool: the patch(1) utility to use. + patch_args: arguments given to the patch tool, defaults to ["-p0"] patch_cmds: sequence of commands to be applied after patches are applied. """ diff --git a/tools/build_defs/repo/http.bzl b/tools/build_defs/repo/http.bzl index 02879f4b7e..fffe226d7f 100644 --- a/tools/build_defs/repo/http.bzl +++ b/tools/build_defs/repo/http.bzl @@ -119,6 +119,7 @@ _http_archive_attrs = { "build_file_content": attr.string(), "patches": attr.label_list(default = []), "patch_tool": attr.string(default = "patch"), + "patch_args": attr.string_list(default = ["-p0"]), "patch_cmds": attr.string_list(default = []), "workspace_file": attr.label(), "workspace_file_content": attr.string(), @@ -239,6 +240,7 @@ Args: patches: A list of files that are to be applied as patches after extracting the archive. patch_tool: the patch(1) utility to use. + patch_args: arguments given to the patch tool, defaults to ["-p0"] patch_cmds: sequence of commands to be applied after patches are applied. """ diff --git a/tools/build_defs/repo/utils.bzl b/tools/build_defs/repo/utils.bzl index b76bac960e..4839b3e73b 100644 --- a/tools/build_defs/repo/utils.bzl +++ b/tools/build_defs/repo/utils.bzl @@ -66,9 +66,13 @@ def patch(ctx): """Implementation of patching an already extracted repository""" bash_exe = ctx.os.environ["BAZEL_SH"] if "BAZEL_SH" in ctx.os.environ else "bash" for patchfile in ctx.attr.patches: - command = "{patchtool} -p0 < {patchfile}".format( + command = "{patchtool} {patch_args} < {patchfile}".format( patchtool = ctx.attr.patch_tool, patchfile = ctx.path(patchfile), + patch_args = " ".join([ + "'%s'" % arg + for arg in ctx.attr.patch_args + ]), ) st = ctx.execute([bash_exe, "-c", command]) if st.return_code: |