diff options
author | Laszlo Csomor <laszlocsomor@google.com> | 2018-05-29 07:41:10 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-05-29 07:42:14 -0700 |
commit | 7fcbc8ffdead028d19606fefa2fa3be13781da98 (patch) | |
tree | 803a2275982ce67dff4251e5a41a1c8dfd186cf8 /tools/sh | |
parent | 26c86f88be0ddd9d59f4fd3f3afdd769af4ecefc (diff) |
shell toolchain: genrule now uses it
genrule() now uses the shell toolchain (as well as
the ShellConfiguration config fragment) to look up
the shell interpreter's path.
Also the CommandHelper no longer looks up the
shell interpreter's path itself. Instead its ctor
takes the path as an argument. This allows
supporting rules that already use the shell
toolchain and rules that still only consider the
configuration fragment.
With these changes genrule() is now able to use
the shell interpreter registered as a toolchain,
even if there's no `--shell_executable` flag
specified (or its value is empty).
Subsequent commits will migrate more and more
rules to depend on the shell toolchain.
This commit takes us closer to:
1. be able to detect the local shell interpreter's
location, especially when it's not the default
/bin/bash
2. be able to define different shell toolchains
(different interpreter paths) for remote builds
3. gracefully fail the build if the machine has no
shell installed but the action graph included a
shell action
See https://github.com/bazelbuild/bazel/issues/4319
Change-Id: I0674c7e2d5917643d87b48b19a1cb43e606ad2f7
Closes #5282.
Change-Id: I0674c7e2d5917643d87b48b19a1cb43e606ad2f7
PiperOrigin-RevId: 198394021
Diffstat (limited to 'tools/sh')
-rw-r--r-- | tools/sh/BUILD | 19 | ||||
-rw-r--r-- | tools/sh/sh_configure.bzl | 4 |
2 files changed, 21 insertions, 2 deletions
diff --git a/tools/sh/BUILD b/tools/sh/BUILD index 66f710a926..ea6ea974ff 100644 --- a/tools/sh/BUILD +++ b/tools/sh/BUILD @@ -21,3 +21,22 @@ filegroup( ], visibility = ["//tools:__pkg__"], ) + +# Do not depend on this rule. +# Use @bazel_tools//tools/sh:toolchain_type instead. +# +# This rule is available exclusively for the Bazel bootstrapping process. +# +# As part of bootstrapping Bazel, we set up a mock @bazel_tools repo, by +# creating a directory with a WORKSPACE file and symlinking the real tools +# directory into it. This approach however won't use the BUILD.tools files as +# BUILD files, so the fake repo won't be exactly the same as the real one. To +# work around this issue without having to symlink each file in the entire +# tools/** tree and symlinking BUILD.tools files as BUILD files, the +# bootstrapper just symlinks the top tools directory. Therefore to bootstrap +# Bazel, we need those targets in BUILD.tools files that Bazel need to also +# exist in BUILD files. +toolchain_type( + name = "toolchain_type", + visibility = ["//visibility:public"], +) diff --git a/tools/sh/sh_configure.bzl b/tools/sh/sh_configure.bzl index f7c8899420..03c821a6be 100644 --- a/tools/sh/sh_configure.bzl +++ b/tools/sh/sh_configure.bzl @@ -54,7 +54,7 @@ load("@bazel_tools//tools/sh:sh_toolchain.bzl", "sh_toolchain") sh_toolchain( name = "local_sh", - path = "{sh_path}", + path = {sh_path}, visibility = ["//visibility:public"], ) @@ -63,7 +63,7 @@ toolchain( toolchain = ":local_sh", toolchain_type = "@bazel_tools//tools/sh:toolchain_type", ) -""".format(sh_path = sh_path)) +""".format(sh_path = "\"%s\"" % sh_path if sh_path else "None")) sh_config = repository_rule( environ = [ |