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 bazelbuild#8033
  • Loading branch information
buchgr committed Apr 16, 2019
1 parent 938efea commit 7bb734b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 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
33 changes: 30 additions & 3 deletions src/test/shell/bazel/bazel_example_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,35 @@ CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${CURRENT_DIR}/../integration_test_setup.sh" \
|| { echo "integration_test_setup.sh not found!" >&2; exit 1; }

# --- 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 ---

# $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 +71,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 +147,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

0 comments on commit 7bb734b

Please sign in to comment.