scripts/build-ios-app.sh

189 lines · 8155 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.6.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>CFBundleDevelopmentRegion</key>
 35    <string>en</string>
 36    <key>CFBundleLocalizations</key>
 37    <array><string>en</string><string>de</string></array>
 38    <key>CFBundleName</key>
 39    <string>orgstar</string>
 40    <key>CFBundleDisplayName</key>
 41    <string>orgstar</string>
 42    <key>LSApplicationCategoryType</key>
 43    <string>public.app-category.productivity</string>
 44    <key>CFBundleExecutable</key>
 45    <string>OrgstarMobile</string>
 46    <key>CFBundlePackageType</key>
 47    <string>APPL</string>
 48    <key>CFBundleShortVersionString</key>
 49    <string>${version}</string>
 50    <key>CFBundleVersion</key>
 51    <string>${version}</string>
 52    <key>CFBundleSupportedPlatforms</key>
 53    <array><string>iPhoneSimulator</string></array>
 54    <key>MinimumOSVersion</key>
 55    <string>26.0</string>
 56    <key>NSCameraUsageDescription</key>
 57    <string>Photos you take from the editor are saved with your notes and linked where the caret is.</string>
 58    <key>NSFaceIDUsageDescription</key>
 59    <string>Face ID unlocks the passphrase of encrypted entries you asked orgstar to remember.</string>
 60    <key>NSCalendarsFullAccessUsageDescription</key>
 61    <string>The agenda shows your calendar events alongside your Org entries. orgstar changes your calendars only when you edit an event or add an entry to one.</string>
 62    <key>NSRemindersFullAccessUsageDescription</key>
 63    <string>The agenda shows your reminders alongside your Org entries. orgstar only reads them.</string>
 64    <key>UIDeviceFamily</key>
 65    <array><integer>1</integer><integer>2</integer></array>
 66    <key>UILaunchScreen</key>
 67    <dict/>
 68    <key>UIApplicationSceneManifest</key>
 69    <dict>
 70        <key>UIApplicationSupportsMultipleScenes</key>
 71        <true/>
 72    </dict>
 73    <key>UISupportedInterfaceOrientations</key>
 74    <array>
 75        <string>UIInterfaceOrientationPortrait</string>
 76        <string>UIInterfaceOrientationLandscapeLeft</string>
 77        <string>UIInterfaceOrientationLandscapeRight</string>
 78    </array>
 79    <key>UISupportedInterfaceOrientations~ipad</key>
 80    <array>
 81        <string>UIInterfaceOrientationPortrait</string>
 82        <string>UIInterfaceOrientationPortraitUpsideDown</string>
 83        <string>UIInterfaceOrientationLandscapeLeft</string>
 84        <string>UIInterfaceOrientationLandscapeRight</string>
 85    </array>
 86    <!-- public.text, not public.plain-text as on the Mac: iOS previews plain text itself and
 87         never asks the Quick Look extension. -->
 88    <key>UTImportedTypeDeclarations</key>
 89    <array>
 90        <dict>
 91            <key>UTTypeIdentifier</key>
 92            <string>org.orgmode.org</string>
 93            <key>UTTypeDescription</key>
 94            <string>Org document</string>
 95            <key>UTTypeConformsTo</key>
 96            <array><string>public.text</string></array>
 97            <key>UTTypeTagSpecification</key>
 98            <dict>
 99                <key>public.filename-extension</key>
100                <array><string>org</string><string>org_archive</string></array>
101            </dict>
102        </dict>
103    </array>
104    <key>CFBundleURLTypes</key>
105    <array>
106        <dict>
107            <key>CFBundleURLName</key>
108            <string>org-protocol</string>
109            <key>CFBundleURLSchemes</key>
110            <array><string>org-protocol</string></array>
111        </dict>
112    </array>
113</dict>
114</plist>
115PLIST
116
117# App Intents metadata for Shortcuts, from the constant values the build extracted; building
118# a package doesn't run this step itself.
119toolchain="$(xcode-select -p)/Toolchains/XcodeDefault.xctoolchain"
120objects=".build/ios/Build/Intermediates.noindex/Orgstar.build/Debug-iphonesimulator/OrgstarMobile-p.build/Objects-normal/arm64"
121work="$(mktemp -d)"
122ls "$PWD/$objects"/*.swiftconstvalues > "$work/constvalues.txt"
123"$toolchain/usr/bin/appintentsmetadataprocessor" --toolchain-dir "$toolchain" --module-name OrgstarMobile \
124    --sdk-root "$(xcrun --sdk iphonesimulator --show-sdk-path)" --xcode-version "$(xcodebuild -version | awk '/Build version/ {print $3}')" \
125    --platform-family iOS --deployment-target 26.0 --bundle-identifier sh.krz.orgstar \
126    --target-triple arm64-apple-ios26.0-simulator --binary-file "$app/OrgstarMobile" --source-file-list "$objects/OrgstarMobile.SwiftFileList" \
127    --swift-const-vals-list "$work/constvalues.txt" --output "$app" --force > /dev/null 2>&1
128
129# The UI's translations, from l10n/Localizable.xcstrings.
130scripts/localize.sh "$app"
131
132appex() { # name, bundle id suffix, extension point, principal class, attributes, entitlements
133    dir="$app/PlugIns/$1.appex"
134    mkdir -p "$dir"
135    cp "$products/$1" "$dir/$1"
136    scripts/localize.sh "$dir"
137    cat > "$dir/Info.plist" <<PLIST
138<?xml version="1.0" encoding="UTF-8"?>
139<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
140<plist version="1.0">
141<dict>
142    <key>CFBundleIdentifier</key>
143    <string>sh.krz.orgstar.$2</string>
144    <key>CFBundleName</key>
145    <string>$1</string>
146    <key>CFBundleDisplayName</key>
147    <string>orgstar</string>
148    <key>CFBundleExecutable</key>
149    <string>$1</string>
150    <key>CFBundlePackageType</key>
151    <string>XPC!</string>
152    <key>CFBundleShortVersionString</key>
153    <string>${version}</string>
154    <key>CFBundleVersion</key>
155    <string>${version}</string>
156    <key>CFBundleSupportedPlatforms</key>
157    <array><string>iPhoneSimulator</string></array>
158    <key>MinimumOSVersion</key>
159    <string>26.0</string>
160    <key>NSExtension</key>
161    <dict>
162        <key>NSExtensionPointIdentifier</key>
163        <string>$3</string>
164        <key>NSExtensionPrincipalClass</key>
165        <string>$4</string>
166        <key>NSExtensionAttributes</key>
167        <dict>$5</dict>
168    </dict>
169</dict>
170</plist>
171PLIST
172    codesign --force --sign - ${6:+--entitlements "$6"} "$dir"
173}
174# Quick Look previews of org files, in Files and wherever else Quick Look shows them.
175appex OrgstarQuickLook quicklook com.apple.quicklook.preview PreviewProvider \
176    "<key>QLSupportedContentTypes</key><array><string>org.orgmode.org</string></array><key>QLIsDataBasedPreview</key><true/>"
177# Capture from the share sheet: a page's link or text.
178appex OrgstarShare share com.apple.share-services ShareViewController \
179    "<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>" \
180    "$entitlements"
181
182# The watch app, which a paired watch installs from here.
183scripts/build-watch-app.sh "$version" > /dev/null
184mkdir -p "$app/Watch"
185cp -R .build/watch-app/OrgstarWatch.app "$app/Watch/"
186
187codesign --force --sign - --entitlements "$entitlements" "$app"
188rm -rf "$work"
189echo "$app"