scripts/build-app.sh
176 lines · 6679 bytes · executable
1 symbol in this file
1#!/bin/sh
2# Builds Orgstar.app in .build/app from the release binary, signed ad hoc for local use. The
3# icon is drawn by scripts/make-icon.swift.
4# Usage: scripts/build-app.sh [version]
5set -eu
6
7cd "$(dirname "$0")/.."
8version="${1:-0.1.0}"
9app=".build/app/Orgstar.app"
10
11swift build -c release --product Orgstar
12swift build -c release --product OrgstarQuickLook
13swift build -c release --product OrgstarSpotlight
14binary="$(swift build -c release --show-bin-path)/Orgstar"
15
16rm -rf "$app"
17mkdir -p "$app/Contents/MacOS" "$app/Contents/Resources"
18cp "$binary" "$app/Contents/MacOS/Orgstar"
19iconset="$(mktemp -d)/AppIcon.iconset"
20swift scripts/make-icon.swift "$iconset"
21iconutil -c icns "$iconset" -o "$app/Contents/Resources/AppIcon.icns"
22rm -rf "$(dirname "$iconset")"
23
24cat > "$app/Contents/Info.plist" <<EOF
25<?xml version="1.0" encoding="UTF-8"?>
26<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
27<plist version="1.0">
28<dict>
29 <key>CFBundleIdentifier</key>
30 <string>sh.krz.orgstar</string>
31 <key>CFBundleName</key>
32 <string>Orgstar</string>
33 <key>CFBundleDisplayName</key>
34 <string>Orgstar</string>
35 <key>CFBundleExecutable</key>
36 <string>Orgstar</string>
37 <key>CFBundlePackageType</key>
38 <string>APPL</string>
39 <key>CFBundleIconFile</key>
40 <string>AppIcon</string>
41 <key>UTImportedTypeDeclarations</key>
42 <array>
43 <dict>
44 <key>UTTypeIdentifier</key>
45 <string>org.orgmode.org</string>
46 <key>UTTypeDescription</key>
47 <string>Org document</string>
48 <key>UTTypeConformsTo</key>
49 <array><string>public.plain-text</string></array>
50 <key>UTTypeTagSpecification</key>
51 <dict>
52 <key>public.filename-extension</key>
53 <array><string>org</string><string>org_archive</string></array>
54 </dict>
55 </dict>
56 </array>
57 <key>CFBundleDocumentTypes</key>
58 <array>
59 <dict>
60 <key>CFBundleTypeName</key>
61 <string>Org document</string>
62 <key>CFBundleTypeRole</key>
63 <string>Editor</string>
64 <key>LSHandlerRank</key>
65 <string>Default</string>
66 <key>LSItemContentTypes</key>
67 <array><string>org.orgmode.org</string></array>
68 </dict>
69 <dict>
70 <key>CFBundleTypeName</key>
71 <string>Text</string>
72 <key>CFBundleTypeRole</key>
73 <string>Editor</string>
74 <key>LSHandlerRank</key>
75 <string>Alternate</string>
76 <key>LSItemContentTypes</key>
77 <array><string>public.plain-text</string></array>
78 </dict>
79 </array>
80 <key>CFBundleURLTypes</key>
81 <array>
82 <dict>
83 <key>CFBundleURLName</key>
84 <string>org-protocol</string>
85 <key>CFBundleURLSchemes</key>
86 <array><string>org-protocol</string></array>
87 </dict>
88 </array>
89 <key>CFBundleShortVersionString</key>
90 <string>${version}</string>
91 <key>CFBundleVersion</key>
92 <string>${version}</string>
93 <key>LSMinimumSystemVersion</key>
94 <string>26.0</string>
95 <key>LSApplicationCategoryType</key>
96 <string>public.app-category.productivity</string>
97 <key>NSCalendarsFullAccessUsageDescription</key>
98 <string>The agenda shows your calendar events alongside your Org entries. Orgstar only reads them.</string>
99 <key>NSHighResolutionCapable</key>
100 <true/>
101 <key>NSPrincipalClass</key>
102 <string>NSApplication</string>
103</dict>
104</plist>
105EOF
106
107# App Intents metadata for Shortcuts, from the constant values Swift Build extracted; SwiftPM
108# doesn't run this step itself.
109toolchain="$(xcode-select -p)/Toolchains/XcodeDefault.xctoolchain"
110objects=".build/out/Intermediates.noindex/Orgstar.build/Release/Orgstar-p.build/Objects-normal/$(uname -m)"
111work="$(mktemp -d)"
112echo "$PWD/$objects/Orgstar-primary.swiftconstvalues" > "$work/constvalues.txt"
113"$toolchain/usr/bin/appintentsmetadataprocessor" --toolchain-dir "$toolchain" --module-name Orgstar \
114 --sdk-root "$(xcrun --sdk macosx --show-sdk-path)" --xcode-version "$(xcodebuild -version | awk '/Build version/ {print $3}')" \
115 --platform-family macOS --deployment-target 26.0 --bundle-identifier sh.krz.orgstar \
116 --target-triple "$(uname -m)-apple-macos26.0" --binary-file "$binary" --source-file-list "$objects/Orgstar.SwiftFileList" \
117 --swift-const-vals-list "$work/constvalues.txt" --output "$app/Contents/Resources" --force > /dev/null 2>&1
118rm -rf "$work"
119
120# App extensions: Quick Look previews and the Spotlight importer. They run sandboxed.
121appex() { # name, extension point, principal class, attributes
122 dir="$app/Contents/PlugIns/$1.appex/Contents"
123 mkdir -p "$dir/MacOS"
124 cp "$(dirname "$binary")/$1" "$dir/MacOS/$1"
125 cat > "$dir/Info.plist" <<PLIST
126<?xml version="1.0" encoding="UTF-8"?>
127<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
128<plist version="1.0">
129<dict>
130 <key>CFBundleIdentifier</key>
131 <string>sh.krz.orgstar.$(echo "$1" | sed 's/^Orgstar//' | tr 'A-Z' 'a-z')</string>
132 <key>CFBundleName</key>
133 <string>$1</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>LSMinimumSystemVersion</key>
143 <string>26.0</string>
144 <key>NSExtension</key>
145 <dict>
146 <key>NSExtensionPointIdentifier</key>
147 <string>$2</string>
148 <key>NSExtensionPrincipalClass</key>
149 <string>$3</string>
150 <key>NSExtensionAttributes</key>
151 <dict>$4</dict>
152 </dict>
153</dict>
154</plist>
155PLIST
156 cat > "$work/sandbox.entitlements" <<PLIST
157<?xml version="1.0" encoding="UTF-8"?>
158<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
159<plist version="1.0">
160<dict>
161 <key>com.apple.security.app-sandbox</key>
162 <true/>
163</dict>
164</plist>
165PLIST
166 codesign --force --sign - --entitlements "$work/sandbox.entitlements" "$app/Contents/PlugIns/$1.appex"
167}
168work="$(mktemp -d)"
169appex OrgstarQuickLook com.apple.quicklook.preview PreviewProvider \
170 "<key>QLSupportedContentTypes</key><array><string>org.orgmode.org</string></array><key>QLIsDataBasedPreview</key><true/>"
171appex OrgstarSpotlight com.apple.spotlight.import ImportExtension \
172 "<key>CSSupportedContentTypes</key><array><string>org.orgmode.org</string></array>"
173rm -rf "$work"
174
175codesign --force --sign - "$app"
176echo "$app"