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

Fix Windows desugaring failure for Android builds #16025

Merged
Merged
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 tools/android/BUILD.tools
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ sh_binary(
name = "desugar_java8",
srcs = ["desugar.sh"],
data = ["//src/tools/android/java/com/google/devtools/build/android/desugar:Desugar"],
deps = ["@bazel_tools//tools/bash/runfiles"],
)

alias(
Expand Down
50 changes: 22 additions & 28 deletions tools/android/desugar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,31 @@
# jdk.internal.lambda.dumpProxyClasses and configures Java 8 library rewriting
# through additional flags.

# exit on errors and uninitialized variables
set -eu

RUNFILES="${RUNFILES:-$0.runfiles}"
RUNFILES_MANIFEST_FILE="${RUNFILES_MANIFEST_FILE:-$RUNFILES/MANIFEST}"

IS_WINDOWS=false
case "$(uname | tr [:upper:] [:lower:])" in
msys*|mingw*|cygwin*)
IS_WINDOWS=true
esac

if "$IS_WINDOWS" && ! type rlocation &> /dev/null; then
function rlocation() {
# Use 'sed' instead of 'awk', so if the absolute path ($2) has spaces, it
# will be printed completely.
local result="$(grep "$1" "${RUNFILES_MANIFEST_FILE}" | head -1)"
# If the entry has a space, it is a mapping from a runfiles-path to absolute
# path, otherwise it resolves to itself.
echo "$result" | grep -q " " \
&& echo "$result" | sed 's/^[^ ]* //' \
|| echo "$result"
}
CHECK_FOR_EXE=0
if [[ ! -d $RUNFILES ]]; then
# Try the Windows path
RUNFILES="${RUNFILES:-$0.exe.runfiles}"
CHECK_FOR_EXE=1
fi
RUNFILES_MANIFEST_FILE="${RUNFILES_MANIFEST_FILE:-$RUNFILES/MANIFEST}"
export JAVA_RUNFILES=$RUNFILES
export RUNFILES_LIB_DEBUG=1
# --- begin runfiles.bash initialization v2 ---
# Copy-pasted from the Bazel Bash runfiles library v2.
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
source "$0.runfiles/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
# --- end runfiles.bash initialization v2 ---

# Find script to call:
# Windows (in MANIFEST): <repository_name>/<path/to>/tool
# Linux/MacOS (symlink): ${RUNFILES}/<repository_name>/<path/to>/tool
if "$IS_WINDOWS"; then
DESUGAR="$(rlocation "[^/]*/src/tools/android/java/com/google/devtools/build/android/desugar/Desugar")"
if [[ $CHECK_FOR_EXE -eq 0 ]]; then
DESUGAR="$(rlocation "bazel_tools/src/tools/android/java/com/google/devtools/build/android/desugar/Desugar")"
else
DESUGAR="$(find "${RUNFILES}" -path "*/src/tools/android/java/com/google/devtools/build/android/desugar/Desugar" | head -1)"
DESUGAR="$(rlocation "bazel_tools/src/tools/android/java/com/google/devtools/build/android/desugar/Desugar.exe")"
fi

readonly TMPDIR="$(mktemp -d)"
Expand Down Expand Up @@ -118,3 +111,4 @@ fi
"--jvm_flag=-Djdk.internal.lambda.dumpProxyClasses=${TMPDIR}" \
"$@" \
"${DESUGAR_JAVA8_LIBS_CONFIG[@]}"