SPB Git

Repository Public License

build.sh 3.8 KB 86 lines shellscript

1#!/usr/bin/env bash2# ORIX Navigator — build, test and run. One build at a time; derived data stays under build/.3#4#   scripts/build.sh generate            regenerate ORIXNavigator.xcodeproj (XcodeGen)5#   scripts/build.sh packages            swift build of the NavigatorUI target (macOS)6#   scripts/build.sh test [filter]       swift test, default filter NavigatorUITests7#   scripts/build.sh mac [Debug|Release] build the Mac app8#   scripts/build.sh ios [Debug|Release] build the iOS app for the simulator9#   scripts/build.sh run-mac [args…]     launch the Debug Mac app in the background with launch arguments10#   scripts/build.sh run-ios [iphone|ipad] [args…]11#   scripts/build.sh sim iphone|ipad     print the UDID of the project simulator (created if missing)12set -euo pipefail1314ROOT="$(cd "$(dirname "$0")/.." && pwd)"15NAME="${ORIX_BUILD_NAME:-shell}"16DD="$ROOT/build/dd-$NAME"17SPM="$ROOT/Packages/NavigatorKit/build/spm-$NAME"18XCODEGEN="${XCODEGEN:-/opt/homebrew/bin/xcodegen}"19BUNDLE_ID="ai.spboucher.orix.navigator"20IPHONE_NAME="ORIXNavigator iPhone"21IPAD_NAME="ORIXNavigator iPad"2223generate() { (cd "$ROOT" && "$XCODEGEN" generate --quiet); }2425# Keeps the lines of an xcodebuild log that matter: warnings, errors and the final result.26filter_log() {27  grep -E "(warning:|error:|BUILD (SUCCEEDED|FAILED)|TEST (SUCCEEDED|FAILED)|Executed [0-9]+ tests|Test Case .* (passed|failed))" \28    | grep -v "appintentsmetadataprocessor" | awk '!seen[$0]++' || true29}3031sim_udid() {32  local name type33  case "${1:-iphone}" in34    iphone) name="$IPHONE_NAME"; type="iPhone 17 Pro" ;;35    ipad) name="$IPAD_NAME"; type="$(xcrun simctl list devicetypes | grep -E 'iPad Pro 13-inch' | tail -1 | sed -E 's/ \(com\..*//')" ;;36    *) echo "unknown simulator: $1" >&2; exit 2 ;;37  esac38  local udid39  udid="$(xcrun simctl list devices available | { grep -F "$name (" || true; } | head -1 | sed -E 's/.*\(([0-9A-F-]{36})\).*/\1/')"40  if [ -z "$udid" ]; then udid="$(xcrun simctl create "$name" "$type")"; fi41  echo "$udid"42}4344mac_app() { echo "$DD/Build/Products/${1:-Debug}/ORIX Navigator.app"; }45ios_app() { echo "$DD/Build/Products/${1:-Debug}-iphonesimulator/ORIX Navigator.app"; }4647build_mac() {48  local config="${1:-Debug}"49  generate50  local extra=()51  if [ "$config" = "Release" ]; then extra=(CODE_SIGNING_ALLOWED=NO); fi52  xcodebuild -project "$ROOT/ORIXNavigator.xcodeproj" -scheme NavigatorMac -configuration "$config" \53    -destination 'platform=macOS,arch=arm64' -derivedDataPath "$DD" -skipPackagePluginValidation \54    ${extra[@]+"${extra[@]}"} build 2>&1 | filter_log55}5657build_ios() {58  local config="${1:-Debug}"59  generate60  xcodebuild -project "$ROOT/ORIXNavigator.xcodeproj" -scheme NavigatoriOS -configuration "$config" \61    -destination 'generic/platform=iOS Simulator' -derivedDataPath "$DD" ARCHS=arm64 ONLY_ACTIVE_ARCH=YES \62    build 2>&1 | filter_log63}6465case "${1:-}" in66  generate) generate ;;67  packages) (cd "$ROOT/Packages/NavigatorKit" && swift build --disable-keychain --scratch-path "$SPM" --target NavigatorUI) ;;68  test) (cd "$ROOT/Packages/NavigatorKit" && swift test --disable-keychain --scratch-path "$SPM" --filter "${2:-NavigatorUITests}") ;;69  mac) build_mac "${2:-Debug}" ;;70  ios) build_ios "${2:-Debug}" ;;71  sim) sim_udid "${2:-iphone}" ;;72  run-mac)73    shift74    # -g: never bring the app to the front. -n: a separate instance, so a running copy is left alone.75    open -g -n "$(mac_app Debug)" --args "$@" ;;76  run-ios)77    shift78    device="iphone"79    if [ "${1:-}" = "iphone" ] || [ "${1:-}" = "ipad" ]; then device="$1"; shift; fi80    udid="$(sim_udid "$device")"81    xcrun simctl list devices | grep -F "$udid" | grep -q Booted || xcrun simctl boot "$udid"82    xcrun simctl install "$udid" "$(ios_app Debug)"83    xcrun simctl launch --terminate-running-process "$udid" "$BUNDLE_ID" "$@" ;;84  *) sed -n '2,12p' "$0"; exit 2 ;;85esac86
Files main
Menu

Theme