Skip to content

Commit

Permalink
Fix java_stub_template.txt on Windows
Browse files Browse the repository at this point in the history
To define a associative arrary in bash, we need `declare -A` instead of `declare -a`,
but `declare -A` is not supported on macOS, so fall back to the old implementation of rlocation on macOS.

Related issue: bazelbuild#2426

--
Change-Id: Ifd42eea0faa5cdbe73b26c9b52437ef6c771f71c
Reviewed-on: https://cr.bazel.build/8790
PiperOrigin-RevId: 147144803
MOS_MIGRATED_REVID=147144803
  • Loading branch information
meteorcloudy authored and kchodorow committed Feb 10, 2017
1 parent b3589a0 commit ae3ee25
Showing 1 changed file with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ die() {
}

# Windows
PLATFORM="$OSTYPE"
function is_windows() {
# On windows, the shell test actually running on msys
if [[ "${PLATFORM}" =~ msys* ]]; then
true
else
false
fi
[[ "${OSTYPE}" =~ msys* ]]
}

# macOS
function is_macos() {
[[ "${OSTYPE}" =~ darwin* ]]
}

# Parse arguments sequentially until the first unrecognized arg is encountered.
Expand Down Expand Up @@ -177,25 +177,32 @@ if [ -z "$RUNFILES_MANIFEST_ONLY" ]; then
fi
}
else
# Read file into my_array
oifs=$IFS
IFS=$'\n'
my_array=( $(sed -e 's/\r//g' "$RUNFILES_MANIFEST_FILE") )
IFS=$oifs
if ! is_macos; then
# Read file into my_array
oifs=$IFS
IFS=$'\n'
my_array=( $(sed -e 's/\r//g' "$RUNFILES_MANIFEST_FILE") )
IFS=$oifs

# Process each runfile line into a [key,value] entry in runfiles_array
declare -a runfiles_array
for line in "${my_array[@]}"
do
line_split=($line)
runfiles_array[${line_split[0]}]=${line_split[1]}
done
# Process each runfile line into a [key,value] entry in runfiles_array
# declare -A is not supported on macOS because an old version of bash is used.
declare -A runfiles_array
for line in "${my_array[@]}"
do
line_split=($line)
runfiles_array[${line_split[0]}]=${line_split[1]}
done
fi

function rlocation() {
if [[ "$1" = /* ]]; then
echo $1
else
echo ${runfiles_array[$1]}
if is_macos; then
echo $(grep "^$1 " $RUNFILES_MANIFEST_FILE | awk '{ print $2 }')
else
echo ${runfiles_array[$1]}
fi
fi
}
fi
Expand Down

0 comments on commit ae3ee25

Please sign in to comment.