fix(build): stop build-ios.sh from clobbering the macOS Xcode project

The iOS packaging script wrote project.yml into the repo root with
`name: MiniPlayer` and ran xcodegen there, regenerating
MiniPlayer.xcodeproj as an iOS-only project and destroying the macOS
target.

Generate into an isolated dir (.build-ios/xcodegen) under a distinct
project name (MiniPlayerIOS), reference packages/sources by absolute
path so they resolve from the nested location, and archive that
project instead. The macOS project is never touched.

Also wire Assets.xcassets into the iOS target for the app icon.
This commit is contained in:
yumoqing 2026-10-04 12:07:42 +08:00
parent dd64a21404
commit fcf12597e0

View File

@ -7,6 +7,7 @@ set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
PARENT_DIR="$(cd "$PROJECT_DIR/.." && pwd)"
APP_NAME="MiniPlayer" APP_NAME="MiniPlayer"
VERSION=$(date +%Y.%m.%d) VERSION=$(date +%Y.%m.%d)
BUILD_DIR="$PROJECT_DIR/.build-ios" BUILD_DIR="$PROJECT_DIR/.build-ios"
@ -25,10 +26,14 @@ echo "Team ID: $TEAM_ID"
# 1. 生成 Xcode 项目 # 1. 生成 Xcode 项目
echo "" echo ""
echo "--- Step 1: 生成 Xcode 项目 ---" echo "--- Step 1: 生成 Xcode 项目 ---"
cd "$PROJECT_DIR"
cat > project.yml << EOF # 关键:iOS 工程生成到一个独立目录 + 独立工程名,
name: MiniPlayer # 绝不在仓库根目录运行 xcodegen —— 否则会以 name: MiniPlayer
# 覆盖 macOS 的 MiniPlayer.xcodeproj,破坏 macOS target。
IOS_GEN_DIR="$BUILD_DIR/xcodegen"
mkdir -p "$IOS_GEN_DIR"
cat > "$IOS_GEN_DIR/project.yml" << EOF
name: MiniPlayerIOS
options: options:
bundleIdPrefix: com.miniplayer bundleIdPrefix: com.miniplayer
deploymentTarget: deploymentTarget:
@ -38,18 +43,20 @@ options:
packages: packages:
SwiftBricks: SwiftBricks:
path: ../swiftbricks path: $PARENT_DIR/swiftbricks
StreamRecorder: StreamRecorder:
path: ../StreamRecorder path: $PARENT_DIR/StreamRecorder
targets: targets:
MiniPlayer: MiniPlayerIOS:
type: application type: application
platform: iOS platform: iOS
sources: sources:
- path: Sources - path: $PROJECT_DIR/Sources
excludes: excludes:
- "**/PlayerRecorder.swift" - "**/PlayerRecorder.swift"
- path: $PROJECT_DIR/Assets.xcassets
buildPhase: resources
dependencies: dependencies:
- package: SwiftBricks - package: SwiftBricks
- package: StreamRecorder - package: StreamRecorder
@ -71,25 +78,25 @@ targets:
GENERATE_INFOPLIST_FILE: YES GENERATE_INFOPLIST_FILE: YES
ASSETCATALOG_COMPILER_APPICON_NAME: AppIcon ASSETCATALOG_COMPILER_APPICON_NAME: AppIcon
resources: resources:
- path: Sources/Resources - path: $PROJECT_DIR/Sources/Resources
EOF EOF
if command -v xcodegen &> /dev/null; then if command -v xcodegen &> /dev/null; then
xcodegen generate (cd "$IOS_GEN_DIR" && xcodegen generate)
echo " ✓ Xcode 项目生成成功" echo " ✓ Xcode 项目生成成功: $IOS_GEN_DIR/MiniPlayerIOS.xcodeproj"
else else
echo " ⚠ xcodegen 未安装,使用 xcodebuild + SPM 模式" echo " ⚠ xcodegen 未安装,使用 xcodebuild + SPM 模式"
rm -f project.yml rm -f "$IOS_GEN_DIR/project.yml"
fi fi
# 2. Archive # 2. Archive
echo "" echo ""
echo "--- Step 2: Archive ---" echo "--- Step 2: Archive ---"
if [ -f "$PROJECT_DIR/MiniPlayer.xcodeproj/project.pbxproj" ]; then if [ -f "$IOS_GEN_DIR/MiniPlayerIOS.xcodeproj/project.pbxproj" ]; then
# 使用 xcodegen 生成的项目 # 使用独立目录里生成的 iOS 工程(不会触碰 macOS 工程)
SCHEME="MiniPlayer" SCHEME="MiniPlayerIOS"
PROJECT_FLAG="-project $PROJECT_DIR/MiniPlayer.xcodeproj" PROJECT_FLAG="-project $IOS_GEN_DIR/MiniPlayerIOS.xcodeproj"
else else
# 使用 SPM 自动生成的项目 # 使用 SPM 自动生成的项目
SCHEME="MiniPlayeriOS" SCHEME="MiniPlayeriOS"
@ -172,5 +179,5 @@ else
echo " 提示: 检查签名配置和 ExportOptions.plist" echo " 提示: 检查签名配置和 ExportOptions.plist"
fi fi
# 清理临时文件 # 清理临时文件(只清理独立生成目录,不触碰仓库根目录)
rm -f "$PROJECT_DIR/project.yml" rm -f "$IOS_GEN_DIR/project.yml"