Skip to content

Commit

Permalink
fix (cli): Improve ./enola dev script launch performance by 40% (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vorburger committed Jun 27, 2024
1 parent f5d4937 commit f3eaaba
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions tools/bazel-java-tool-chain/bazel-java-tool-chain.bash
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,24 @@ function cleanup {
# * https://stackoverflow.com/questions/78057833/how-to-query-bazel-for-the-absolute-jave-home-like-path-to-the-remote-jdk-of

function java_binary {
local current_java_runtime

local ROOT
ROOT="$(realpath "$(dirname "${BASH_SOURCE[0]}"/)")"
cd "$ROOT" || exit 9

# Hide Bazel output, unlike it failed (same also in //enola)
# https://github.com/enola-dev/enola/issues/751
local CACHE_DIR="$ROOT"/../../.cache/
mkdir -p "$CACHE_DIR"
local CACHE="$CACHE_DIR/bazel-java-tool-chain"
local JAVA
JAVA=$(cat "$CACHE")
if [ -f "$JAVA" ]; then
echo "$JAVA"
exit 0
fi

# Hide Bazel output, unless it failed (same also in //enola script)
LOG=$(mktemp)
local current_java_runtime
if ! current_java_runtime="$(bazelisk cquery @bazel_tools//tools/jdk:current_java_runtime \
--output starlark --starlark:file "$ROOT"/bazel-java-tool-chain.bzl 2>"$LOG")"; then
cat "$LOG"
Expand All @@ -49,6 +60,7 @@ function java_binary {
rm "$LOG"
fi

local LOG
LOG=$(mktemp)
if ! output_base="$(bazel info output_base 2>"$LOG")"; then
cat "$LOG"
Expand All @@ -58,5 +70,10 @@ function java_binary {
rm "$LOG"
fi

echo "$output_base/$current_java_runtime/bin/java"
# https://github.com/enola-dev/enola/issues/751
JAVA="$output_base/$current_java_runtime/bin/java"
echo "$JAVA" >"$CACHE"

# This echo must be last, as that's how we return what we found to the caller which sources this file and runs this Bash function
echo "$JAVA"
}

0 comments on commit f3eaaba

Please sign in to comment.