scripts/build-ios-app.sh
172 lines · 7326 bytes · executable
1#!/bin/sh
2# Builds orgstar.app for the iOS Simulator in .build/ios-app from the OrgstarMobile product,
3# signed ad hoc. Install with `xcrun simctl install booted .build/ios-app/orgstar.app`.
4# Usage: scripts/build-ios-app.sh [version]
5set -eu
6
7cd "$(dirname "$0")/.."
8version="${1:-0.1.0}"
9app=".build/ios-app/orgstar.app"
10products=".build/ios/Build/Products/Debug-iphonesimulator"
11
12# The entitlements (the app group the share extension leaves captures in) go where the
13# Simulator reads them, into the binaries.
14entitlements=scripts/OrgstarMobile.entitlements
15for scheme in OrgstarMobile OrgstarQuickLook OrgstarShare; do
16 xcodebuild -scheme "$scheme" -destination 'generic/platform=iOS Simulator' -derivedDataPath .build/ios build -quiet \
17 CODE_SIGN_ENTITLEMENTS="$PWD/$entitlements"
18done
19
20rm -rf "$app"
21mkdir -p "$app"
22cp "$products/OrgstarMobile" "$app/OrgstarMobile"
23for bundle in "$products"/*.bundle; do
24 [ -e "$bundle" ] && cp -R "$bundle" "$app/"
25done
26
27cat > "$app/Info.plist" <<PLIST
28<?xml version="1.0" encoding="UTF-8"?>
29<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
30<plist version="1.0">
31<dict>
32 <key>CFBundleIdentifier</key>
33 <string>sh.krz.orgstar</string>
34 <key>CFBundleName</key>
35 <string>orgstar</string>
36 <key>CFBundleDisplayName</key>
37 <string>orgstar</string>
38 <key>LSApplicationCategoryType</key>
39 <string>public.app-category.productivity</string>
40 <key>CFBundleExecutable</key>
41 <string>OrgstarMobile</string>
42 <key>CFBundlePackageType</key>
43 <string>APPL</string>
44 <key>CFBundleShortVersionString</key>
45 <string>${version}</string>
46 <key>CFBundleVersion</key>
47 <string>${version}</string>
48 <key>CFBundleSupportedPlatforms</key>
49 <array><string>iPhoneSimulator</string></array>
50 <key>MinimumOSVersion</key>
51 <string>26.0</string>
52 <key>NSFaceIDUsageDescription</key>
53 <string>Face ID unlocks the passphrase of encrypted entries you asked orgstar to remember.</string>
54 <key>NSCalendarsFullAccessUsageDescription</key>
55 <string>The agenda shows your calendar events alongside your Org entries. orgstar only reads them.</string>
56 <key>UIDeviceFamily</key>
57 <array><integer>1</integer><integer>2</integer></array>
58 <key>UILaunchScreen</key>
59 <dict/>
60 <key>UIApplicationSceneManifest</key>
61 <dict>
62 <key>UIApplicationSupportsMultipleScenes</key>
63 <true/>
64 </dict>
65 <key>UISupportedInterfaceOrientations</key>
66 <array>
67 <string>UIInterfaceOrientationPortrait</string>
68 <string>UIInterfaceOrientationLandscapeLeft</string>
69 <string>UIInterfaceOrientationLandscapeRight</string>
70 </array>
71 <key>UISupportedInterfaceOrientations~ipad</key>
72 <array>
73 <string>UIInterfaceOrientationPortrait</string>
74 <string>UIInterfaceOrientationPortraitUpsideDown</string>
75 <string>UIInterfaceOrientationLandscapeLeft</string>
76 <string>UIInterfaceOrientationLandscapeRight</string>
77 </array>
78 <!-- public.text, not public.plain-text as on the Mac: iOS previews plain text itself and
79 never asks the Quick Look extension. -->
80 <key>UTImportedTypeDeclarations</key>
81 <array>
82 <dict>
83 <key>UTTypeIdentifier</key>
84 <string>org.orgmode.org</string>
85 <key>UTTypeDescription</key>
86 <string>Org document</string>
87 <key>UTTypeConformsTo</key>
88 <array><string>public.text</string></array>
89 <key>UTTypeTagSpecification</key>
90 <dict>
91 <key>public.filename-extension</key>
92 <array><string>org</string><string>org_archive</string></array>
93 </dict>
94 </dict>
95 </array>
96 <key>CFBundleURLTypes</key>
97 <array>
98 <dict>
99 <key>CFBundleURLName</key>
100 <string>org-protocol</string>
101 <key>CFBundleURLSchemes</key>
102 <array><string>org-protocol</string></array>
103 </dict>
104 </array>
105</dict>
106</plist>
107PLIST
108
109# App Intents metadata for Shortcuts, from the constant values the build extracted; building
110# a package doesn't run this step itself.
111toolchain="$(xcode-select -p)/Toolchains/XcodeDefault.xctoolchain"
112objects=".build/ios/Build/Intermediates.noindex/Orgstar.build/Debug-iphonesimulator/OrgstarMobile-p.build/Objects-normal/arm64"
113work="$(mktemp -d)"
114ls "$PWD/$objects"/*.swiftconstvalues > "$work/constvalues.txt"
115"$toolchain/usr/bin/appintentsmetadataprocessor" --toolchain-dir "$toolchain" --module-name OrgstarMobile \
116 --sdk-root "$(xcrun --sdk iphonesimulator --show-sdk-path)" --xcode-version "$(xcodebuild -version | awk '/Build version/ {print $3}')" \
117 --platform-family iOS --deployment-target 26.0 --bundle-identifier sh.krz.orgstar \
118 --target-triple arm64-apple-ios26.0-simulator --binary-file "$app/OrgstarMobile" --source-file-list "$objects/OrgstarMobile.SwiftFileList" \
119 --swift-const-vals-list "$work/constvalues.txt" --output "$app" --force > /dev/null 2>&1
120
121appex() { # name, bundle id suffix, extension point, principal class, attributes, entitlements
122 dir="$app/PlugIns/$1.appex"
123 mkdir -p "$dir"
124 cp "$products/$1" "$dir/$1"
125 cat > "$dir/Info.plist" <<PLIST
126<?xml version="1.0" encoding="UTF-8"?>
127<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
128<plist version="1.0">
129<dict>
130 <key>CFBundleIdentifier</key>
131 <string>sh.krz.orgstar.$2</string>
132 <key>CFBundleName</key>
133 <string>$1</string>
134 <key>CFBundleDisplayName</key>
135 <string>orgstar</string>
136 <key>CFBundleExecutable</key>
137 <string>$1</string>
138 <key>CFBundlePackageType</key>
139 <string>XPC!</string>
140 <key>CFBundleShortVersionString</key>
141 <string>${version}</string>
142 <key>CFBundleVersion</key>
143 <string>${version}</string>
144 <key>CFBundleSupportedPlatforms</key>
145 <array><string>iPhoneSimulator</string></array>
146 <key>MinimumOSVersion</key>
147 <string>26.0</string>
148 <key>NSExtension</key>
149 <dict>
150 <key>NSExtensionPointIdentifier</key>
151 <string>$3</string>
152 <key>NSExtensionPrincipalClass</key>
153 <string>$4</string>
154 <key>NSExtensionAttributes</key>
155 <dict>$5</dict>
156 </dict>
157</dict>
158</plist>
159PLIST
160 codesign --force --sign - ${6:+--entitlements "$6"} "$dir"
161}
162# Quick Look previews of org files, in Files and wherever else Quick Look shows them.
163appex OrgstarQuickLook quicklook com.apple.quicklook.preview PreviewProvider \
164 "<key>QLSupportedContentTypes</key><array><string>org.orgmode.org</string></array><key>QLIsDataBasedPreview</key><true/>"
165# Capture from the share sheet: a page's link or text.
166appex OrgstarShare share com.apple.share-services ShareViewController \
167 "<key>NSExtensionActivationRule</key><dict><key>NSExtensionActivationSupportsWebURLWithMaxCount</key><integer>1</integer><key>NSExtensionActivationSupportsText</key><true/><key>NSExtensionActivationSupportsImageWithMaxCount</key><integer>10</integer><key>NSExtensionActivationSupportsMovieWithMaxCount</key><integer>10</integer><key>NSExtensionActivationSupportsFileWithMaxCount</key><integer>10</integer></dict>" \
168 "$entitlements"
169
170codesign --force --sign - --entitlements "$entitlements" "$app"
171rm -rf "$work"
172echo "$app"