|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 6 | +DERIVED_DATA_PATH="$ROOT_DIR/build" |
| 7 | +APP_PATH="$DERIVED_DATA_PATH/Build/Products/Debug-iphoneos/Bitkit.app" |
| 8 | +BUNDLE_ID="to.bitkit" |
| 9 | + |
| 10 | +DEVICE_LIST_DIR="$(mktemp -d "${TMPDIR:-/tmp}/bitkit-devices.XXXXXX")" |
| 11 | +DEVICE_LIST_JSON="$DEVICE_LIST_DIR/devices.json" |
| 12 | +trap 'rm -rf "$DEVICE_LIST_DIR"' EXIT |
| 13 | + |
| 14 | +if ! command -v python3 >/dev/null 2>&1; then |
| 15 | + echo "python3 is required to parse the devicectl device list." >&2 |
| 16 | + exit 1 |
| 17 | +fi |
| 18 | + |
| 19 | +echo "Looking for connected iPhones..." |
| 20 | +xcrun devicectl list devices \ |
| 21 | + --filter "hardwareProperties.deviceType == 'iPhone' AND hardwareProperties.reality == 'physical'" \ |
| 22 | + --timeout 10 \ |
| 23 | + --json-output "$DEVICE_LIST_JSON" >/dev/null |
| 24 | + |
| 25 | +if ! DEVICE_INFO="$( |
| 26 | + python3 - "$DEVICE_LIST_JSON" <<'PY' |
| 27 | +import json |
| 28 | +import sys |
| 29 | +
|
| 30 | +with open(sys.argv[1], "r", encoding="utf-8") as file: |
| 31 | + payload = json.load(file) |
| 32 | +
|
| 33 | +devices = payload.get("result", {}).get("devices", []) |
| 34 | +
|
| 35 | +if not devices: |
| 36 | + raise SystemExit(1) |
| 37 | +
|
| 38 | +device = devices[0] |
| 39 | +name = device.get("deviceProperties", {}).get("name", "Unknown iPhone") |
| 40 | +identifier = device.get("identifier") |
| 41 | +
|
| 42 | +if not identifier: |
| 43 | + raise SystemExit(1) |
| 44 | +
|
| 45 | +print(f"{identifier}\t{name}") |
| 46 | +PY |
| 47 | +)"; then |
| 48 | + echo "No connected physical iPhone found." >&2 |
| 49 | + exit 1 |
| 50 | +fi |
| 51 | + |
| 52 | +DEVICE_ID="${DEVICE_INFO%%$'\t'*}" |
| 53 | +DEVICE_NAME="${DEVICE_INFO#*$'\t'}" |
| 54 | + |
| 55 | +echo "Using $DEVICE_NAME ($DEVICE_ID)" |
| 56 | +echo "Building Debug app..." |
| 57 | +xcodebuild \ |
| 58 | + -project "$ROOT_DIR/Bitkit.xcodeproj" \ |
| 59 | + -scheme Bitkit \ |
| 60 | + -configuration Debug \ |
| 61 | + -destination "generic/platform=iOS" \ |
| 62 | + -derivedDataPath "$DERIVED_DATA_PATH" \ |
| 63 | + build |
| 64 | + |
| 65 | +LDK_STUB_PATH="$APP_PATH/Frameworks/LDKNodeFFI.framework" |
| 66 | +if [[ -d "$LDK_STUB_PATH" ]]; then |
| 67 | + echo "Removing LDKNodeFFI static framework stub..." |
| 68 | + rm -rf "$LDK_STUB_PATH" |
| 69 | +fi |
| 70 | + |
| 71 | +echo "Installing $APP_PATH..." |
| 72 | +xcrun devicectl device install app --device "$DEVICE_ID" "$APP_PATH" |
| 73 | + |
| 74 | +echo "Launching $BUNDLE_ID..." |
| 75 | +xcrun devicectl device process launch --device "$DEVICE_ID" "$BUNDLE_ID" --terminate-existing --console |
0 commit comments