scripts/build-ios-app.sh
170 lines · 6949 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>NSCalendarsFullAccessUsageDescription</key>
53 <string>The agenda shows your calendar events alongside your Org entries. orgstar only reads them.</string>
54 <key>UIDeviceFamily</key>
55 <array><integer>1</integer><integer>2</integer></array>
56 <key>UILaunchScreen</key>
57 <dict/>
58 <key>UIApplicationSceneManifest</key>
59 <dict>
60 <key>UIApplicationSupportsMultipleScenes</key>
61 <true/>
62 </dict>
63 <key>UISupportedInterfaceOrientations</key>
64 <array>
65 <string>UIInterfaceOrientationPortrait</string>
66 <string>UIInterfaceOrientationLandscapeLeft</string>
67 <string>UIInterfaceOrientationLandscapeRight</string>
68 </array>
69 <key>UISupportedInterfaceOrientations~ipad</key>
70 <array>
71 <string>UIInterfaceOrientationPortrait</string>
72 <string>UIInterfaceOrientationPortraitUpsideDown</string>
73 <string>UIInterfaceOrientationLandscapeLeft</string>
74 <string>UIInterfaceOrientationLandscapeRight</string>
75 </array>
76 <!-- public.text, not public.plain-text as on the Mac: iOS previews plain text itself and
77 never asks the Quick Look extension. -->
78 <key>UTImportedTypeDeclarations</key>
79 <array>
80 <dict>
81 <key>UTTypeIdentifier</key>
82 <string>org.orgmode.org</string>
83 <key>UTTypeDescription</key>
84 <string>Org document</string>
85 <key>UTTypeConformsTo</key>
86 <array><string>public.text</string></array>
87 <key>UTTypeTagSpecification</key>
88 <dict>
89 <key>public.filename-extension</key>
90 <array><string>org</string><string>org_archive</string></array>
91 </dict>
92 </dict>
93 </array>
94 <key>CFBundleURLTypes</key>
95 <array>
96 <dict>
97 <key>CFBundleURLName</key>
98 <string>org-protocol</string>
99 <key>CFBundleURLSchemes</key>
100 <array><string>org-protocol</string></array>
101 </dict>
102 </array>
103</dict>
104</plist>
105PLIST
106
107# App Intents metadata for Shortcuts, from the constant values the build extracted; building
108# a package doesn't run this step itself.
109toolchain="$(xcode-select -p)/Toolchains/XcodeDefault.xctoolchain"
110objects=".build/ios/Build/Intermediates.noindex/Orgstar.build/Debug-iphonesimulator/OrgstarMobile-p.build/Objects-normal/arm64"
111work="$(mktemp -d)"
112ls "$PWD/$objects"/*.swiftconstvalues > "$work/constvalues.txt"
113"$toolchain/usr/bin/appintentsmetadataprocessor" --toolchain-dir "$toolchain" --module-name OrgstarMobile \
114 --sdk-root "$(xcrun --sdk iphonesimulator --show-sdk-path)" --xcode-version "$(xcodebuild -version | awk '/Build version/ {print $3}')" \
115 --platform-family iOS --deployment-target 26.0 --bundle-identifier sh.krz.orgstar \
116 --target-triple arm64-apple-ios26.0-simulator --binary-file "$app/OrgstarMobile" --source-file-list "$objects/OrgstarMobile.SwiftFileList" \
117 --swift-const-vals-list "$work/constvalues.txt" --output "$app" --force > /dev/null 2>&1
118
119appex() { # name, bundle id suffix, extension point, principal class, attributes, entitlements
120 dir="$app/PlugIns/$1.appex"
121 mkdir -p "$dir"
122 cp "$products/$1" "$dir/$1"
123 cat > "$dir/Info.plist" <<PLIST
124<?xml version="1.0" encoding="UTF-8"?>
125<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
126<plist version="1.0">
127<dict>
128 <key>CFBundleIdentifier</key>
129 <string>sh.krz.orgstar.$2</string>
130 <key>CFBundleName</key>
131 <string>$1</string>
132 <key>CFBundleDisplayName</key>
133 <string>orgstar</string>
134 <key>CFBundleExecutable</key>
135 <string>$1</string>
136 <key>CFBundlePackageType</key>
137 <string>XPC!</string>
138 <key>CFBundleShortVersionString</key>
139 <string>${version}</string>
140 <key>CFBundleVersion</key>
141 <string>${version}</string>
142 <key>CFBundleSupportedPlatforms</key>
143 <array><string>iPhoneSimulator</string></array>
144 <key>MinimumOSVersion</key>
145 <string>26.0</string>
146 <key>NSExtension</key>
147 <dict>
148 <key>NSExtensionPointIdentifier</key>
149 <string>$3</string>
150 <key>NSExtensionPrincipalClass</key>
151 <string>$4</string>
152 <key>NSExtensionAttributes</key>
153 <dict>$5</dict>
154 </dict>
155</dict>
156</plist>
157PLIST
158 codesign --force --sign - ${6:+--entitlements "$6"} "$dir"
159}
160# Quick Look previews of org files, in Files and wherever else Quick Look shows them.
161appex OrgstarQuickLook quicklook com.apple.quicklook.preview PreviewProvider \
162 "<key>QLSupportedContentTypes</key><array><string>org.orgmode.org</string></array><key>QLIsDataBasedPreview</key><true/>"
163# Capture from the share sheet: a page's link or text.
164appex OrgstarShare share com.apple.share-services ShareViewController \
165 "<key>NSExtensionActivationRule</key><dict><key>NSExtensionActivationSupportsWebURLWithMaxCount</key><integer>1</integer><key>NSExtensionActivationSupportsText</key><true/></dict>" \
166 "$entitlements"
167
168codesign --force --sign - --entitlements "$entitlements" "$app"
169rm -rf "$work"
170echo "$app"