scripts/build-app.sh

9954efcbf435b2e8d78a4b59bfbbbb67c1b6c379
orgstar/scripts/build-app.sh

264 lines · 11595 bytes · executable

  1#!/bin/sh
  2# Builds orgstar.app in .build/app from the release binary. The icon is drawn by
  3# scripts/make-icon.swift.
  4# Usage: scripts/build-app.sh [version] [build]
  5#   ORGSTAR_SIGN   signing identity; ad hoc ("-") for local use by default. Any other
  6#                  identity also turns on the hardened runtime and a secure timestamp.
  7#   ORGSTAR_ARCHS  architectures, e.g. "arm64 x86_64" for a universal app; this Mac's by default.
  8set -eu
  9
 10cd "$(dirname "$0")/.."
 11version="${1:-1.2.0}"
 12build="${2:-$version}"
 13sign="${ORGSTAR_SIGN:--}"
 14app=".build/app/orgstar.app"
 15arch_flags=""
 16for arch in ${ORGSTAR_ARCHS:-$(uname -m)}; do arch_flags="$arch_flags --arch $arch"; done
 17if [ "$sign" = "-" ]; then
 18    sign_flags=""
 19else
 20    sign_flags="--options runtime --timestamp"
 21fi
 22
 23# shellcheck disable=SC2086
 24swift build -c release $arch_flags --product Orgstar
 25# shellcheck disable=SC2086
 26swift build -c release $arch_flags --product OrgstarQuickLook
 27# shellcheck disable=SC2086
 28swift build -c release $arch_flags --product OrgstarSpotlight
 29# shellcheck disable=SC2086
 30swift build -c release $arch_flags --product OrgstarWidgets
 31# shellcheck disable=SC2086
 32binary="$(swift build -c release $arch_flags --show-bin-path)/Orgstar"
 33
 34rm -rf "$app" .build/app/dSYMs
 35mkdir -p "$app/Contents/MacOS" "$app/Contents/Resources" "$app/Contents/Frameworks" .build/app/dSYMs
 36cp "$binary" "$app/Contents/MacOS/Orgstar"
 37# The build's debug symbols, for symbolicating crash reports; the executables ship stripped.
 38for dsym in "$(dirname "$binary")"/*.dSYM; do ditto "$dsym" ".build/app/dSYMs/$(basename "$dsym")"; done
 39
 40# Sparkle, from its SwiftPM artifact: the framework beside the binary, found through an rpath.
 41sparkle="$(find .build/artifacts -path '*Sparkle.xcframework/macos-*/Sparkle.framework' -maxdepth 7 | head -1)"
 42[ -n "$sparkle" ] || { echo "Sparkle.framework not in .build/artifacts; swift build fetches it." >&2; exit 1; }
 43ditto "$sparkle" "$app/Contents/Frameworks/Sparkle.framework"
 44otool -l "$app/Contents/MacOS/Orgstar" | grep -q '@executable_path/../Frameworks' \
 45    || install_name_tool -add_rpath @executable_path/../Frameworks "$app/Contents/MacOS/Orgstar"
 46strip -x "$app/Contents/MacOS/Orgstar"
 47
 48# SwiftMath's math fonts, which it finds in the app's resources. LatexPreview uses only the
 49# default, Latin Modern.
 50cp -R "$(dirname "$binary")/SwiftMath_SwiftMath.bundle" "$app/Contents/Resources/"
 51find "$app/Contents/Resources/SwiftMath_SwiftMath.bundle" -path '*/mathFonts.bundle/*' \
 52    \( -name '*.otf' -o -name '*.plist' \) ! -name 'latinmodern-math.*' -delete
 53# MathJax, for PDF export.
 54cp -R "$(dirname "$binary")/Orgstar_OrgMathJax.bundle" "$app/Contents/Resources/"
 55
 56# Updates: the appcast and its signing key, for signed builds only; a dev build never checks.
 57if [ "$sign" != "-" ]; then
 58    feed_keys="    <key>SUFeedURL</key>
 59    <string>https://files.krz.sh/orgstar/appcast.xml</string>
 60    <key>SUPublicEDKey</key>
 61    <string>${ORGSTAR_ED_PUBLIC_KEY:?set ORGSTAR_ED_PUBLIC_KEY to the key generate_keys printed}</string>"
 62else
 63    feed_keys=""
 64fi
 65# The UI's translations, from l10n/Localizable.xcstrings and l10n/DeveloperID.xcstrings.
 66scripts/localize.sh --developer-id "$app/Contents/Resources"
 67
 68# The icon (macOS derives its dark and tinted styles), and the Dock icons Settings offers.
 69work="$(mktemp -d)"
 70xcrun actool packaging/AppIcons.xcassets --compile "$app/Contents/Resources" --platform macosx \
 71    --minimum-deployment-target 26.0 --app-icon AppIcon --output-partial-info-plist "$work/icon.plist" > /dev/null
 72rm -rf "$work"
 73mkdir -p "$app/Contents/Resources/IconPreviews"
 74cp packaging/IconPreviews/*.png "$app/Contents/Resources/IconPreviews/"
 75
 76cat > "$app/Contents/Info.plist" <<EOF
 77<?xml version="1.0" encoding="UTF-8"?>
 78<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 79<plist version="1.0">
 80<dict>
 81    <key>CFBundleIdentifier</key>
 82    <string>sh.krz.orgstar</string>
 83    <key>CFBundleDevelopmentRegion</key>
 84    <string>en</string>
 85    <key>CFBundleLocalizations</key>
 86    <array><string>en</string><string>de</string><string>fr</string><string>ja</string><string>es</string><string>pt-BR</string></array>
 87    <key>CFBundleName</key>
 88    <string>orgstar</string>
 89    <key>CFBundleDisplayName</key>
 90    <string>orgstar</string>
 91    <key>CFBundleExecutable</key>
 92    <string>Orgstar</string>
 93    <key>CFBundlePackageType</key>
 94    <string>APPL</string>
 95    <key>CFBundleIconName</key>
 96    <string>AppIcon</string>
 97    <key>UTImportedTypeDeclarations</key>
 98    <array>
 99        <dict>
100            <key>UTTypeIdentifier</key>
101            <string>org.orgmode.org</string>
102            <key>UTTypeDescription</key>
103            <string>Org document</string>
104            <key>UTTypeConformsTo</key>
105            <array><string>public.plain-text</string></array>
106            <key>UTTypeTagSpecification</key>
107            <dict>
108                <key>public.filename-extension</key>
109                <array><string>org</string><string>org_archive</string></array>
110            </dict>
111        </dict>
112    </array>
113    <key>CFBundleDocumentTypes</key>
114    <array>
115        <dict>
116            <key>CFBundleTypeName</key>
117            <string>Org document</string>
118            <key>CFBundleTypeRole</key>
119            <string>Editor</string>
120            <key>LSHandlerRank</key>
121            <string>Default</string>
122            <key>LSItemContentTypes</key>
123            <array><string>org.orgmode.org</string></array>
124        </dict>
125        <dict>
126            <key>CFBundleTypeName</key>
127            <string>Text</string>
128            <key>CFBundleTypeRole</key>
129            <string>Editor</string>
130            <key>LSHandlerRank</key>
131            <string>Alternate</string>
132            <key>LSItemContentTypes</key>
133            <array><string>public.plain-text</string></array>
134        </dict>
135    </array>
136    <key>CFBundleURLTypes</key>
137    <array>
138        <dict>
139            <key>CFBundleURLName</key>
140            <string>org-protocol</string>
141            <key>CFBundleURLSchemes</key>
142            <array><string>org-protocol</string><string>orgstar</string></array>
143        </dict>
144    </array>
145    <key>CFBundleShortVersionString</key>
146    <string>${version}</string>
147    <key>CFBundleVersion</key>
148    <string>${build}</string>
149    <key>LSMinimumSystemVersion</key>
150    <string>26.0</string>
151${feed_keys}
152    <key>LSApplicationCategoryType</key>
153    <string>public.app-category.productivity</string>
154    <key>NSCalendarsFullAccessUsageDescription</key>
155    <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>
156    <key>NSRemindersFullAccessUsageDescription</key>
157    <string>The agenda shows your reminders alongside your Org entries. orgstar only reads them.</string>
158    <key>NSHighResolutionCapable</key>
159    <true/>
160    <key>NSPrincipalClass</key>
161    <string>NSApplication</string>
162    <key>NSUserActivityTypes</key>
163    <array><string>sh.krz.orgstar.editing</string></array>
164</dict>
165</plist>
166EOF
167
168# App Intents metadata for Shortcuts, from the constant values Swift Build extracted; SwiftPM
169# doesn't run this step itself.
170toolchain="$(xcode-select -p)/Toolchains/XcodeDefault.xctoolchain"
171objects=".build/out/Intermediates.noindex/Orgstar.build/Release/Orgstar-p.build/Objects-normal/$(uname -m)"
172work="$(mktemp -d)"
173echo "$PWD/$objects/Orgstar-primary.swiftconstvalues" > "$work/constvalues.txt"
174"$toolchain/usr/bin/appintentsmetadataprocessor" --toolchain-dir "$toolchain" --module-name Orgstar \
175    --sdk-root "$(xcrun --sdk macosx --show-sdk-path)" --xcode-version "$(xcodebuild -version | awk '/Build version/ {print $3}')" \
176    --platform-family macOS --deployment-target 26.0 --bundle-identifier sh.krz.orgstar \
177    --target-triple "$(uname -m)-apple-macos26.0" --binary-file "$binary" --source-file-list "$objects/Orgstar.SwiftFileList" \
178    --swift-const-vals-list "$work/constvalues.txt" --output "$app/Contents/Resources" --force > /dev/null 2>&1
179rm -rf "$work"
180
181# App extensions: Quick Look previews, the Spotlight importer and the widgets. They run
182# sandboxed.
183appex() { # name, extension point, principal class (or ""), attributes, extra entitlements
184    dir="$app/Contents/PlugIns/$1.appex/Contents"
185    mkdir -p "$dir/MacOS" "$dir/Resources"
186    cp "$(dirname "$binary")/$1" "$dir/MacOS/$1"
187    strip -x "$dir/MacOS/$1"
188    scripts/localize.sh "$dir/Resources"
189    cat > "$dir/Info.plist" <<PLIST
190<?xml version="1.0" encoding="UTF-8"?>
191<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
192<plist version="1.0">
193<dict>
194    <key>CFBundleIdentifier</key>
195    <string>sh.krz.orgstar.$(echo "$1" | sed 's/^Orgstar//' | tr 'A-Z' 'a-z')</string>
196    <key>CFBundleName</key>
197    <string>$1</string>
198    <key>CFBundleExecutable</key>
199    <string>$1</string>
200    <key>CFBundlePackageType</key>
201    <string>XPC!</string>
202    <key>CFBundleShortVersionString</key>
203    <string>${version}</string>
204    <key>CFBundleVersion</key>
205    <string>${build}</string>
206    <key>LSMinimumSystemVersion</key>
207    <string>26.0</string>
208    <key>NSExtension</key>
209    <dict>
210        <key>NSExtensionPointIdentifier</key>
211        <string>$2</string>
212$([ -n "$3" ] && printf '        <key>NSExtensionPrincipalClass</key>\n        <string>%s</string>\n' "$3")
213        <key>NSExtensionAttributes</key>
214        <dict>$4</dict>
215    </dict>
216</dict>
217</plist>
218PLIST
219    cat > "$work/sandbox.entitlements" <<PLIST
220<?xml version="1.0" encoding="UTF-8"?>
221<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
222<plist version="1.0">
223<dict>
224    <key>com.apple.security.app-sandbox</key>
225    <true/>
226${5:-}
227</dict>
228</plist>
229PLIST
230    # shellcheck disable=SC2086
231    codesign --force --sign "$sign" $sign_flags --entitlements "$work/sandbox.entitlements" "$app/Contents/PlugIns/$1.appex"
232}
233work="$(mktemp -d)"
234appex OrgstarQuickLook com.apple.quicklook.preview PreviewProvider \
235    "<key>QLSupportedContentTypes</key><array><string>org.orgmode.org</string></array><key>QLIsDataBasedPreview</key><true/>"
236appex OrgstarSpotlight com.apple.spotlight.import ImportExtension \
237    "<key>CSSupportedContentTypes</key><array><string>org.orgmode.org</string></array>"
238# The widgets read what the app writes in ~/Library/Application Support/Orgstar/Widgets.
239appex OrgstarWidgets com.apple.widgetkit-extension "" "" \
240    "    <key>com.apple.security.temporary-exception.files.home-relative-path.read-only</key>
241    <array><string>/Library/Application Support/Orgstar/Widgets/</string></array>"
242
243# Sparkle's inner pieces are signed first, as its documentation has it, then the framework.
244fw="$app/Contents/Frameworks/Sparkle.framework/Versions/B"
245for item in "$fw/XPCServices/Installer.xpc" "$fw/XPCServices/Downloader.xpc" "$fw/Autoupdate" "$fw/Updater.app" "$app/Contents/Frameworks/Sparkle.framework"; do
246    # shellcheck disable=SC2086
247    codesign --force --sign "$sign" $sign_flags "$item"
248done
249
250# The hardened runtime needs Calendar access declared for the agenda's events.
251cat > "$work/app.entitlements" <<PLIST
252<?xml version="1.0" encoding="UTF-8"?>
253<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
254<plist version="1.0">
255<dict>
256    <key>com.apple.security.personal-information.calendars</key>
257    <true/>
258</dict>
259</plist>
260PLIST
261# shellcheck disable=SC2086
262codesign --force --sign "$sign" $sign_flags --entitlements "$work/app.entitlements" "$app"
263rm -rf "$work"
264echo "$app"
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form