aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/repo.bzl
diff options
context:
space:
mode:
authorGravatar Loo Rong Jie <loorongjie@gmail.com>2018-01-04 11:08:03 +0800
committerGravatar Loo Rong Jie <loorongjie@gmail.com>2018-01-04 11:08:03 +0800
commit9c12d821f6912deb848b1593b059c8490f1f30a1 (patch)
tree27d59c5d4b2326b76c6894f1556aa1bfdde0b2fc /third_party/repo.bzl
parent6db014b44863bab616f026beab461fd646fcb505 (diff)
[Bazel/Windows] Wrap rm -rf in Bash for Windows (and some refactoring)
Diffstat (limited to 'third_party/repo.bzl')
-rw-r--r--third_party/repo.bzl20
1 files changed, 12 insertions, 8 deletions
diff --git a/third_party/repo.bzl b/third_party/repo.bzl
index c29fef9629..11e9c842d2 100644
--- a/third_party/repo.bzl
+++ b/third_party/repo.bzl
@@ -22,6 +22,14 @@ _SINGLE_URL_WHITELIST = depset([
def _is_windows(ctx):
return ctx.os.name.lower().find("windows") != -1
+def _wrap_bash_cmd(ctx, cmd):
+ if _is_windows(ctx):
+ bazel_sh = _get_env_var(ctx, "BAZEL_SH")
+ if not bazel_sh:
+ fail("BAZEL_SH environment variable is not set")
+ cmd = [bazel_sh, "-c", " ".join(cmd)]
+ return cmd
+
def _get_env_var(ctx, name):
if name in ctx.os.environ:
return ctx.os.environ[name]
@@ -46,12 +54,8 @@ def _apply_patch(ctx, patch_file):
# Don't check patch on Windows, because patch is only available under bash.
if not _is_windows(ctx) and not ctx.which("patch"):
fail("patch command is not found, please install it")
- cmd = ["patch", "-p1", "-d", ctx.path("."), "-i", ctx.path(patch_file)]
- if _is_windows(ctx):
- bazel_sh = _get_env_var(ctx, "BAZEL_SH")
- if not bazel_sh:
- fail("BAZEL_SH environment variable is not set")
- cmd = [bazel_sh, "-c", " ".join(cmd)]
+ cmd = _wrap_bash_cmd(
+ ctx, ["patch", "-p1", "-d", ctx.path("."), "-i", ctx.path(patch_file)])
_execute_and_check_ret_code(ctx, cmd)
def _apply_delete(ctx, paths):
@@ -60,8 +64,8 @@ def _apply_delete(ctx, paths):
fail("refusing to rm -rf path starting with '/': " + path)
if ".." in path:
fail("refusing to rm -rf path containing '..': " + path)
- _execute_and_check_ret_code(
- ctx, ["rm", "-rf"] + [ctx.path(path) for path in paths])
+ cmd = _wrap_bash_cmd(ctx, ["rm", "-rf"] + [ctx.path(path) for path in paths])
+ _execute_and_check_ret_code(ctx, cmd)
def _tf_http_archive(ctx):
if ("mirror.bazel.build" not in ctx.attr.urls[0] or