Skip to content

Commit 98c25b8

Browse files
freakboy3742zanieb
andauthored
[3.13] gh-129156: Fix variable quoting in android-env.sh script (GH-129321) (#129332)
Adds quoting to `android-env.sh` to protect against spaces in paths. (cherry picked from commit a49225c) Co-authored-by: Zanie Blue <[email protected]>
1 parent 6e88741 commit 98c25b8

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

Android/android-env.sh

+17-15
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# This script must be sourced with the following variables already set:
2-
: ${ANDROID_HOME:?} # Path to Android SDK
3-
: ${HOST:?} # GNU target triplet
2+
: "${ANDROID_HOME:?}" # Path to Android SDK
3+
: "${HOST:?}" # GNU target triplet
44

55
# You may also override the following:
6-
: ${api_level:=21} # Minimum Android API level the build will run on
7-
: ${PREFIX:-} # Path in which to find required libraries
6+
: "${api_level:=21}" # Minimum Android API level the build will run on
7+
: "${PREFIX:-}" # Path in which to find required libraries
88

99

1010
# Print all messages on stderr so they're visible when running within build-wheel.
@@ -27,20 +27,20 @@ fail() {
2727
ndk_version=27.1.12297006
2828

2929
ndk=$ANDROID_HOME/ndk/$ndk_version
30-
if ! [ -e $ndk ]; then
30+
if ! [ -e "$ndk" ]; then
3131
log "Installing NDK - this may take several minutes"
32-
yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "ndk;$ndk_version"
32+
yes | "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" "ndk;$ndk_version"
3333
fi
3434

35-
if [ $HOST = "arm-linux-androideabi" ]; then
35+
if [ "$HOST" = "arm-linux-androideabi" ]; then
3636
clang_triplet=armv7a-linux-androideabi
3737
else
38-
clang_triplet=$HOST
38+
clang_triplet="$HOST"
3939
fi
4040

4141
# These variables are based on BuildSystemMaintainers.md above, and
4242
# $ndk/build/cmake/android.toolchain.cmake.
43-
toolchain=$(echo $ndk/toolchains/llvm/prebuilt/*)
43+
toolchain=$(echo "$ndk"/toolchains/llvm/prebuilt/*)
4444
export AR="$toolchain/bin/llvm-ar"
4545
export AS="$toolchain/bin/llvm-as"
4646
export CC="$toolchain/bin/${clang_triplet}${api_level}-clang"
@@ -72,12 +72,12 @@ LDFLAGS="$LDFLAGS -lm"
7272

7373
# -mstackrealign is included where necessary in the clang launcher scripts which are
7474
# pointed to by $CC, so we don't need to include it here.
75-
if [ $HOST = "arm-linux-androideabi" ]; then
75+
if [ "$HOST" = "arm-linux-androideabi" ]; then
7676
CFLAGS="$CFLAGS -march=armv7-a -mthumb"
7777
fi
7878

7979
if [ -n "${PREFIX:-}" ]; then
80-
abs_prefix=$(realpath $PREFIX)
80+
abs_prefix="$(realpath "$PREFIX")"
8181
CFLAGS="$CFLAGS -I$abs_prefix/include"
8282
LDFLAGS="$LDFLAGS -L$abs_prefix/lib"
8383

@@ -87,11 +87,13 @@ fi
8787

8888
# When compiling C++, some build systems will combine CFLAGS and CXXFLAGS, and some will
8989
# use CXXFLAGS alone.
90-
export CXXFLAGS=$CFLAGS
90+
export CXXFLAGS="$CFLAGS"
9191

9292
# Use the same variable name as conda-build
93-
if [ $(uname) = "Darwin" ]; then
94-
export CPU_COUNT=$(sysctl -n hw.ncpu)
93+
if [ "$(uname)" = "Darwin" ]; then
94+
CPU_COUNT="$(sysctl -n hw.ncpu)"
95+
export CPU_COUNT
9596
else
96-
export CPU_COUNT=$(nproc)
97+
CPU_COUNT="$(nproc)"
98+
export CPU_COUNT
9799
fi

0 commit comments

Comments
 (0)