Jotley / app · jotley.ai / scripts / test-mac-routing.sh
| 1 | #!/bin/zsh |
| 2 | # Uses the actual Debug app module and an existing Swift test source. |
| 3 | set -euo pipefail |
| 4 | task_repo_root="$(cd "$(dirname "$0")/.." && pwd)" |
| 5 | task_products="${JOTLEY_MAC_BUILD_PRODUCTS:-/tmp/jotley-local-xcode-build/Build/Products/Debug}" |
| 6 | task_app_source="$task_products/Jotley.app/Contents" |
| 7 | test -f "$task_app_source/MacOS/Jotley.debug.dylib" |
| 8 | test -d "$task_app_source/Resources/JotleyNotes.momd" |
| 9 | task_harness_root="$(mktemp -d /tmp/jotley-mac-routing.XXXXXX)" |
| 10 | task_profile_file="$HOME/Library/Containers/com.protomota.jotley.mac-routing-tests/Data/tmp/routing-$$.profraw" |
| 11 | trap 'rm -rf "$task_harness_root"; rm -f "$task_profile_file"' EXIT |
| 12 | task_harness_app="$task_harness_root/JotleyRoutingTests.app" |
| 13 | mkdir -p "$task_harness_app/Contents/MacOS" "$task_harness_app/Contents/Resources" "$task_harness_app/Contents/Frameworks" |
| 14 | cp -R "$task_app_source/Resources/." "$task_harness_app/Contents/Resources/" |
| 15 | cp "$task_app_source/MacOS/Jotley.debug.dylib" "$task_harness_app/Contents/MacOS/" |
| 16 | cp -R "$task_app_source/Frameworks/Sparkle.framework" "$task_harness_app/Contents/Frameworks/" |
| 17 | python3 - "$task_harness_app/Contents/Info.plist" "$task_harness_root/entitlements.plist" <<'PY' |
| 18 | import plistlib, sys |
| 19 | info = { |
| 20 | 'CFBundleIdentifier': 'com.protomota.jotley.mac-routing-tests', |
| 21 | 'CFBundleExecutable': 'MacRoutingHarness', |
| 22 | 'CFBundleName': 'Jotley Routing Tests', |
| 23 | 'CFBundlePackageType': 'APPL', |
| 24 | 'LSMinimumSystemVersion': '27.0', |
| 25 | 'LSUIElement': True, |
| 26 | 'NSMicrophoneUsageDescription': 'Routing regression tests must not begin microphone capture.', |
| 27 | } |
| 28 | for path, data in [(sys.argv[1], info), (sys.argv[2], {'com.apple.security.app-sandbox': True})]: |
| 29 | with open(path, 'wb') as output: plistlib.dump(data, output) |
| 30 | PY |
| 31 | task_arch="$(uname -m)" |
| 32 | task_sdk="$(xcrun --sdk macosx --show-sdk-path)" |
| 33 | # C shim modules of resolved packages (for example _AtomicsShims) are not copied into Products. |
| 34 | task_package_includes=() |
| 35 | for task_include in "$task_products"/../../../SourcePackages/checkouts/*/Sources/*/include(N/); do |
| 36 | task_package_includes+=(-I "$task_include") |
| 37 | done |
| 38 | for task_module_map in "$task_products"/../../Intermediates.noindex/GeneratedModuleMaps/*.modulemap(N); do |
| 39 | task_package_includes+=(-Xcc "-fmodule-map-file=$task_module_map") |
| 40 | done |
| 41 | xcrun swiftc -parse-as-library -D JOTLEY_MAC_ROUTING_HARNESS \ |
| 42 | -target "$task_arch-apple-macos27.0" -sdk "$task_sdk" \ |
| 43 | -I "$task_products" -F "$task_products" "${task_package_includes[@]}" "$task_repo_root/JotleyUITests-macOS/JotleyUITests_macOS.swift" \ |
| 44 | "$task_harness_app/Contents/MacOS/Jotley.debug.dylib" \ |
| 45 | -Xlinker -rpath -Xlinker @executable_path \ |
| 46 | -Xlinker -rpath -Xlinker @executable_path/../Frameworks \ |
| 47 | -o "$task_harness_app/Contents/MacOS/MacRoutingHarness" |
| 48 | codesign --force --sign - "$task_harness_app/Contents/MacOS/Jotley.debug.dylib" |
| 49 | # The separate test identity has App Sandbox and no audio/network entitlements. |
| 50 | # It never changes the production app's signature, entitlements or permissions. |
| 51 | codesign --force --sign - --entitlements "$task_harness_root/entitlements.plist" "$task_harness_app" |
| 52 | LLVM_PROFILE_FILE="$task_profile_file" "$task_harness_app/Contents/MacOS/MacRoutingHarness" "$@" |