Skip to content

Commit

Permalink
correctly access javabase in java_integration_test
Browse files Browse the repository at this point in the history
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 bazelbuild#8033
  • Loading branch information
buchgr committed Apr 15, 2019
1 parent c07188a commit 34419ed
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/test/shell/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ sh_test(
data = [
":test-deps",
"//src/test/shell:shell_utils",
"@bazel_tools//tools/bash/runfiles",
],
shard_count = 5,
tags = [
Expand Down
44 changes: 36 additions & 8 deletions src/test/shell/integration/java_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
Expand Down Expand Up @@ -246,17 +274,17 @@ 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"
cat > "$pkg/jvm/BUILD" <<EOF
package(default_visibility=["//visibility:public"])
java_runtime(
name='runtime',
java_home='$javabase',
java_home='$my_java_home',
)
EOF

Expand Down

0 comments on commit 34419ed

Please sign in to comment.