From fcf12597e0e940231c1e1dbeb6238c44e3f550ab Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sun, 4 Oct 2026 12:07:42 +0800 Subject: [PATCH] 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. --- scripts/build-ios.sh | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/scripts/build-ios.sh b/scripts/build-ios.sh index 9f217a5..3f40596 100755 --- a/scripts/build-ios.sh +++ b/scripts/build-ios.sh @@ -7,6 +7,7 @@ set -e SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" +PARENT_DIR="$(cd "$PROJECT_DIR/.." && pwd)" APP_NAME="MiniPlayer" VERSION=$(date +%Y.%m.%d) BUILD_DIR="$PROJECT_DIR/.build-ios" @@ -25,10 +26,14 @@ echo "Team ID: $TEAM_ID" # 1. 生成 Xcode 项目 echo "" echo "--- Step 1: 生成 Xcode 项目 ---" -cd "$PROJECT_DIR" -cat > project.yml << EOF -name: MiniPlayer +# 关键:iOS 工程生成到一个独立目录 + 独立工程名, +# 绝不在仓库根目录运行 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: bundleIdPrefix: com.miniplayer deploymentTarget: @@ -38,18 +43,20 @@ options: packages: SwiftBricks: - path: ../swiftbricks + path: $PARENT_DIR/swiftbricks StreamRecorder: - path: ../StreamRecorder + path: $PARENT_DIR/StreamRecorder targets: - MiniPlayer: + MiniPlayerIOS: type: application platform: iOS sources: - - path: Sources + - path: $PROJECT_DIR/Sources excludes: - "**/PlayerRecorder.swift" + - path: $PROJECT_DIR/Assets.xcassets + buildPhase: resources dependencies: - package: SwiftBricks - package: StreamRecorder @@ -71,25 +78,25 @@ targets: GENERATE_INFOPLIST_FILE: YES ASSETCATALOG_COMPILER_APPICON_NAME: AppIcon resources: - - path: Sources/Resources + - path: $PROJECT_DIR/Sources/Resources EOF if command -v xcodegen &> /dev/null; then - xcodegen generate - echo " ✓ Xcode 项目生成成功" + (cd "$IOS_GEN_DIR" && xcodegen generate) + echo " ✓ Xcode 项目生成成功: $IOS_GEN_DIR/MiniPlayerIOS.xcodeproj" else echo " ⚠ xcodegen 未安装,使用 xcodebuild + SPM 模式" - rm -f project.yml + rm -f "$IOS_GEN_DIR/project.yml" fi # 2. Archive echo "" echo "--- Step 2: Archive ---" -if [ -f "$PROJECT_DIR/MiniPlayer.xcodeproj/project.pbxproj" ]; then - # 使用 xcodegen 生成的项目 - SCHEME="MiniPlayer" - PROJECT_FLAG="-project $PROJECT_DIR/MiniPlayer.xcodeproj" +if [ -f "$IOS_GEN_DIR/MiniPlayerIOS.xcodeproj/project.pbxproj" ]; then + # 使用独立目录里生成的 iOS 工程(不会触碰 macOS 工程) + SCHEME="MiniPlayerIOS" + PROJECT_FLAG="-project $IOS_GEN_DIR/MiniPlayerIOS.xcodeproj" else # 使用 SPM 自动生成的项目 SCHEME="MiniPlayeriOS" @@ -172,5 +179,5 @@ else echo " 提示: 检查签名配置和 ExportOptions.plist" fi -# 清理临时文件 -rm -f "$PROJECT_DIR/project.yml" +# 清理临时文件(只清理独立生成目录,不触碰仓库根目录) +rm -f "$IOS_GEN_DIR/project.yml"