1313# #
1414# #===----------------------------------------------------------------------===##
1515
16- #! /bin/bash
16+ log () { printf -- " ** %s\n" " $* " >&2 ; }
17+ error () { printf -- " ** ERROR: %s\n" " $* " >&2 ; }
18+ fatal () { error " $@ " ; exit 1; }
1719
1820EXAMPLE=APIGateway
1921OUTPUT_DIR=.build/release
2022OUTPUT_FILE=${OUTPUT_DIR} /APIGatewayLambda
2123LIBS_TO_CHECK=" libFoundation.so libFoundationInternationalization.so lib_FoundationICU.so"
2224
23- pushd Examples/${EXAMPLE} || exit 1
25+ pushd Examples/${EXAMPLE} || fatal " Failed to change directory to Examples/ ${EXAMPLE} . "
2426
2527# recompile the example without the --static-swift-stdlib flag
26- LAMBDA_USE_LOCAL_DEPS=../.. swift build -c release -Xlinker -s
28+ LAMBDA_USE_LOCAL_DEPS=../.. swift build -c release -Xlinker -s || fatal " Failed to build the example. "
2729
2830# check if the binary exists
2931if [ ! -f " ${OUTPUT_FILE} " ]; then
30- echo " ❌ ${OUTPUT_FILE} does not exist."
31- exit 1
32+ error " ❌ ${OUTPUT_FILE} does not exist."
3233fi
3334
3435# Checking for Foundation or ICU dependencies
@@ -42,10 +43,10 @@ for LIB in ${LIBS_TO_CHECK}; do
4243
4344 # 1 is success (grep failed to find the lib), 0 is failure (grep successly found the lib)
4445 SUCCESS=$?
45- [ " $SUCCESS " -eq 0 ] && echo " ❌ ${LIB} found." && break || echo " ✅ ${LIB} not found."
46+ [ " $SUCCESS " -eq 0 ] && log " ❌ ${LIB} found." && break || log " ✅ ${LIB} not found."
4647done
4748
48- popd || exit 1
49+ popd || fatal " Failed to change directory back to the root directory. "
4950
5051# exit code is the opposite of the grep exit code
51- [ " $SUCCESS " -eq 0 ] && echo " ❌ At least one foundation lib was found, reporting the error." && exit 1 || echo " ✅ No foundation lib found, congrats!" && exit 0
52+ [ " $SUCCESS " -eq 0 ] && error " ❌ At least one foundation lib was found, reporting the error." || log " ✅ No foundation lib found, congrats!" && exit 0
0 commit comments