fix(build): IPA 加固门禁审计按分支脚本支持的参数传参,兼容旧分支打包

旧分支自带的 audit_exported_ipa.py 只支持 ipa / --bundle-id,
服务端传入 --archive、--report-out 等参数会被 argparse 拒绝导致打包失败。
现先解析分支脚本声明的参数,仅传入其支持的选项,旧脚本仍执行基础审计。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-11-26 12:02:55 +09:00
co-authored by Claude Opus 5.5
parent e9449155e4
commit 488c6416c2
2 changed files with 70 additions and 0 deletions
+38
View File
@@ -1285,6 +1285,34 @@ def persist_task_artifacts(
return persisted_dsym, persisted_maps
_ARGPARSE_OPTION_RE = re.compile(r"""add_argument\(\s*['"](--[\w-]+)['"]""")
def _detect_audit_script_options(audit_script: Path) -> Optional[set]:
"""从分支自带审计脚本源码中解析 argparse 声明的可选参数;无法判断时返回 None(按新版处理)。"""
try:
source = audit_script.read_text(encoding="utf-8", errors="replace")
except OSError:
return None
options = set(_ARGPARSE_OPTION_RE.findall(source))
return options or None
def _filter_audit_cmd_options(cmd: list, supported: set) -> tuple:
"""剔除旧版审计脚本不认识的「--选项 值」对,返回 (新命令, 被剔除的选项列表)。"""
filtered, dropped = [], []
i = 0
while i < len(cmd):
item = cmd[i]
if item.startswith("--") and item not in supported:
dropped.append(item)
i += 2 # 服务端追加的审计选项都带一个值
continue
filtered.append(item)
i += 1
return filtered, dropped
async def _run_exported_ipa_audit(
task_id: str,
audit_script: Path,
@@ -1324,6 +1352,16 @@ async def _run_exported_ipa_audit(
chosen_sym = (exact or sym_maps)[-1]
cmd.extend(["--symbol-map", str(chosen_sym)])
# 兼容旧分支:其自带审计脚本可能只支持 ipa / --bundle-id,传入未知参数会被 argparse 直接拒绝
supported = _detect_audit_script_options(audit_script)
if supported is not None:
cmd, dropped = _filter_audit_cmd_options(cmd, supported)
if dropped:
await log_streamer.emit(
task_id,
f"⚠️ 分支审计脚本为旧版,不支持 {', '.join(dropped)},按分支脚本能力执行基础审计",
)
await log_streamer.emit(task_id, "开始 IPA 加固门禁审计...")
process = await asyncio.create_subprocess_exec(
*cmd,