[Android] [PATCH] compile.sh: local.properties init: fix regex matching android sdk/ndk variables.

Robert Mourning robedmo.git at gmail.com
Sat Jan 27 11:39:42 CET 2018


From: Robert Mourning <robedmo.git at gmail.com>

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.

---
 compile.sh | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/compile.sh b/compile.sh
index 1fa14f9ae..8cfaa957c 100755
--- a/compile.sh
+++ b/compile.sh
@@ -176,14 +176,20 @@ init_local_props() {
         echo_props > "$1"
         return 0
     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
     sdk_line_start="^sdk\.dir="
     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
     ndk_line_start="^ndk\.dir="
     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 [ "$total_sdk_count" -eq "1" -a "$good_sdk_count" -eq "1" \
 	    -a "$total_ndk_count" -eq "1" -a "$good_ndk_count" -eq "1" ]
-- 
2.15.1.windows.2



More information about the Android mailing list