fix: 本地 Pod 索引缺少所需版本时自动 --repo-update 重试
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
10c39b5116
commit
a9e169b00c
@@ -860,6 +860,27 @@ def _pod_dir(build_dir: Path, xcode: dict = None) -> Path:
|
||||
return None
|
||||
|
||||
|
||||
_POD_SPEC_MISSING = "Unable to find a specification for"
|
||||
|
||||
|
||||
async def _run_pod(task_id: str, pod_dir: Path, *extra_args: str) -> tuple:
|
||||
"""执行 pod install,实时输出日志,返回 (退出码, 输出行)。"""
|
||||
process = await asyncio.create_subprocess_exec(
|
||||
"pod", "install", *extra_args,
|
||||
cwd=str(pod_dir),
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.STDOUT,
|
||||
)
|
||||
output = []
|
||||
async for line in process.stdout:
|
||||
decoded = line.decode("utf-8", errors="replace").strip()
|
||||
if decoded:
|
||||
output.append(decoded)
|
||||
await log_streamer.emit(task_id, decoded)
|
||||
await process.wait()
|
||||
return process.returncode, output
|
||||
|
||||
|
||||
async def run_pod_install(task_id: str, build_dir: Path, xcode: dict = None):
|
||||
"""安装 CocoaPods 依赖"""
|
||||
await log_streamer.emit_step(task_id, "安装依赖")
|
||||
@@ -871,21 +892,13 @@ async def run_pod_install(task_id: str, build_dir: Path, xcode: dict = None):
|
||||
if pod_dir != build_dir:
|
||||
await log_streamer.emit(task_id, f"Podfile 目录: {pod_dir.relative_to(build_dir)}")
|
||||
|
||||
process = await asyncio.create_subprocess_exec(
|
||||
"pod", "install",
|
||||
cwd=str(pod_dir),
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.STDOUT,
|
||||
)
|
||||
returncode, output = await _run_pod(task_id, pod_dir)
|
||||
# 打包机本地的 Specs 索引过旧时找不到新版本 Pod,更新索引后重试一次
|
||||
if returncode != 0 and any(_POD_SPEC_MISSING in line for line in output):
|
||||
await log_streamer.emit(task_id, "本地 Pod 索引缺少所需版本,更新索引后重试(pod install --repo-update)", level="warn")
|
||||
returncode, output = await _run_pod(task_id, pod_dir, "--repo-update")
|
||||
|
||||
async for line in process.stdout:
|
||||
decoded = line.decode("utf-8", errors="replace").strip()
|
||||
if decoded:
|
||||
await log_streamer.emit(task_id, decoded)
|
||||
|
||||
await process.wait()
|
||||
|
||||
if process.returncode != 0:
|
||||
if returncode != 0:
|
||||
raise BuildError("pod install 失败", category="config")
|
||||
|
||||
patched_files = await asyncio.to_thread(_patch_afnetworking_private_headers, pod_dir)
|
||||
|
||||
@@ -295,6 +295,28 @@ async def test_run_pod_install_uses_xcode_subdirectory(tmp_path, log_streamer):
|
||||
assert mock_exec.call_args.kwargs["cwd"] == str(sub)
|
||||
|
||||
|
||||
async def test_run_pod_install_retries_with_repo_update(tmp_path, log_streamer):
|
||||
"""本地 Specs 索引过旧找不到版本时,带 --repo-update 重试一次。"""
|
||||
(tmp_path / "Podfile").write_text("pod 'OpenSSL-Universal', '1.1.2301'")
|
||||
missing = _make_mock_process(1, b"[!] Unable to find a specification for `OpenSSL-Universal (= 1.1.2301)`\n")
|
||||
|
||||
with patch("asyncio.create_subprocess_exec", side_effect=[missing, _make_mock_process()]) as mock_exec:
|
||||
await run_pod_install("t1", tmp_path)
|
||||
|
||||
assert mock_exec.call_args_list[0].args == ("pod", "install")
|
||||
assert mock_exec.call_args_list[1].args == ("pod", "install", "--repo-update")
|
||||
|
||||
|
||||
async def test_run_pod_install_other_failure_not_retried(tmp_path, log_streamer):
|
||||
(tmp_path / "Podfile").write_text("pod 'SnapKit'")
|
||||
|
||||
with patch("asyncio.create_subprocess_exec", return_value=_make_mock_process(1, b"[!] Some error\n")) as mock_exec:
|
||||
with pytest.raises(Exception, match="pod install 失败"):
|
||||
await run_pod_install("t1", tmp_path)
|
||||
|
||||
assert mock_exec.call_count == 1
|
||||
|
||||
|
||||
async def test_build_project_passes_scheme_as_exec_argument(tmp_path, log_streamer):
|
||||
"""Scheme 中的 shell 特殊字符只能作为 xcodebuild 参数,不能被执行。"""
|
||||
build_dir = tmp_path / "build"
|
||||
|
||||
Reference in New Issue
Block a user