Skip to content

Commit

Permalink
have bazel_example_test.sh properly depend on
Browse files Browse the repository at this point in the history
- no longer uses $bazel_javabase from testenv.sh
- works with absolute $(JAVABASE) paths and JDK's other than
  local_jdk.

Progress towards #8033

Closes #8041.

PiperOrigin-RevId: 243798469
  • Loading branch information
buchgr authored and copybara-github committed Apr 16, 2019
1 parent aadf364 commit 61bf65a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/test/shell/bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,15 @@ sh_test(
name = "bazel_example_test",
size = "large",
srcs = ["bazel_example_test.sh"],
args = ["$(JAVABASE)"],
data = [
":test-deps",
"//src/test/shell/bazel/apple:objc-deps",
"@bazel_tools//tools/bash/runfiles",
],
shard_count = 3,
tags = ["no_windows"],
toolchains = ["@bazel_tools//tools/jdk:current_java_runtime"],
)

sh_test(
Expand Down
39 changes: 32 additions & 7 deletions src/test/shell/bazel/bazel_example_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,39 @@
#
# Tests the examples provided in Bazel
#

# Load the test setup defined in the parent directory
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${CURRENT_DIR}/../integration_test_setup.sh" \
# --- begin runfiles.bash initialization ---
set -euo pipefail
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 ---

source "$(rlocation "io_bazel/src/test/shell/integration_test_setup.sh")" \
|| { echo "integration_test_setup.sh not found!" >&2; exit 1; }

# $1 is equal to the $(JAVABASE) make variable
javabase="$1"
if [[ $javabase = external/* ]]; then
javabase=${javabase#external/}
fi
javabase="$(rlocation "${javabase}/bin/java")"
javabase=${javabase%/bin/java}

function set_up() {
copy_examples
cat > WORKSPACE <<EOF
Expand All @@ -42,7 +69,7 @@ function test_cpp() {
# An assertion that execute a binary from a sub directory (to test runfiles)
function assert_binary_run_from_subdir() {
( # Needed to make execution from a different path work.
export PATH=${bazel_javabase}/bin:"$PATH" &&
export PATH=${javabase}/bin:"$PATH" &&
mkdir -p x &&
cd x &&
unset JAVA_RUNFILES &&
Expand Down Expand Up @@ -118,8 +145,6 @@ function test_native_python_with_zip() {

function test_shell() {
assert_build "//examples/shell:bin"
unset RUNFILES_DIR
unset RUNFILES_MANIFEST_FILE
assert_bazel_run "//examples/shell:bin" "Hello Bazel!"
assert_test_ok "//examples/shell:test"
}
Expand Down
8 changes: 7 additions & 1 deletion src/test/shell/bin/bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@
# Wrapper script to run bazel in the tests. Any change to this file will
# affect all our integration tests.
#
exec $(rlocation io_bazel/src/bazel) --bazelrc=$TEST_TMPDIR/bazelrc "$@"
bazel_bin=$(rlocation io_bazel/src/bazel)
# unset runfiles environment so that the "inner bazel"
# has to detect its own runfiles
unset RUNFILES_DIR
unset RUNFILES_MANIFEST_FILE
unset RUNFILES_MANIFEST_ONLY
exec $bazel_bin --bazelrc=$TEST_TMPDIR/bazelrc "$@"

0 comments on commit 61bf65a

Please sign in to comment.