Created
November 15, 2017 13:04
-
-
Save Zetten/0bf6817471c6ab3b59e8a630c988fcf9 to your computer and use it in GitHub Desktop.
Bazel patched http archive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://gist.github.com/damienmg/db6b8515c6f656cd0a6169d87eca66a2 | |
def _new_patched_http_archive_impl(rctx): | |
# Download the archive and extract it | |
rctx.download_and_extract( | |
url=rctx.attr.urls, | |
output=rctx.path(""), | |
stripPrefix=rctx.attr.strip_prefix, | |
type=rctx.attr.type, | |
sha256=rctx.attr.sha256) | |
# Now patch the repository | |
for patch in rctx.attr.patches: | |
patch_file = str(rctx.path(patch).realpath) | |
result = rctx.execute(["bash", "-c", "patch -p1 < " + patch_file]) | |
if result.return_code != 0: | |
fail("Failed to patch (%s): %s" % (result.return_code, result.stderr)) | |
# And finally add the build file | |
rctx.symlink(rctx.attr.build_file, "BUILD.bazel") | |
new_patched_http_archive = repository_rule( | |
implementation=_new_patched_http_archive_impl, | |
attrs={ | |
"urls": attr.string_list(mandatory=True), | |
"patches": attr.label_list(mandatory=True), | |
"sha256": attr.string(mandatory=True), | |
"strip_prefix": attr.string(mandatory=False, default=""), | |
"type": attr.string(mandatory=False, default=""), | |
"build_file": attr.label(mandatory=True, allow_single_file=True), | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment