Commit eed01ac1 authored by Robert Mourning's avatar Robert Mourning Committed by Geoffrey Métais

compile.sh: local.properties init: fix regex matching android sdk/ndk variables.

grep was interpreting the variables as regexes intended to
match themselves. this could cause errors or false positives/negatives if the
variables contain regex metacharacters. now the variables are escaped to
produce regexes that will always and only match themselves.
Signed-off-by: default avatarGeoffrey Métais <geoffrey.metais@gmail.com>
parent 969ea713
...@@ -176,14 +176,20 @@ init_local_props() { ...@@ -176,14 +176,20 @@ init_local_props() {
echo_props > "$1" echo_props > "$1"
return 0 return 0
fi fi
# escape special chars to get regex that matches string
make_regex() {
echo "$1" | sed -e 's/\([[\^$.*]\)/\\\1/g' -
}
android_sdk_regex=`make_regex "${ANDROID_SDK}"`
android_ndk_regex=`make_regex "${ANDROID_NDK}"`
# check for lines setting the SDK directory # check for lines setting the SDK directory
sdk_line_start="^sdk\.dir=" sdk_line_start="^sdk\.dir="
total_sdk_count=`grep -c "${sdk_line_start}" "$1"` total_sdk_count=`grep -c "${sdk_line_start}" "$1"`
good_sdk_count=`grep -c "${sdk_line_start}${ANDROID_SDK}\$" "$1"` good_sdk_count=`grep -c "${sdk_line_start}${android_sdk_regex}\$" "$1"`
# check for lines setting the NDK directory # check for lines setting the NDK directory
ndk_line_start="^ndk\.dir=" ndk_line_start="^ndk\.dir="
total_ndk_count=`grep -c "${ndk_line_start}" "$1"` total_ndk_count=`grep -c "${ndk_line_start}" "$1"`
good_ndk_count=`grep -c "${ndk_line_start}${ANDROID_NDK}\$" "$1"` good_ndk_count=`grep -c "${ndk_line_start}${android_ndk_regex}\$" "$1"`
# if one of each is found and both match the environment vars, no action needed # if one of each is found and both match the environment vars, no action needed
if [ "$total_sdk_count" -eq "1" -a "$good_sdk_count" -eq "1" \ if [ "$total_sdk_count" -eq "1" -a "$good_sdk_count" -eq "1" \
-a "$total_ndk_count" -eq "1" -a "$good_ndk_count" -eq "1" ] -a "$total_ndk_count" -eq "1" -a "$good_ndk_count" -eq "1" ]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment