1# Copyright 2024 The Bazel Authors. All rights reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15# --- begin runfiles.bash initialization v3 --- 16# Copy-pasted from the Bazel Bash runfiles library v3. 17set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash 18source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ 19 source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ 20 source "$0.runfiles/$f" 2>/dev/null || \ 21 source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ 22 source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ 23 { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e 24# --- end runfiles.bash initialization v3 --- 25set +e 26 27bin=$(rlocation $BIN_RLOCATION) 28if [[ -z "$bin" ]]; then 29 echo "Unable to locate test binary: $BIN_RLOCATION" 30 exit 1 31fi 32 33function test_invocation() { 34 actual=$($bin) 35 # How we detect if a zip file was executed from depends on which bootstrap 36 # is used. 37 # bootstrap_impl=script outputs RULES_PYTHON_ZIP_DIR=<somepath> 38 # bootstrap_impl=system_python outputs file:.*Bazel.runfiles 39 expected_pattern="Hello" 40 if ! (echo "$actual" | grep "$expected_pattern" ) >/dev/null; then 41 echo "Test case failed: $1" 42 echo "expected output to match: $expected_pattern" 43 echo "but got:\n$actual" 44 exit 1 45 fi 46} 47 48# Test invocation with RUNFILES_DIR set 49unset RUNFILES_MANIFEST_FILE 50if [[ ! -e "$RUNFILES_DIR" ]]; then 51 echo "Runfiles doesn't exist: $RUNFILES_DIR" 52 exit 1 53fi 54test_invocation "using RUNFILES_DIR" 55 56 57orig_runfiles_dir="$RUNFILES_DIR" 58unset RUNFILES_DIR 59 60# Test invocation using manifest within runfiles directory (output manifest) 61# NOTE: this file may not actually exist in our test, but that's OK; the 62# bootstrap just uses the path to find the runfiles directory. 63export RUNFILES_MANIFEST_FILE="$orig_runfiles_dir/MANIFEST" 64test_invocation "using RUNFILES_MANIFEST_FILE with output manifest" 65 66# Test invocation using manifest outside runfiles (input manifest) 67# NOTE: this file may not actually exist in our test, but that's OK; the 68# bootstrap just uses the path to find the runfiles directory. 69export RUNFILES_MANIFEST_FILE="${orig_runfiles_dir%%.runfiles}.runfiles_manifest" 70test_invocation "using RUNFILES_MANIFEST_FILE with input manifest" 71 72# Test invocation without any runfiles env vars set 73unset RUNFILES_MANIFEST_FILE 74test_invocation "using no runfiles env vars" 75