krz/orgstar

A native macOS editor for org-mode files. editor org-mode swift

scripts/build-ios-app.sh

16086b4cf2caff5328774b2cd5ae3ffe1ab65ca4
orgstar/scripts/build-ios-app.sh history · blame · raw

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