-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·82 lines (68 loc) · 2.84 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·82 lines (68 loc) · 2.84 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
#!/bin/bash
# ============================================================
# FileAssistant 构建脚本:编译 → 组装 .app → 签名
# 用法:./build.sh(任意目录执行均可,脚本自动切换到自身所在目录)
# ============================================================
# —— 自检:防止本文件在复制粘贴中损坏(历史上发生过丢行/丢字符)——
bash -n "$0" 2>/dev/null || { echo "✗ build.sh 语法已损坏,请从原始来源重建(用终端 heredoc 方式)"; exit 1; }
grep -q 'SIGN_ID=' "$0" || { echo "✗ build.sh 关键内容丢失(复制损坏),请从原始来源重建"; exit 1; }
set -euo pipefail
cd "$(dirname "$0")"
echo "==> 检查系统版本"
OSVER=$(sw_vers -productVersion | cut -d. -f1)
if [ "${OSVER:-0}" -lt 13 ]; then
echo "✗ 本项目要求 macOS 13 及以上(当前 ${OSVER})"
exit 1
fi
echo "==> 检查编译器"
if SWIFTC=$(xcrun -f swiftc 2>/dev/null); then
echo " ${SWIFTC}"
elif SWIFTC=$(command -v swiftc); then
echo " ${SWIFTC}"
else
echo "✗ 未找到 swiftc,请先安装命令行工具:xcode-select --install"
exit 1
fi
# 多 SDK 环境自动选用最新 SDK(规避 MacOSX.sdk 符号链接指向旧 SDK 的问题)
SDK_DIR="$(dirname "$(xcrun --show-sdk-path 2>/dev/null)")"
if [ -d "${SDK_DIR}" ] && ls "${SDK_DIR}"/MacOSX*.sdk >/dev/null 2>&1; then
NEWEST="$(ls "${SDK_DIR}" 2>/dev/null | grep -E '^MacOSX[0-9]+(\.[0-9]+)?\.sdk$' | sort -t. -k1.7n -k2,2n | tail -n 1 || true)"
if [ -n "${NEWEST}" ]; then
export SDKROOT="${SDK_DIR}/${NEWEST}"
echo " SDK: ${SDKROOT}"
fi
fi
BUILD=build
APP="${BUILD}/FileAssistant.app"
rm -rf "${BUILD}"
mkdir -p "${APP}/Contents/MacOS" \
"${APP}/Contents/Resources"
# 关闭 set -e:两个目标都编完再统一判定,一次暴露全部错误
set +e
echo "==> 编译主程序"
APP_OK=0
"${SWIFTC}" -O -parse-as-library -module-name FileAssistant \
src/App/*.swift \
-o "${APP}/Contents/MacOS/FileAssistant" || APP_OK=1
if [ "${APP_OK}" -ne 0 ]; then
echo ""
echo "✗ 编译失败,汇总:"
[ "${APP_OK}" -ne 0 ] && echo " - 主程序(src/App/*.swift)有错误"
echo ""
echo "请把「编译」段落之间的全部 error 原样贴出(不要只截第一条)。"
echo "建议:./build.sh 2>&1 | tee build.log,然后贴 build.log 全文。"
exit 1
fi
set -e
echo "==> 写入 Info.plist"
cp plists/App-Info.plist "${APP}/Contents/Info.plist"
# 签名身份:优先自签证书 FileAssistantDev,不存在时回退 ad-hoc
SIGN_ID="-"
if security find-identity -v -p codesigning 2>/dev/null | grep -q FileAssistantDev; then
SIGN_ID="FileAssistantDev"
fi
echo "==> 签名主程序(身份: ${SIGN_ID})"
codesign --force --sign "${SIGN_ID}" "${APP}"
echo ""
echo "✓ 构建完成: ${APP}"
echo " 下一步: ./install.sh && ./register.sh"