1+ #! /bin/bash
2+ # #===----------------------------------------------------------------------===##
3+ # #
4+ # # This source file is part of the SwiftAWSLambdaRuntime open source project
5+ # #
6+ # # Copyright (c) 2017-2024 Apple Inc. and the SwiftAWSLambdaRuntime project authors
7+ # # Licensed under Apache License v2.0
8+ # #
9+ # # See LICENSE.txt for license information
10+ # # See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors
11+ # #
12+ # # SPDX-License-Identifier: Apache-2.0
13+ # #
14+ # #===----------------------------------------------------------------------===##
15+ 
16+ log () { printf  -- " ** %s\n" " $* " >&2 ;  }
17+ error () { printf  -- " ** ERROR: %s\n" " $* " >&2 ;  }
18+ fatal () { error " $@ " ;  exit  1;  }
19+ 
20+ EXAMPLE=APIGateway
21+ OUTPUT_DIR=.build/release
22+ OUTPUT_FILE=${OUTPUT_DIR} /APIGatewayLambda
23+ LIBS_TO_CHECK=" libFoundation.so libFoundationInternationalization.so lib_FoundationICU.so" 
24+ 
25+ pushd  Examples/${EXAMPLE}  ||  fatal " Failed to change directory to Examples/${EXAMPLE} ." 
26+ 
27+ #  recompile the example without the --static-swift-stdlib flag
28+ LAMBDA_USE_LOCAL_DEPS=../.. swift build -c release -Xlinker -s ||  fatal " Failed to build the example." 
29+ 
30+ #  check if the binary exists
31+ if  [ !  -f  " ${OUTPUT_FILE} " ;  then 
32+   error " ❌ ${OUTPUT_FILE}  does not exist." 
33+ fi 
34+ 
35+ #  Checking for Foundation or ICU dependencies
36+ echo  " Checking for Foundation or ICU dependencies in ${OUTPUT_DIR} /${OUTPUT_FILE} ." 
37+ LIBRARIES=$( ldd ${OUTPUT_FILE}  |  awk ' {print $1}' ) 
38+ for  LIB  in  ${LIBS_TO_CHECK} ;  do 
39+   echo  -n " Checking for ${LIB} ... " 
40+   
41+   #  check if the binary has a dependency on Foundation or ICU
42+   echo  " ${LIBRARIES} " |  grep " ${LIB} " #  return 1 if not found
43+ 
44+   #  1 is success (grep failed to find the lib), 0 is failure (grep successly found the lib)
45+   SUCCESS=$? 
46+   [ " $SUCCESS " -eq  0 ] &&  log " ❌ ${LIB}  found." &&  break  ||  log " ✅ ${LIB}  not found." 
47+ done 
48+ 
49+ popd  ||  fatal " Failed to change directory back to the root directory." 
50+ 
51+ #  exit code is the opposite of the grep exit code
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