Repository navigation
Expand file tree
/
Copy pathbundle.sh
More file actions
executable file
·60 lines (56 loc) · 2.25 KB
/
Copy pathbundle.sh
File metadata and controls
executable file
·60 lines (56 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/sh
# Cargo's runner on macOS (.cargo/config.toml): runs zbugs-rune from inside
# an app bundle, `ZBugs Rune.app` beside the executable, so it launches as
# an app with its icon (AppIcon.icon) in the Dock and the app switcher. The
# bundle stays, to open from Finder. Tests and other executables run as
# they are.
set -eu
exe=$1
shift
[ "$(basename "$exe")" = zbugs-rune ] || exec "$exe" "$@"
here=$(cd "$(dirname "$0")" && pwd)
# Absolute: actool takes relative paths from a directory of its own.
app="$(cd "$(dirname "$exe")" && pwd)/ZBugs Rune.app"
res="$app/Contents/Resources"
mkdir -p "$app/Contents/MacOS" "$res"
# The icon, through Xcode's actool, when it changed: Assets.car for macOS 26
# and later, AppIcon.icns for earlier ones.
if [ ! -e "$res/Assets.car" ] || [ -n "$(find "$here/AppIcon.icon" -newer "$res/Assets.car")" ]; then
partial=$(mktemp)
out=$(xcrun actool "$here/AppIcon.icon" --compile "$res" --platform macosx \
--minimum-deployment-target 11.0 --app-icon AppIcon \
--output-partial-info-plist "$partial" --output-format human-readable-text) ||
{ echo "$out" >&2; exit 1; }
rm -f "$partial"
fi
cat > "$app/Contents/Info.plist" <<'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>zbugs-rune</string>
<key>CFBundleIdentifier</key>
<string>dev.rocicorp.zbugs-rune</string>
<key>CFBundleName</key>
<string>ZBugs Rune</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleIconFile</key>
<string>AppIcon</string>
<key>CFBundleIconName</key>
<string>AppIcon</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>NSHighResolutionCapable</key>
<true/>
</dict>
</plist>
EOF
# A hard link, not a copy: the executable can be large in a debug build.
ln -f "$exe" "$app/Contents/MacOS/zbugs-rune"
# LaunchServices can see the bundle before it's whole, as when actool runs,
# and the Dock then shows the app as broken: register it as it is now.
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister \
-f "$app"
exec "$app/Contents/MacOS/zbugs-rune" "$@"