Skip to content

Commit a8dacc7

Browse files
ted-xiesgowroji
andauthored
Migrate legacy desugar wrapper to new rlocation() (#16025)
RELNOTES: Fix for desugaring failure on Bazel+Android+Windows build scenario. PiperOrigin-RevId: 464654335 Change-Id: I845093b134dc68ae541603008fe7fee701c7451c Co-authored-by: Gowroji Sunil <[email protected]>
1 parent 6102d33 commit a8dacc7

File tree

2 files changed

+23
-28
lines changed

2 files changed

+23
-28
lines changed

tools/android/BUILD.tools

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ sh_binary(
118118
name = "desugar_java8",
119119
srcs = ["desugar.sh"],
120120
data = ["//src/tools/android/java/com/google/devtools/build/android/desugar:Desugar"],
121+
deps = ["@bazel_tools//tools/bash/runfiles"],
121122
)
122123

123124
alias(

tools/android/desugar.sh

+22-28
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,31 @@
1717
# jdk.internal.lambda.dumpProxyClasses and configures Java 8 library rewriting
1818
# through additional flags.
1919

20-
# exit on errors and uninitialized variables
21-
set -eu
22-
2320
RUNFILES="${RUNFILES:-$0.runfiles}"
24-
RUNFILES_MANIFEST_FILE="${RUNFILES_MANIFEST_FILE:-$RUNFILES/MANIFEST}"
25-
26-
IS_WINDOWS=false
27-
case "$(uname | tr [:upper:] [:lower:])" in
28-
msys*|mingw*|cygwin*)
29-
IS_WINDOWS=true
30-
esac
31-
32-
if "$IS_WINDOWS" && ! type rlocation &> /dev/null; then
33-
function rlocation() {
34-
# Use 'sed' instead of 'awk', so if the absolute path ($2) has spaces, it
35-
# will be printed completely.
36-
local result="$(grep "$1" "${RUNFILES_MANIFEST_FILE}" | head -1)"
37-
# If the entry has a space, it is a mapping from a runfiles-path to absolute
38-
# path, otherwise it resolves to itself.
39-
echo "$result" | grep -q " " \
40-
&& echo "$result" | sed 's/^[^ ]* //' \
41-
|| echo "$result"
42-
}
21+
CHECK_FOR_EXE=0
22+
if [[ ! -d $RUNFILES ]]; then
23+
# Try the Windows path
24+
RUNFILES="${RUNFILES:-$0.exe.runfiles}"
25+
CHECK_FOR_EXE=1
4326
fi
27+
RUNFILES_MANIFEST_FILE="${RUNFILES_MANIFEST_FILE:-$RUNFILES/MANIFEST}"
28+
export JAVA_RUNFILES=$RUNFILES
29+
export RUNFILES_LIB_DEBUG=1
30+
# --- begin runfiles.bash initialization v2 ---
31+
# Copy-pasted from the Bazel Bash runfiles library v2.
32+
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
33+
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
34+
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
35+
source "$0.runfiles/$f" 2>/dev/null || \
36+
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
37+
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
38+
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
39+
# --- end runfiles.bash initialization v2 ---
4440

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

5447
readonly TMPDIR="$(mktemp -d)"
@@ -118,3 +111,4 @@ fi
118111
"--jvm_flag=-Djdk.internal.lambda.dumpProxyClasses=${TMPDIR}" \
119112
"$@" \
120113
"${DESUGAR_JAVA8_LIBS_CONFIG[@]}"
114+

0 commit comments

Comments
 (0)