13
13
# #
14
14
# #===----------------------------------------------------------------------===##
15
15
16
- #! /bin/bash
16
+ log () { printf -- " ** %s\n" " $* " >&2 ; }
17
+ error () { printf -- " ** ERROR: %s\n" " $* " >&2 ; }
18
+ fatal () { error " $@ " ; exit 1; }
17
19
18
20
EXAMPLE=APIGateway
19
21
OUTPUT_DIR=.build/release
20
22
OUTPUT_FILE=${OUTPUT_DIR} /APIGatewayLambda
21
23
LIBS_TO_CHECK=" libFoundation.so libFoundationInternationalization.so lib_FoundationICU.so"
22
24
23
- pushd Examples/${EXAMPLE} || exit 1
25
+ pushd Examples/${EXAMPLE} || fatal " Failed to change directory to Examples/ ${EXAMPLE} . "
24
26
25
27
# 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. "
27
29
28
30
# check if the binary exists
29
31
if [ ! -f " ${OUTPUT_FILE} " ]; then
30
- echo " ❌ ${OUTPUT_FILE} does not exist."
31
- exit 1
32
+ error " ❌ ${OUTPUT_FILE} does not exist."
32
33
fi
33
34
34
35
# Checking for Foundation or ICU dependencies
@@ -42,10 +43,10 @@ for LIB in ${LIBS_TO_CHECK}; do
42
43
43
44
# 1 is success (grep failed to find the lib), 0 is failure (grep successly found the lib)
44
45
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."
46
47
done
47
48
48
- popd || exit 1
49
+ popd || fatal " Failed to change directory back to the root directory. "
49
50
50
51
# 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