-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·90 lines (74 loc) · 2.76 KB
/
Copy pathrelease.sh
File metadata and controls
executable file
·90 lines (74 loc) · 2.76 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
#!/bin/bash
set -euo pipefail
# cd 到脚本所在目录
cd "$(dirname "$0")"
# 版本号配置
VERSION_SHORT="1.0" # 短版本号 (如 1.0, 1.1)
VERSION_BUILD="1" # 构建号 (如 1, 2, 3)
# 自动定位源码:脚本在根目录 → 进入 src;脚本已在 src → 直接用当前目录
if [ -d src ] && [ -z "$(find . -maxdepth 1 -name '*.swift')" ]; then
cd src
fi
echo ">> 工作目录: $(pwd)"
# 收集源文件(Bash 3.2 兼容写法;排除 build 目录)
SOURCES=()
while IFS= read -r f; do
SOURCES+=("$f")
done < <(find . -name '*.swift' -not -path './build/*' | sort)
if [ ${#SOURCES[@]} -eq 0 ]; then
echo "!! 未找到 .swift 文件,请确认脚本放在项目根目录或 src 目录"
exit 1
fi
echo ">> 共 ${#SOURCES[@]} 个源文件"
# 清理上次(可能残缺)的构建产物
rm -rf build
mkdir -p build/bin
# 设置环境变量供 Swift 代码读取
export VERSION_SHORT="${VERSION_SHORT}"
export VERSION_BUILD="${VERSION_BUILD}"
# 双架构分别编译
echo ">> 编译 arm64 ..."
swiftc -O -whole-module-optimization \
-target arm64-apple-macos14.0 \
-o build/bin/FileAssistant-arm64 \
"${SOURCES[@]}"
echo ">> 编译 x86_64 ..."
swiftc -O -whole-module-optimization \
-target x86_64-apple-macos14.0 \
-o build/bin/FileAssistant-x86_64 \
"${SOURCES[@]}"
# 合并为通用二进制
echo ">> 合并通用二进制 ..."
lipo -create -output build/bin/FileAssistant \
build/bin/FileAssistant-arm64 build/bin/FileAssistant-x86_64
# 组装 .app
APP=build/FileAssistant.app
mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Resources"
cp build/bin/FileAssistant "$APP/Contents/MacOS/"
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>CFBundleName</key><string>FileAssistant</string>
<key>CFBundleDisplayName</key><string>FileAssistant</string>
<key>CFBundleIdentifier</key><string>local.fileassistant</string>
<key>CFBundleExecutable</key><string>FileAssistant</string>
<key>CFBundlePackageType</key><string>APPL</string>
<key>CFBundleVersion</key><string>${VERSION_BUILD}</string>
<key>CFBundleShortVersionString</key><string>${VERSION_SHORT}</string>
<key>CFBundleInfoDictionaryVersion</key><string>6.0</string>
<key>LSMinimumSystemVersion</key><string>14.0</string>
<key>NSPrincipalClass</key><string>NSApplication</string>
<key>NSHighResolutionCapable</key><true/>
</dict>
</plist>
EOF
printf 'APPL????' > "$APP/Contents/PkgInfo"
# ad-hoc 签名
codesign --force --sign - "$APP"
# 验证
echo ">> 架构验证:"
lipo -info "$APP/Contents/MacOS/FileAssistant"
echo ">> 完成:$(pwd)/$APP"
echo " 测试运行: open '$APP'"