From 34419edc8f6a94518e80865bbfba764b1cec5548 Mon Sep 17 00:00:00 2001 From: Jakob Buchgraber Date: Mon, 15 Apr 2019 16:56:07 +0200 Subject: [PATCH 1/3] correctly access javabase in java_integration_test java_integration_test assumes that $(JAVABASE) is always a runfiles relative path. However, that's not correct as it purely depends on the usage of java_runtime. For example, java_runtime( name = "abs_path_jdk", java_home = "/usr/local/lib/jdk", ) when running with --javabase=//:abs_path_jdk then all $(JAVABASE) make variables will contain "/usr/local/lib/jdk". Progress towards #8033 --- src/test/shell/integration/BUILD | 1 + .../integration/java_integration_test.sh | 44 +++++++++++++++---- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/test/shell/integration/BUILD b/src/test/shell/integration/BUILD index b5233b0b364d0e..adf5ebc692da46 100644 --- a/src/test/shell/integration/BUILD +++ b/src/test/shell/integration/BUILD @@ -164,6 +164,7 @@ sh_test( data = [ ":test-deps", "//src/test/shell:shell_utils", + "@bazel_tools//tools/bash/runfiles", ], shard_count = 5, tags = [ diff --git a/src/test/shell/integration/java_integration_test.sh b/src/test/shell/integration/java_integration_test.sh index a61ff4c4743f6e..8289e1d1be8187 100755 --- a/src/test/shell/integration/java_integration_test.sh +++ b/src/test/shell/integration/java_integration_test.sh @@ -15,24 +15,52 @@ # limitations under the License. # # These are end to end tests for building Java. -CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -source "${CURRENT_DIR}/../shell_utils.sh" \ +# --- 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 --- + +source $(rlocation io_bazel/src/test/shell/shell_utils.sh) \ || { echo "shell_utils.sh not found!" >&2; exit 1; } # Load the test setup defined in the parent directory -source "${CURRENT_DIR}/../integration_test_setup.sh" \ +source $(rlocation io_bazel/src/test/shell/integration_test_setup.sh) \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } set -eu -declare -r runfiles_relative_javabase="$1" +# Might be runfiles relative or an absolute path depending on the +# java_runtime +javabase="$1" +if [[ $javabase = external/* ]]; then + javabase=${javabase#external/} +fi +javabase="$(rlocation "${javabase}/bin/java")" +javabase=${javabase%/bin/java} + add_to_bazelrc "build --package_path=%workspace%" #### HELPER FUNCTIONS ################################################## function setup_local_jdk() { local -r dest="$1" - local -r src="${BAZEL_RUNFILES}/${runfiles_relative_javabase}" + local -r src="${java_home}" mkdir -p "$dest" || fail "mkdir -p $dest" cp -LR "${src}"/* "$dest" || fail "cp -LR \"${src}\"/* \"$dest\"" @@ -246,9 +274,9 @@ function assert_singlejar_works() { setup_local_jdk "$local_jdk" ln -s "my_jdk" "$pkg/my_jdk.symlink" - local -r javabase="$(get_real_path "$pkg/my_jdk.symlink")" + local -r my_java_home="$(get_real_path "$pkg/my_jdk.symlink")" else - local -r javabase="${BAZEL_RUNFILES}/${runfiles_relative_javabase}" + local -r my_java_home="${java_home}" fi mkdir -p "$pkg/jvm" @@ -256,7 +284,7 @@ function assert_singlejar_works() { package(default_visibility=["//visibility:public"]) java_runtime( name='runtime', - java_home='$javabase', + java_home='$my_java_home', ) EOF From 7ac47379c5e03cea2b30ed0236a155155195eaad Mon Sep 17 00:00:00 2001 From: Jakob Buchgraber Date: Mon, 15 Apr 2019 17:33:40 +0200 Subject: [PATCH 2/3] fix build --- src/test/shell/integration/java_integration_test.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/shell/integration/java_integration_test.sh b/src/test/shell/integration/java_integration_test.sh index 8289e1d1be8187..bc50ba28ee4879 100755 --- a/src/test/shell/integration/java_integration_test.sh +++ b/src/test/shell/integration/java_integration_test.sh @@ -60,7 +60,7 @@ add_to_bazelrc "build --package_path=%workspace%" function setup_local_jdk() { local -r dest="$1" - local -r src="${java_home}" + local -r src="${javabase}" mkdir -p "$dest" || fail "mkdir -p $dest" cp -LR "${src}"/* "$dest" || fail "cp -LR \"${src}\"/* \"$dest\"" @@ -274,9 +274,9 @@ function assert_singlejar_works() { setup_local_jdk "$local_jdk" ln -s "my_jdk" "$pkg/my_jdk.symlink" - local -r my_java_home="$(get_real_path "$pkg/my_jdk.symlink")" + local -r my_javabase="$(get_real_path "$pkg/my_jdk.symlink")" else - local -r my_java_home="${java_home}" + local -r my_javabase="${javabase}" fi mkdir -p "$pkg/jvm" @@ -284,7 +284,7 @@ function assert_singlejar_works() { package(default_visibility=["//visibility:public"]) java_runtime( name='runtime', - java_home='$my_java_home', + java_home='$my_javabase', ) EOF From 235402b6a6dcecd824231af22f19cde3888dca4a Mon Sep 17 00:00:00 2001 From: Jakob Buchgraber Date: Tue, 16 Apr 2019 10:36:11 +0200 Subject: [PATCH 3/3] set -euo pipefail --- src/test/shell/integration/java_integration_test.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/shell/integration/java_integration_test.sh b/src/test/shell/integration/java_integration_test.sh index bc50ba28ee4879..13e073b2e9cd99 100755 --- a/src/test/shell/integration/java_integration_test.sh +++ b/src/test/shell/integration/java_integration_test.sh @@ -15,6 +15,7 @@ # limitations under the License. # # These are end to end tests for building Java. +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