Skip to content

Commit abd0666

Browse files
committed
Update test scripts to use POSIX shell
1 parent 75cfb4b commit abd0666

File tree

7 files changed

+90
-91
lines changed

7 files changed

+90
-91
lines changed

tests/build_all.sh

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/bash
1+
#!/bin/sh
2+
#
23
# Runs all tests available on this system.
34
#
45
# Android: Requires ANDROID_NDK_HOME set.
@@ -8,39 +9,41 @@
89
# For verbose mode, use:
910
# ./build_all.sh -v
1011

11-
if ! type cmake &> /dev/null; then
12-
echo "cmake not found, exiting."
13-
exit -1
12+
if ! type cmake > /dev/null 2>&1; then
13+
echo ">>> Error: cmake not found"
14+
exit 1
1415
fi
1516

1617
while getopts "v" OPTION; do
17-
case $OPTION in
18-
v) VERBOSE=1
19-
;;
20-
esac
18+
case $OPTION in
19+
v) VERBOSE=1
20+
;;
21+
*)
22+
;;
23+
esac
2124
done
2225

2326
run_test() {
2427
if [ -n "$VERBOSE" ]; then
25-
echo ">>> $@"
26-
"$@"
27-
local result=$?
28-
printf ">>> $@: "
28+
echo ">>> $1"
29+
"$1"
30+
result=$?
31+
printf ">>> %s: " "$1"
2932
else
3033
# Execute in background, showing spinner
31-
printf "$@: "
32-
"$@" > /dev/null 2>&1 &
34+
printf "%s: " "$1"
35+
"$1" > /dev/null 2>&1 &
3336
pid=$!
3437
i=0
3538
spin='-\|/'
3639
while kill -0 $pid 2>/dev/null; do
37-
i=$(( (i + 1) % 4 ))
38-
printf "\b${spin:$i:1}"
40+
i=$(( i % 4 + 1 ))
41+
printf "\b%s" "$(echo "$spin" | cut -c $i)"
3942
sleep .1
4043
done
4144
printf "\b"
4245
wait $pid
43-
local result=$?
46+
result=$?
4447
fi
4548
if [ $result -eq 0 ]; then
4649
echo "Success"
@@ -49,24 +52,23 @@ run_test() {
4952
fi
5053
}
5154

52-
if [[ -z "${ANDROID_NDK_HOME}" ]]; then
55+
if [ -z "${ANDROID_NDK_HOME}" ]; then
5356
echo "./build_android.sh: Skipped (ANDROID_NDK_HOME not set)"
5457
else
5558
run_test ./build_android.sh
5659
run_test ./build_android_examples.sh
5760
fi
5861

59-
if ! type xcodebuild &> /dev/null; then
62+
if ! type xcodebuild > /dev/null 2>&1; then
6063
echo "./build_apple.sh: Skipped (xcodebuild not found)"
6164
else
6265
run_test ./build_apple.sh
6366
run_test ./build_apple_examples.sh
6467
fi
6568

66-
if ! type emcmake &> /dev/null; then
69+
if ! type emcmake > /dev/null 2>&1; then
6770
echo "./build_emscripten.sh: Skipped (emcmake not found)"
6871
else
6972
run_test ./build_emscripten.sh
7073
run_test ./build_emscripten_examples.sh
7174
fi
72-

tests/build_android.sh

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
1-
#!/bin/bash
2-
if [[ -z "${ANDROID_NDK_HOME}" ]]; then
1+
#!/bin/sh
2+
3+
if [ -z "${ANDROID_NDK_HOME}" ]; then
34
echo "Error: ANDROID_NDK_HOME not set"
4-
exit -1
5+
exit 1
56
fi
67

7-
NDK_MAJOR_VERSION=$(grep "Pkg.Revision" $ANDROID_NDK_HOME/source.properties | sed -e 's/Pkg.Revision = \([0-9]*\).*/\1/')
8-
if [[ "$NDK_MAJOR_VERSION" < 17 ]]; then
8+
NDK_MAJOR_VERSION=$(grep "Pkg.Revision" "$ANDROID_NDK_HOME"/source.properties | sed -e 's/Pkg.Revision = \([0-9]*\).*/\1/')
9+
if [ "$NDK_MAJOR_VERSION" -lt 17 ]; then
910
echo "Error: NDK 17 or newer required"
10-
exit -1
11+
exit 1
1112
fi
1213

1314
WIN64_MAKE=$ANDROID_NDK_HOME/prebuilt/windows-x86_64/bin/make.exe
14-
if [ -f $WIN64_MAKE ]; then
15-
WIN64_FLAGS=(-G "Unix Makefiles" -D CMAKE_MAKE_PROGRAM=$WIN64_MAKE)
15+
if [ -f "$WIN64_MAKE" ]; then
16+
set -- "$@" -G "Unix Makefiles" -D CMAKE_MAKE_PROGRAM="$WIN64_MAKE"
1617
fi
1718

18-
declare -a abis=("armeabi-v7a" "armeabi-v7a with NEON" "arm64-v8a" "x86" "x86_64")
19-
20-
for abi in "${abis[@]}"; do
21-
if [[ "$abi" == "x86_64" && "$NDK_MAJOR_VERSION" < 19 ]]; then
19+
for abi in "armeabi-v7a" "armeabi-v7a with NEON" "arm64-v8a" "x86" "x86_64"; do
20+
if [ "$abi" = "x86_64" ] && [ "$NDK_MAJOR_VERSION" -lt 19 ]; then
2221
# An error in NDK 18 (and older) prevents CMake from finding x86_64 libraries.
23-
echo ">>> Skipping ABI $abi (NDK 19 or newer required)"
22+
echo ">>> Android: Skipping ABI $abi (NDK 19 or newer required)"
2423
continue
2524
fi
26-
echo ">>> Building ABI $abi"
27-
rm -Rf "build/android_$abi"
25+
echo ">>> Android: Building ABI $abi"
26+
rm -rf "build/android_$abi"
2827
cmake -S .. -B "build/android_$abi" \
2928
-D GLFM_USE_CLANG_TIDY=ON \
30-
-D CMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake \
29+
-D CMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME"/build/cmake/android.toolchain.cmake \
3130
-D CMAKE_C_FLAGS=-Werror \
3231
-D CMAKE_VERBOSE_MAKEFILE=ON \
3332
-D ANDROID_ABI="$abi" \
34-
"${WIN64_FLAGS[@]}" || exit $?
33+
"$@" || exit $?
3534
cmake --build "build/android_$abi" || exit $?
3635
done

tests/build_android_examples.sh

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1-
#!/bin/bash
2-
if [[ -z "${ANDROID_NDK_HOME}" ]]; then
1+
#!/bin/sh
2+
3+
if [ -z "${ANDROID_NDK_HOME}" ]; then
34
echo "Error: ANDROID_NDK_HOME not set"
4-
exit -1
5+
exit 1
56
fi
67

7-
NDK_MAJOR_VERSION=$(grep "Pkg.Revision" $ANDROID_NDK_HOME/source.properties | sed -e 's/Pkg.Revision = \([0-9]*\).*/\1/')
8-
if [[ "$NDK_MAJOR_VERSION" < 17 ]]; then
8+
NDK_MAJOR_VERSION=$(grep "Pkg.Revision" "$ANDROID_NDK_HOME"/source.properties | sed -e 's/Pkg.Revision = \([0-9]*\).*/\1/')
9+
if [ "$NDK_MAJOR_VERSION" -lt 17 ]; then
910
echo "Error: NDK 17 or newer required"
10-
exit -1
11+
exit 1
1112
fi
1213

1314
WIN64_MAKE=$ANDROID_NDK_HOME/prebuilt/windows-x86_64/bin/make.exe
14-
if [ -f $WIN64_MAKE ]; then
15-
WIN64_FLAGS=(-G "Unix Makefiles" -D CMAKE_MAKE_PROGRAM=$WIN64_MAKE)
15+
if [ -f "$WIN64_MAKE" ]; then
16+
set -- "$@" -G "Unix Makefiles" -D CMAKE_MAKE_PROGRAM="$WIN64_MAKE"
1617
fi
1718

18-
rm -Rf build/android_examples
19+
rm -rf build/android_examples
1920
cmake -D GLFM_BUILD_EXAMPLES=ON \
20-
-D CMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake \
21+
-D CMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME"/build/cmake/android.toolchain.cmake \
2122
-D CMAKE_C_FLAGS=-Werror=deprecated-declarations \
2223
-D CMAKE_VERBOSE_MAKEFILE=ON \
23-
"${WIN64_FLAGS[@]}" \
24+
"$@" \
2425
-S .. -B build/android_examples || exit $?
2526
cmake --build build/android_examples || exit $?

tests/build_apple.sh

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,60 @@
1-
#!/bin/bash
2-
if ! type xcodebuild &> /dev/null; then
1+
#!/bin/sh
2+
3+
if ! type xcodebuild > /dev/null 2>&1; then
34
echo "Error: xcodebuild not found"
4-
exit -1
5+
exit 1
56
fi
6-
if ! type xcpretty &> /dev/null; then
7+
if ! type xcpretty > /dev/null 2>&1; then
78
echo ">>> Skipping analyze step: xcpretty not found"
89
else
910
has_xcpretty=1
1011
fi
1112

1213
# Find clang-tidy either in the path or installed via brew
13-
clang_tidy=$(which clang-tidy 2>/dev/null || which $(brew --prefix llvm)/bin/clang-tidy 2>/dev/null)
14-
if [ $? -ne 0 ]; then
14+
if ! clang_tidy=$(which clang-tidy 2>/dev/null || which "$(brew --prefix llvm)"/bin/clang-tidy 2>/dev/null); then
1515
echo ">>> Skipping analyze step: clang-tidy not found"
1616
else
1717
has_clang_tidy=1
1818
fi
1919

2020
export CFLAGS=-Werror
2121

22-
declare -a sdks=("appletvos" "appletvsimulator" "iphoneos" "iphonesimulator" "macosx")
23-
declare -a objc_arc_names=("objc_arc_on" "objc_arc_off")
24-
declare -a objc_arc_values=("YES" "NO")
25-
2622
# Check failure when cmake piped to xcpretty
2723
set -o pipefail
2824

29-
for i in "${!objc_arc_names[@]}"; do
30-
builddir="build/apple_${objc_arc_names[i]}"
25+
for objc_arc in YES NO; do
26+
builddir="build/apple_objc_arc_$objc_arc"
3127

32-
rm -Rf $builddir
28+
rm -rf "$builddir"
3329

34-
cmake -S .. -B $builddir \
30+
cmake -S .. -B "$builddir" \
3531
-G Xcode \
3632
-D CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH=NO \
37-
-D CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC=${objc_arc_values[i]} || exit $?
33+
-D CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC="$objc_arc" || exit $?
3834

39-
for sdk in "${sdks[@]}"; do
40-
echo ">>> Building $sdk (${objc_arc_names[i]})"
41-
if [ ! $has_xcpretty ] || [ ! $has_clang_tidy ]; then
42-
cmake --build $builddir -- -sdk $sdk || exit $?
35+
for sdk in appletvos appletvsimulator iphoneos iphonesimulator macosx; do
36+
echo ">>> Apple: Building $sdk (OBJC_ARC=$objc_arc)"
37+
if [ ! "$has_xcpretty" ] || [ ! "$has_clang_tidy" ]; then
38+
cmake --build "$builddir" -- -sdk "$sdk" || exit $?
4339
else
44-
cmake --build $builddir -- -sdk $sdk \
45-
| xcpretty -r json-compilation-database --output $builddir/compile_commands.json || exit $?
40+
cmake --build "$builddir" -- -sdk "$sdk" \
41+
| xcpretty -r json-compilation-database --output "$builddir"/compile_commands.json || exit $?
4642

4743
# Don't analyze simulators, which share code (building is included to targeting multiple archs)
48-
if [[ $sdk = *simulator ]]; then
44+
if echo "$sdk" | grep -q "simulator"; then
4945
continue
5046
fi
5147

52-
echo ">>> Analyzing $sdk (${objc_arc_names[i]})"
48+
echo ">>> Apple: Analyzing $sdk (OBJC_ARC=$objc_arc)"
5349

5450
# Remove "ivfsstatcache" flag from compile_commands.json.
5551
# Current clang-tidy version (16.0.1) doesn't understand "ivfsstatcache" flag from xcodebuild 14.3.
56-
sed -i.bak 's/ -ivfsstatcache [^ ]* / /g' $builddir/compile_commands.json
52+
sed -i.bak 's/ -ivfsstatcache [^ ]* / /g' "$builddir"/compile_commands.json
5753

5854
# Use compile_commands.json generated from xcpretty to run clang-tidy. This will also check header files.
5955
# Since GLFM for Apple has only one source file, it is easy to just specify glfm_apple.m.
6056
# For bigger projects, the filenames could be parsed from compile_commands.json.
61-
$clang_tidy --config-file=clang-tidy-analyze.yml -p $builddir ../src/glfm_apple.m || exit $?
57+
$clang_tidy --config-file=clang-tidy-analyze.yml -p "$builddir" ../src/glfm_apple.m || exit $?
6258
fi
6359
done
6460
done

tests/build_apple_examples.sh

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
#!/bin/bash
2-
if ! type xcodebuild &> /dev/null; then
1+
#!/bin/sh
2+
3+
if ! type xcodebuild > /dev/null 2>&1; then
34
echo "Error: xcodebuild not found"
4-
exit -1
5+
exit 1
56
fi
67

78
export CFLAGS=-Werror=deprecated-declarations
8-
declare -a sdks=("appletvos" "iphoneos" "macosx")
99

10-
rm -Rf build/apple_examples
10+
rm -rf build/apple_examples
1111

1212
cmake -S .. -B build/apple_examples -G Xcode \
1313
-D GLFM_BUILD_EXAMPLES=ON \
1414
-D CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY="" \
1515
-D CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED=NO || exit $?
1616

17-
for sdk in "${sdks[@]}"; do
18-
echo ">>> Building examples for $sdk"
19-
cmake --build build/apple_examples -- -sdk ${sdk} || exit $?
17+
for sdk in appletvos iphoneos macosx; do
18+
echo ">>> Apple: Building examples for $sdk"
19+
cmake --build build/apple_examples -- -sdk "$sdk" || exit $?
2020
done
21-

tests/build_emscripten.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
#!/bin/bash
2-
if ! type emcmake &> /dev/null; then
1+
#!/bin/sh
2+
3+
if ! type emcmake > /dev/null 2>&1; then
34
echo "Error: emcmake not found"
4-
exit -1
5+
exit 1
56
fi
67

78
export CFLAGS=-Werror
89

9-
rm -Rf build/emscripten
10+
rm -rf build/emscripten
1011
emcmake cmake -S .. -B build/emscripten \
1112
-D GLFM_USE_CLANG_TIDY=ON \
1213
-D CMAKE_VERBOSE_MAKEFILE=ON || exit $?

tests/build_emscripten_examples.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
#!/bin/bash
2-
if ! type emcmake &> /dev/null; then
1+
#!/bin/sh
2+
3+
if ! type emcmake > /dev/null 2>&1; then
34
echo "Error: emcmake not found"
4-
exit -1
5+
exit 1
56
fi
67

78
export CFLAGS=-Werror=deprecated-declarations
89

9-
rm -Rf build/emscripten_examples
10+
rm -rf build/emscripten_examples
1011
emcmake cmake -S .. -B build/emscripten_examples \
1112
-D GLFM_BUILD_EXAMPLES=ON \
1213
-D CMAKE_VERBOSE_MAKEFILE=ON || exit $?

0 commit comments

Comments
 (0)