diff --git a/backend/config.py b/backend/config.py index 7d4fbd6..685630b 100644 --- a/backend/config.py +++ b/backend/config.py @@ -108,6 +108,7 @@ COPY_ITEMS = [ "readoorTests", "Vendor", "AutoPacking", + "iOSGuardIntegration", "Podfile", "Pods", "Podfile.lock", diff --git a/backend/services/build_service.py b/backend/services/build_service.py index 4a22288..f7934a6 100644 --- a/backend/services/build_service.py +++ b/backend/services/build_service.py @@ -164,7 +164,7 @@ def _resolve_provisioning_profile(profile_reference: str) -> tuple[str, str]: _ERROR_RULES = [ (["No signing certificate", "Signing certificate \"", "Code Signing Error", "Code Sign error", "errSecInternalComponent", "CSSMERR_TP_NOT_TRUSTED", - "iPhone Distribution", "iPhone Developer: no identity found"], + "iPhone Distribution: no identity found", "iPhone Developer: no identity found"], "certificate", "签名证书问题:证书过期、未安装或不匹配,请检查钥匙串中的证书"), (["Provisioning profile", "No matching provisioning profiles", "embedded.mobileprovision", "PROVISIONING_PROFILE_SPECIFIER", @@ -209,6 +209,10 @@ def _classify_build_error(output_lines: list, step: str) -> tuple: """ output_text = "\n".join(output_lines) + missing_script = re.search(r"""can't open file ['"]([^'"]+)['"]: \[Errno 2\] No such file or directory""", output_text) + if missing_script: + return "config", f"构建脚本缺失:{missing_script.group(1)},请检查源码拷贝配置" + for keywords, category, hint in _ERROR_RULES: for kw in keywords: if kw.lower() in output_text.lower(): @@ -663,6 +667,12 @@ async def copy_source_code(task_id: str, task, source_dir: Path, definition: dic await log_streamer.emit(task_id, "代码拷贝完成") return build_dir + # 旧项目配置可能早于 Route 2 集成,按分支实际内容补齐快照。 + if (project_id == LEGACY_PROJECT_ID or definition.get("patcher") == PATCHER_READOOR) and ( + source_dir / "iOSGuardIntegration" + ).is_dir() and "iOSGuardIntegration" not in copy_items: + copy_items = [*copy_items, "iOSGuardIntegration"] + build_dir.mkdir(parents=True) for item in copy_items: src = source_dir / item @@ -673,7 +683,7 @@ async def copy_source_code(task_id: str, task, source_dir: Path, definition: dic dst = build_dir / item if src.is_dir(): await log_streamer.emit(task_id, f"拷贝目录: {item}") - shutil.copytree(src, dst, ignore=shutil.ignore_patterns(".git", "DerivedData")) + shutil.copytree(src, dst, symlinks=True, ignore=shutil.ignore_patterns(".git", "DerivedData")) elif src.is_file(): await log_streamer.emit(task_id, f"拷贝文件: {item}") shutil.copy2(src, dst) @@ -979,6 +989,15 @@ async def build_project(task_id: str, task, config_data: dict, build_dir: Path, else: raise BuildError("项目未配置 Xcode workspace 或 project", category="config") + if scheme in ("readoor31", "readoor31OtherPay"): + project_file = build_dir / "readoor.xcodeproj" / "project.pbxproj" + if project_file.is_file(): + project_text = project_file.read_text(encoding="utf-8") + for script in ("ig_ld_wrapper.py", "ig_guard_frameworks_phase.py"): + relative = Path("iOSGuardIntegration/toolchain/tools/xcode_archive") / script + if str(relative) in project_text and not (build_dir / relative).is_file(): + raise BuildError(f"源码快照缺少工程引用的脚本:{relative}", category="config") + export_path.mkdir(parents=True, exist_ok=True) # 清理 diff --git a/tests/test_build_service.py b/tests/test_build_service.py index 3fa3890..85476c7 100644 --- a/tests/test_build_service.py +++ b/tests/test_build_service.py @@ -22,6 +22,8 @@ from backend.services.build_service import ( _cleanup_old_builds, _mark_superseded_tasks, _resolve_provisioning_profile, + _classify_build_error, + BuildError, ) from backend.services.log_streamer import LogStreamer @@ -202,14 +204,45 @@ async def test_copy_source_code(tmp_dirs, log_streamer): assert result.exists() assert (result / "readoor" / "AppDelegate.swift").exists() assert (result / "Pods").exists() - assert (result / "Podfile").exists() - assert not (result / "podfile").exists() + names = {entry.name for entry in result.iterdir()} + assert "Podfile" in names + assert "podfile" not in names assert (result / "Podfile.lock").exists() assert (result / "readoor.xcworkspace").exists() assert (result / "Vendor" / "RDEpubReaderView" / "RDEpubReaderView.podspec").exists() assert (result / "AutoPacking" / "obfuscation" / "generate_image_whitelist.py").exists() +async def test_legacy_copy_items_include_guard_with_relative_links(tmp_dirs): + source, builds = tmp_dirs + toolchain = source / "iOSGuardIntegration" / "toolchain" + toolchain.mkdir(parents=True) + (toolchain / "readoor-test").symlink_to("../..") + definition = {"copy_items": ["readoor"]} + with patch("backend.services.build_service.BUILD_BASE_DIR", builds): + snapshot = await copy_source_code("guard", MagicMock(), source, definition) + link = snapshot / "iOSGuardIntegration/toolchain/readoor-test" + assert link.is_symlink() and link.resolve() == snapshot + assert definition["copy_items"] == ["readoor"] + + +async def test_missing_guard_script_fails_before_archive(tmp_dirs): + source, _ = tmp_dirs + relative = "iOSGuardIntegration/toolchain/tools/xcode_archive/ig_guard_frameworks_phase.py" + (source / "readoor.xcodeproj/project.pbxproj").write_text(relative) + with pytest.raises(BuildError, match="ig_guard_frameworks_phase.py"): + await build_project("guard", MagicMock(), {"SCHEME": "readoor31OtherPay"}, source, + {"workspace": "readoor.xcworkspace"}) + + +def test_missing_script_with_normal_signing_identity(): + lines = ["Signing Identity: iPhone Distribution: Example", + "python3: can't open file '/tmp/guard.py': [Errno 2] No such file or directory"] + category, hint = _classify_build_error(lines, "archive") + assert category == "config" and "/tmp/guard.py" in hint + assert _classify_build_error(["No signing certificate found"], "archive")[0] == "certificate" + + async def test_copy_source_code_normalizes_lowercase_podfile(tmp_dirs, log_streamer): """旧分支的 podfile 也必须复制为 Pods 工程引用的 Podfile。""" source_dir, build_dir_parent = tmp_dirs