diff options
author | Laszlo Csomor <laszlocsomor@google.com> | 2018-06-27 08:29:32 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-06-27 08:31:00 -0700 |
commit | c334bce728c7898559c2492a72f0c88184ba7548 (patch) | |
tree | 0301e5011649bfb0a8a74fbb04cc59321c463b3a /examples/shell/bin.sh | |
parent | db9afe745e855e03aea69a00457bab7aa4a80b5d (diff) |
Windows,examples: //examples/shell now works
The targets in //examples/shell:* now use the Bash
runfiles library in
@bazel_tools//tools/bash/runfiles and work on
Windows.
Also undef the RUNFILES_* envvars in
bazel_example_test::test_shell (which builds the
shell example project) so that the runfiles
library discovers its own runfiles instead of
trying (and failing) to use the enclosing test's
runfiles (which it shouldn't use, because the test
executes "bazel run //examples/shell:bin" so that
target's runfiles are independent of the enclosing
test's runfiles).
Fixes https://github.com/bazelbuild/bazel/issues/3839
Closes #5480.
Change-Id: I44f9bf9b11f7fac0e1c0995a44c2336846dc2bc8
PiperOrigin-RevId: 202313105
Diffstat (limited to 'examples/shell/bin.sh')
-rwxr-xr-x | examples/shell/bin.sh | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/examples/shell/bin.sh b/examples/shell/bin.sh index 5b51ccf06c..9131503b91 100755 --- a/examples/shell/bin.sh +++ b/examples/shell/bin.sh @@ -14,12 +14,28 @@ # See the License for the specific language governing permissions and # limitations under the License. -set -eu +set -euo pipefail +# --- begin runfiles.bash initialization --- +if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then + if [[ -f "$0.runfiles_manifest" ]]; then + export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest" + elif [[ -f "$0.runfiles/MANIFEST" ]]; then + export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST" + elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then + export RUNFILES_DIR="$0.runfiles" + fi +fi +if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then + source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash" +elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then + source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \ + "$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)" +else + echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash" + exit 1 +fi +# --- end runfiles.bash initialization --- -# This allows the script to be both a binary and a library script. If our binary has defined -# RUNFILES then we use it, otherwise we look for our own runfiles. -RUNFILES=${RUNFILES:-$0.runfiles/io_bazel} - -source "${RUNFILES}/examples/shell/lib.sh" +source "$(rlocation io_bazel/examples/shell/lib.sh)" showfile |