0972ef42 by 柴进

增加mac intel芯片的打包逻辑

1 parent 4dae7c18
1 #!/bin/bash
2 # macOS Build Script - Universal (Intel + Apple Silicon)
3 # 自动检测架构,自动安装依赖
4
5 set -e # 遇错即停
6
7 echo "================================"
8 echo "Building Gemini Image Generator"
9 echo "================================"
10
11 # 检测架构
12 ARCH=$(uname -m)
13 echo "Detected architecture: $ARCH"
14
15 # 设置 Homebrew 路径
16 if [ "$ARCH" = "arm64" ]; then
17 BREW_PREFIX="/opt/homebrew"
18 else
19 BREW_PREFIX="/usr/local"
20 fi
21
22 # 检查 Homebrew 是否安装
23 if ! command -v brew &> /dev/null; then
24 echo "Homebrew not found. Installing..."
25 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
26
27 # 添加到当前 shell 的 PATH
28 eval "$($BREW_PREFIX/bin/brew shellenv)"
29 fi
30
31 # 确保 brew 在 PATH 中
32 if ! command -v brew &> /dev/null; then
33 eval "$($BREW_PREFIX/bin/brew shellenv)"
34 fi
35
36 # 检查 Python 3.11 是否安装
37 PYTHON_CMD="$BREW_PREFIX/bin/python3.11"
38 if [ ! -f "$PYTHON_CMD" ]; then
39 echo "Python 3.11 not found. Installing via Homebrew..."
40 brew install python@3.11
41 fi
42
43 # 验证 Python 可用
44 if [ ! -f "$PYTHON_CMD" ]; then
45 echo "Error: Failed to install Python 3.11"
46 exit 1
47 fi
48
49 echo "Using Python: $PYTHON_CMD"
50 $PYTHON_CMD --version
51
52 # 检查虚拟环境是否有效(macOS 用 bin/activate,Windows 用 Scripts/activate)
53 if [ ! -f ".venv/bin/activate" ]; then
54 echo "Valid virtual environment not found, creating..."
55 rm -rf .venv
56 "$PYTHON_CMD" -m venv .venv
57 fi
58
59 # 激活虚拟环境
60 echo "Activating virtual environment..."
61 source .venv/bin/activate
62
63 # 安装依赖
64 echo "Installing dependencies..."
65 pip install --upgrade pip
66 pip install -r requirements.txt
67 pip install pyinstaller
68
69 # 清理旧构建
70 echo "Cleaning previous builds..."
71 rm -rf build dist *.spec
72
73 # 构建
74 echo "Building executable..."
75 pyinstaller --name="ZB100ImageGenerator" \
76 --onedir \
77 --windowed \
78 --add-data "config.json:." \
79 --icon=zb100_mac.icns \
80 image_generator.py
81
82 # 验证构建结果
83 if [ -d "dist/ZB100ImageGenerator.app" ]; then
84 echo "================================"
85 echo "Build successful!"
86 echo "Architecture: $ARCH"
87 echo "Application: dist/ZB100ImageGenerator.app"
88 echo "================================"
89
90 # 显示 app 信息
91 ls -lh dist/ZB100ImageGenerator.app/Contents/MacOS/
92 else
93 echo "================================"
94 echo "Build failed!"
95 echo "================================"
96 exit 1
97 fi