aboutsummaryrefslogtreecommitdiff
path: root/toolchains
diff options
context:
space:
mode:
authorLászló Csomor <laszlocsomor@users.noreply.github.com>2018-12-04 16:14:08 +0100
committerGitHub <noreply@github.com>2018-12-04 16:14:08 +0100
commitdaf513702286fe211f291675443235e35e79f34f (patch)
tree18ef785a490b369d62f305c1aaaa52fcd3febe11 /toolchains
parentf4a2bae427c4958af834c34624767b0144f7ab12 (diff)
downloadbazel-skylib-daf513702286fe211f291675443235e35e79f34f.tar.gz
unittest.bzl: supports Windows (#84)
In this commit: - change unittest.bzl to declare a named output file instead of relying on the deprecated [1] default output name (ctx.outputs.executable). - define a new toolchain_type and toolchain rules for cmd.exe and for Bash (basically Windows and non-Windows) - register the new toolchains in workspace.bzl - let unittest.make-created test rules require the new toolchain_type - write the test output script as a Windows batch script or as a Shell script, depending on the selected toolchain This PR enables the Bazel team to break the Bash dependency (for test execution) on Windows, and can run Starlark unittests with the new, Windows-native test wrapper (still under development). See https://github.com/bazelbuild/bazel/issues/5508
Diffstat (limited to 'toolchains')
-rw-r--r--toolchains/unittest/BUILD47
1 files changed, 47 insertions, 0 deletions
diff --git a/toolchains/unittest/BUILD b/toolchains/unittest/BUILD
new file mode 100644
index 0000000..195bbb6
--- /dev/null
+++ b/toolchains/unittest/BUILD
@@ -0,0 +1,47 @@
+load("//lib:unittest.bzl", "TOOLCHAIN_TYPE", "unittest_toolchain")
+
+toolchain_type(
+ name = "toolchain_type",
+ visibility = ["//visibility:public"],
+)
+
+unittest_toolchain(
+ name = "cmd",
+ failure_templ = """@echo off
+echo %s
+exit /b 1
+""",
+ file_ext = ".bat",
+ join_on = "\necho ",
+ success_templ = "@exit /b 0",
+ visibility = ["//visibility:public"],
+)
+
+unittest_toolchain(
+ name = "bash",
+ failure_templ = """#!/bin/sh
+cat <<'EOF'
+%s
+EOF
+exit 1
+""",
+ file_ext = ".sh",
+ join_on = "\n",
+ success_templ = "#!/bin/sh\nexit 0",
+ visibility = ["//visibility:public"],
+)
+
+toolchain(
+ name = "cmd_toolchain",
+ exec_compatible_with = [
+ "@bazel_tools//platforms:windows",
+ ],
+ toolchain = ":cmd",
+ toolchain_type = TOOLCHAIN_TYPE,
+)
+
+toolchain(
+ name = "bash_toolchain",
+ toolchain = ":bash",
+ toolchain_type = TOOLCHAIN_TYPE,
+)