Branchwell

Jotley / app · jotley.ai / scripts / test-mac-routing.sh

Raw 3.1 KB on c22c50f3614b055549c1ecbf54af0165e0bc8df1
1#!/bin/zsh
2# Uses the actual Debug app module and an existing Swift test source.
3set -euo pipefail
4task_repo_root="$(cd "$(dirname "$0")/.." && pwd)"
5task_products="${JOTLEY_MAC_BUILD_PRODUCTS:-/tmp/jotley-local-xcode-build/Build/Products/Debug}"
6task_app_source="$task_products/Jotley.app/Contents"
7test -f "$task_app_source/MacOS/Jotley.debug.dylib"
8test -d "$task_app_source/Resources/JotleyNotes.momd"
9task_harness_root="$(mktemp -d /tmp/jotley-mac-routing.XXXXXX)"
10task_profile_file="$HOME/Library/Containers/com.protomota.jotley.mac-routing-tests/Data/tmp/routing-$$.profraw"
11trap 'rm -rf "$task_harness_root"; rm -f "$task_profile_file"' EXIT
12task_harness_app="$task_harness_root/JotleyRoutingTests.app"
13mkdir -p "$task_harness_app/Contents/MacOS" "$task_harness_app/Contents/Resources" "$task_harness_app/Contents/Frameworks"
14cp -R "$task_app_source/Resources/." "$task_harness_app/Contents/Resources/"
15cp "$task_app_source/MacOS/Jotley.debug.dylib" "$task_harness_app/Contents/MacOS/"
16cp -R "$task_app_source/Frameworks/Sparkle.framework" "$task_harness_app/Contents/Frameworks/"
17python3 - "$task_harness_app/Contents/Info.plist" "$task_harness_root/entitlements.plist" <<'PY'
18import plistlib, sys
19info = {
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}
28for 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)
30PY
31task_arch="$(uname -m)"
32task_sdk="$(xcrun --sdk macosx --show-sdk-path)"
33# C shim modules of resolved packages (for example _AtomicsShims) are not copied into Products.
34task_package_includes=()
35for task_include in "$task_products"/../../../SourcePackages/checkouts/*/Sources/*/include(N/); do
36 task_package_includes+=(-I "$task_include")
37done
38for task_module_map in "$task_products"/../../Intermediates.noindex/GeneratedModuleMaps/*.modulemap(N); do
39 task_package_includes+=(-Xcc "-fmodule-map-file=$task_module_map")
40done
41xcrun 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"
48codesign --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.
51codesign --force --sign - --entitlements "$task_harness_root/entitlements.plist" "$task_harness_app"
52LLVM_PROFILE_FILE="$task_profile_file" "$task_harness_app/Contents/MacOS/MacRoutingHarness" "$@"