krz/orgstar

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

scripts/build-ios-app.sh

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

166 lines · 6689 bytes · executable

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