aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar Klaus Aehlig <aehlig@google.com>2018-01-15 09:35:16 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-01-15 09:37:25 -0800
commit7831d8c9be23d419a64dfbc48e09fa175e1f1536 (patch)
treeb75c59839661db6024ae80a8c1ca5d7bc3dcecb0 /tools
parentf2075d27ca124156fcd7c01242c552175c0cf145 (diff)
Support patches in http_archive
Support applying a sequence of patches for external repositories imported via http_archive. (Note that we only support the version from @bazel_tools, not the deprecated native rules.) Works towards #3395. Change-Id: I96c746acc04790b051eb686856c04a3ff3c90059 PiperOrigin-RevId: 181975322
Diffstat (limited to 'tools')
-rw-r--r--tools/build_defs/repo/http.bzl16
1 files changed, 16 insertions, 0 deletions
diff --git a/tools/build_defs/repo/http.bzl b/tools/build_defs/repo/http.bzl
index 28c4a79b32..79732bccc0 100644
--- a/tools/build_defs/repo/http.bzl
+++ b/tools/build_defs/repo/http.bzl
@@ -29,6 +29,16 @@ These rules are improved versions of the native http rules and will eventually
replace the native rules.
"""
+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(
+ patchtool=ctx.attr.patch_tool,
+ patchfile=ctx.path(patchfile))
+ st = ctx.execute([bash_exe, "-c", command])
+ if st.return_code:
+ fail("Error applying patch %s:\n%s" % (str(patchfile), st.stderr))
def _http_archive_impl(ctx):
"""Implementation of the http_archive rule."""
@@ -37,6 +47,7 @@ def _http_archive_impl(ctx):
ctx.download_and_extract(ctx.attr.urls, "", ctx.attr.sha256, ctx.attr.type,
ctx.attr.strip_prefix)
+ _patch(ctx)
ctx.file("WORKSPACE", "workspace(name = \"{name}\")\n".format(name=ctx.name))
if ctx.attr.build_file:
print("ctx.attr.build_file %s" % str(ctx.attr.build_file))
@@ -69,6 +80,8 @@ _http_archive_attrs = {
"type": attr.string(),
"build_file": attr.label(),
"build_file_content": attr.string(),
+ "patches": attr.label_list(default=[]),
+ "patch_tool": attr.string(default="patch"),
}
@@ -171,6 +184,9 @@ Args:
This must be an file, http or https URL. Redirections are followed.
Authentication is not supported.
+ patches: A list of files that are to be applied as patches after extracting
+ the archive.
+ patch_tool: the patch(1) utility to use.
"""