-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·189 lines (158 loc) · 7.04 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·189 lines (158 loc) · 7.04 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/bash
set -e
# ─────────────────────────────────────────────
# DockMaster Pro — Build Script
# Usage:
# ./build.sh # release build (arm64 only)
# ./build.sh --debug # debug build
# ./build.sh --universal # universal build (arm64 + x86_64)
# ./build.sh --sign "Developer ID Application: Your Name (TEAMID)" \
# --apple-id "your@apple.id" --team-id "TEAMID" \
# --password "app-specific-password"
# ─────────────────────────────────────────────
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
TARGET="DockMasterPro"
APP_NAME="DockMaster Pro"
APP_BUNDLE="${APP_NAME}.app"
BUILD_DIR="${SCRIPT_DIR}/build"
INFO_PLIST="${SCRIPT_DIR}/${TARGET}/App/Info.plist"
ENTITLEMENTS="${SCRIPT_DIR}/DockMasterPro.entitlements"
# ── Parse arguments ───────────────────────────
CONFIGURATION="release"
SIGN_IDENTITY=""
APPLE_ID=""
TEAM_ID=""
APP_PASSWORD=""
UNIVERSAL=false
while [[ $# -gt 0 ]]; do
case "$1" in
--debug) CONFIGURATION="debug"; shift ;;
--universal) UNIVERSAL=true; shift ;;
--sign) SIGN_IDENTITY="$2"; shift 2 ;;
--apple-id) APPLE_ID="$2"; shift 2 ;;
--team-id) TEAM_ID="$2"; shift 2 ;;
--password) APP_PASSWORD="$2"; shift 2 ;;
*) echo "Unknown option: $1"; exit 1 ;;
esac
done
APP_PATH="${BUILD_DIR}/${APP_BUNDLE}"
# ── Step 1: Compile ───────────────────────────
echo "▶ Building (${CONFIGURATION})..."
if [ "$UNIVERSAL" = true ]; then
echo " Building arm64..."
swift build -c "${CONFIGURATION}" --arch arm64 2>&1
echo " Building x86_64..."
swift build -c "${CONFIGURATION}" --arch x86_64 2>&1
ARM64_BIN="${SCRIPT_DIR}/.build/arm64-apple-macosx/${CONFIGURATION}/${TARGET}"
X86_64_BIN="${SCRIPT_DIR}/.build/x86_64-apple-macosx/${CONFIGURATION}/${TARGET}"
# Create universal binary
UNIVERSAL_BIN="${BUILD_DIR}/${TARGET}-universal"
mkdir -p "${BUILD_DIR}"
lipo -create -output "${UNIVERSAL_BIN}" "${ARM64_BIN}" "${X86_64_BIN}"
SPM_BUNDLE_ARM="${SCRIPT_DIR}/.build/arm64-apple-macosx/${CONFIGURATION}"
SPM_BUNDLE_X86="${SCRIPT_DIR}/.build/x86_64-apple-macosx/${CONFIGURATION}"
echo "✓ Universal build succeeded"
else
swift build -c "${CONFIGURATION}" --arch arm64 2>&1
SPM_BUILD_DIR="${SCRIPT_DIR}/.build/arm64-apple-macosx/${CONFIGURATION}"
echo "✓ Build succeeded"
fi
# ── Step 2: Assemble .app bundle ──────────────
echo "▶ Assembling ${APP_BUNDLE}..."
rm -rf "${APP_PATH}"
mkdir -p "${APP_PATH}/Contents/MacOS"
mkdir -p "${APP_PATH}/Contents/Resources"
# Executable
if [ "$UNIVERSAL" = true ]; then
cp "${UNIVERSAL_BIN}" "${APP_PATH}/Contents/MacOS/${TARGET}"
else
cp "${SPM_BUILD_DIR}/${TARGET}" "${APP_PATH}/Contents/MacOS/${TARGET}"
fi
# Info.plist
cp "${INFO_PLIST}" "${APP_PATH}/Contents/Info.plist"
# SPM resource bundles (localizations, assets, etc.)
if [ "$UNIVERSAL" = true ]; then
for bundle in "${SPM_BUNDLE_ARM}"/*.bundle; do
[ -e "$bundle" ] && cp -r "$bundle" "${APP_PATH}/Contents/Resources/"
done
else
for bundle in "${SPM_BUILD_DIR}"/*.bundle; do
[ -e "$bundle" ] && cp -r "$bundle" "${APP_PATH}/Contents/Resources/"
done
fi
# App icon
ICNS="${SCRIPT_DIR}/${TARGET}/Resources/AppIcon.icns"
[ -f "$ICNS" ] && cp "$ICNS" "${APP_PATH}/Contents/Resources/AppIcon.icns"
echo "✓ Bundle assembled: ${APP_PATH}"
# ── Step 3: Code sign ─────────────────────────
if [ -n "$SIGN_IDENTITY" ]; then
echo "▶ Signing with: ${SIGN_IDENTITY}"
# Sign internal bundles first
for bundle in "${APP_PATH}/Contents/Resources"/*.bundle; do
[ -e "$bundle" ] && codesign --force --options runtime \
--sign "$SIGN_IDENTITY" "$bundle"
done
# Sign main executable
if [ -f "$ENTITLEMENTS" ]; then
echo " Using entitlements: ${ENTITLEMENTS}"
codesign --force --options runtime \
--entitlements "$ENTITLEMENTS" \
--sign "$SIGN_IDENTITY" "${APP_PATH}/Contents/MacOS/${TARGET}"
else
codesign --force --options runtime \
--sign "$SIGN_IDENTITY" "${APP_PATH}/Contents/MacOS/${TARGET}"
fi
# Sign the app bundle
codesign --force --deep --options runtime \
--sign "$SIGN_IDENTITY" "${APP_PATH}"
echo "✓ Signed"
# ── Step 3.5: Notarize ────────────────────
if [ -n "$APPLE_ID" ] && [ -n "$TEAM_ID" ] && [ -n "$APP_PASSWORD" ]; then
echo "▶ Notarizing..."
# Create a temporary zip for notarization
NOTARIZE_ZIP="${BUILD_DIR}/notarize-tmp.zip"
cd "${BUILD_DIR}"
zip -qr "${NOTARIZE_ZIP}" "${APP_BUNDLE}"
cd "${SCRIPT_DIR}"
# Submit for notarization
xcrun notarytool submit "${NOTARIZE_ZIP}" \
--apple-id "${APPLE_ID}" \
--team-id "${TEAM_ID}" \
--password "${APP_PASSWORD}" \
--wait
# Staple the notarization ticket
xcrun stapler staple "${APP_PATH}"
# Clean up temp zip
rm -f "${NOTARIZE_ZIP}"
echo "✓ Notarized and stapled"
else
echo "⚠ Skipping notarization (provide --apple-id, --team-id, --password)"
fi
else
echo "▶ Ad-hoc signing (local use only)..."
codesign --force --deep --sign - "${APP_PATH}"
echo "✓ Ad-hoc signed"
fi
# ── Step 4: Package as zip ────────────────────
VERSION=$(defaults read "${APP_PATH}/Contents/Info.plist" CFBundleShortVersionString 2>/dev/null || echo "1.0.0")
ARCH_SUFFIX=""
[ "$UNIVERSAL" = true ] && ARCH_SUFFIX="-universal"
ZIP_NAME="${TARGET}_v${VERSION}${ARCH_SUFFIX}.zip"
ZIP_PATH="${BUILD_DIR}/${ZIP_NAME}"
echo "▶ Creating ${ZIP_NAME}..."
cd "${BUILD_DIR}"
zip -qr "${ZIP_NAME}" "${APP_BUNDLE}"
cd "${SCRIPT_DIR}"
echo "✓ Package ready: ${ZIP_PATH}"
# ── Summary ───────────────────────────────────
echo ""
echo "┌─────────────────────────────────────────┐"
echo "│ Build complete │"
echo "├─────────────────────────────────────────┤"
printf "│ App : %-30s │\n" "${APP_PATH##*/Users/shicheng/}"
printf "│ Zip : %-30s │\n" "${ZIP_NAME}"
ARCH_INFO="arm64"
[ "$UNIVERSAL" = true ] && ARCH_INFO="universal (arm64 + x86_64)"
printf "│ Arch : %-30s │\n" "${ARCH_INFO}"
printf "│ Config : %-30s │\n" "${CONFIGURATION}"
echo "└─────────────────────────────────────────┘"