From 348225e4d25b9259489c1ed66eb7eca7612cddcc Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Wed, 13 Jun 2018 05:08:16 -0700 Subject: 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 --- tools/build_defs/repo/git.bzl | 3 +++ tools/build_defs/repo/http.bzl | 2 ++ tools/build_defs/repo/utils.bzl | 6 +++++- 3 files changed, 10 insertions(+), 1 deletion(-) (limited to 'tools') 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: -- cgit v1.2.3