Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correctly access javabase in java_integration_test #8047

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
45 changes: 37 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,53 @@
# 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" \
set -euo pipefail
# --- begin runfiles.bash initialization ---
laszlocsomor marked this conversation as resolved.
Show resolved Hide resolved
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="${javabase}"

mkdir -p "$dest" || fail "mkdir -p $dest"
cp -LR "${src}"/* "$dest" || fail "cp -LR \"${src}\"/* \"$dest\""
Expand Down Expand Up @@ -246,17 +275,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_javabase="$(get_real_path "$pkg/my_jdk.symlink")"
else
local -r javabase="${BAZEL_RUNFILES}/${runfiles_relative_javabase}"
local -r my_javabase="${javabase}"
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_javabase',
)
EOF

Expand Down