kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

ios_app.sh (5394B)


      1 #!/usr/bin/env bash
      2 # Build a minimal C-only UIKit app for the iOS simulator. The app uses the
      3 # Objective-C runtime C API instead of Objective-C syntax, so it exercises kit's
      4 # C frontend, iOS hosted profile, Mach-O linker, SDK C headers, and UIKit stub
      5 # linking without requiring an Objective-C frontend.
      6 
      7 set -u
      8 
      9 ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
     10 KIT="${KIT:-$ROOT/build/kit}"
     11 BUILD_DIR="$ROOT/build/test/smoke-ios-app"
     12 APP_ID="${KIT_IOS_APP_ID:-dev.kit.CSmoke}"
     13 APP_NAME="KitCSmoke"
     14 TARGET="arm64-apple-ios-simulator"
     15 SIM_TIMEOUT="${KIT_IOS_SIM_TIMEOUT:-30}"
     16 
     17 mkdir -p "$BUILD_DIR"
     18 
     19 KIT_KIT_DIR="$ROOT/test/lib"
     20 # shellcheck source=../lib/kit_sh_kit.sh
     21 . "$ROOT/test/lib/kit_sh_kit.sh"
     22 kit_report_init
     23 
     24 work="$BUILD_DIR"
     25 
     26 kit_run_timeout() {
     27   local seconds=$1
     28   shift
     29   /usr/bin/perl -e 'alarm shift @ARGV; exec @ARGV' "$seconds" "$@"
     30 }
     31 
     32 if [ "$(uname -s 2>/dev/null)" != "Darwin" ]; then
     33   skip_test "build" "iOS simulator app build requires a Darwin host"
     34   kit_summary test-smoke-ios-app; kit_exit
     35 fi
     36 if [ ! -x "$KIT" ]; then
     37   skip_test "build" "$KIT not built (run 'make bin')"
     38   kit_summary test-smoke-ios-app; kit_exit
     39 fi
     40 
     41 SDK="$(xcrun --sdk iphonesimulator --show-sdk-path 2>/dev/null || true)"
     42 if [ -z "$SDK" ]; then
     43   skip_test "build" "no iPhoneSimulator SDK (xcrun --show-sdk-path empty)"
     44   kit_summary test-smoke-ios-app; kit_exit
     45 fi
     46 
     47 INCLUDE_DIR="$BUILD_DIR/include"
     48 rm -rf "$INCLUDE_DIR"
     49 mkdir -p "$INCLUDE_DIR"
     50 ln -s "$SDK/System/Library/Frameworks/CoreGraphics.framework/Headers" \
     51   "$INCLUDE_DIR/CoreGraphics"
     52 ln -s "$SDK/System/Library/Frameworks/CoreFoundation.framework/Headers" \
     53   "$INCLUDE_DIR/CoreFoundation"
     54 
     55 EXE="$BUILD_DIR/$APP_NAME"
     56 if ! "$KIT" cc -target "$TARGET" --sysroot "$SDK" -I "$INCLUDE_DIR" -lc -lobjc \
     57     "$ROOT/test/smoke/ios_app.c" \
     58     -framework UIKit -framework Foundation -framework CoreGraphics \
     59     -o "$EXE" >"$BUILD_DIR/build.out" 2>"$BUILD_DIR/build.err"; then
     60   not_ok "build app executable" "$BUILD_DIR/build.err"
     61   kit_summary test-smoke-ios-app; kit_exit
     62 fi
     63 ok "build app executable"
     64 
     65 if ! otool -l "$EXE" >"$BUILD_DIR/otool.out" 2>"$BUILD_DIR/otool.err"; then
     66   not_ok "inspect app executable" "$BUILD_DIR/otool.err"
     67   kit_summary test-smoke-ios-app; kit_exit
     68 fi
     69 if grep -A4 LC_BUILD_VERSION "$BUILD_DIR/otool.out" | grep -q "platform 7"; then
     70   ok "Mach-O platform ios-simulator"
     71 else
     72   not_ok "Mach-O platform ios-simulator" "$BUILD_DIR/otool.out"
     73   kit_summary test-smoke-ios-app; kit_exit
     74 fi
     75 
     76 APP="$BUILD_DIR/$APP_NAME.app"
     77 rm -rf "$APP"
     78 mkdir -p "$APP"
     79 cp "$EXE" "$APP/$APP_NAME"
     80 cat >"$APP/Info.plist" <<EOF
     81 <?xml version="1.0" encoding="UTF-8"?>
     82 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
     83   "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
     84 <plist version="1.0">
     85 <dict>
     86   <key>CFBundleDevelopmentRegion</key>
     87   <string>en</string>
     88   <key>CFBundleExecutable</key>
     89   <string>$APP_NAME</string>
     90   <key>CFBundleIdentifier</key>
     91   <string>$APP_ID</string>
     92   <key>CFBundleInfoDictionaryVersion</key>
     93   <string>6.0</string>
     94   <key>CFBundleName</key>
     95   <string>$APP_NAME</string>
     96   <key>CFBundlePackageType</key>
     97   <string>APPL</string>
     98   <key>CFBundleShortVersionString</key>
     99   <string>1.0</string>
    100   <key>CFBundleSupportedPlatforms</key>
    101   <array>
    102     <string>iPhoneSimulator</string>
    103   </array>
    104   <key>CFBundleVersion</key>
    105   <string>1</string>
    106   <key>MinimumOSVersion</key>
    107   <string>12.0</string>
    108 </dict>
    109 </plist>
    110 EOF
    111 
    112 if ! plutil -lint "$APP/Info.plist" >"$BUILD_DIR/plutil.out" \
    113     2>"$BUILD_DIR/plutil.err"; then
    114   not_ok "bundle Info.plist" "$BUILD_DIR/plutil.err"
    115   kit_summary test-smoke-ios-app; kit_exit
    116 fi
    117 ok "bundle Info.plist"
    118 
    119 if ! codesign -s - --force "$APP" >"$BUILD_DIR/codesign.out" \
    120     2>"$BUILD_DIR/codesign.err"; then
    121   not_ok "codesign simulator app" "$BUILD_DIR/codesign.err"
    122   kit_summary test-smoke-ios-app; kit_exit
    123 fi
    124 ok "codesign simulator app"
    125 
    126 if [ "${KIT_IOS_SIM_LAUNCH:-0}" != "1" ]; then
    127   skip_test "launch simulator app" "set KIT_IOS_SIM_LAUNCH=1 with a booted simulator"
    128   kit_summary test-smoke-ios-app; kit_exit
    129 fi
    130 
    131 kit_run_timeout "$SIM_TIMEOUT" xcrun simctl install booted "$APP" \
    132   >"$BUILD_DIR/sim-install.out" 2>"$BUILD_DIR/sim-install.err"
    133 sim_rc=$?
    134 if [ "$sim_rc" -ne 0 ]; then
    135   if [ "$sim_rc" -eq 142 ]; then
    136     echo "simctl install timed out after ${SIM_TIMEOUT}s" \
    137       >"$BUILD_DIR/sim-install.err"
    138   fi
    139   if [ "${KIT_IOS_SIM_REQUIRE_LAUNCH:-0}" = "1" ]; then
    140     not_ok "install simulator app" "$BUILD_DIR/sim-install.err"
    141   else
    142     skip_test "install simulator app" "no booted simulator accepting installs"
    143   fi
    144   kit_summary test-smoke-ios-app; kit_exit
    145 fi
    146 ok "install simulator app"
    147 
    148 kit_run_timeout "$SIM_TIMEOUT" xcrun simctl launch booted "$APP_ID" \
    149   >"$BUILD_DIR/sim-launch.out" 2>"$BUILD_DIR/sim-launch.err"
    150 sim_rc=$?
    151 if [ "$sim_rc" -ne 0 ]; then
    152   if [ "$sim_rc" -eq 142 ]; then
    153     echo "simctl launch timed out after ${SIM_TIMEOUT}s" \
    154       >"$BUILD_DIR/sim-launch.err"
    155   fi
    156   if [ "${KIT_IOS_SIM_REQUIRE_LAUNCH:-0}" = "1" ]; then
    157     not_ok "launch simulator app" "$BUILD_DIR/sim-launch.err"
    158   else
    159     skip_test "launch simulator app" "simulator launch failed"
    160   fi
    161   kit_summary test-smoke-ios-app; kit_exit
    162 fi
    163 ok "launch simulator app"
    164 
    165 kit_run_timeout "$SIM_TIMEOUT" xcrun simctl terminate booted "$APP_ID" \
    166   >"$BUILD_DIR/sim-terminate.out" 2>"$BUILD_DIR/sim-terminate.err" || true
    167 
    168 kit_summary test-smoke-ios-app
    169 kit_exit