feat: 修复混淆路径过滤与错误分类误报,并加速打包流程

- 同步 discovery.py 修复:相对 scan_dir 路径过滤,防止 ./build 目录下 Pods/ 第三方库保护失效
- 同步 obfuscate_symbols.py 多进程并行混淆写盘,build_service 启用 PYTHONUNBUFFERED=1 与 python3 -u 实时输出进度
- build_service 移除全新 derived_data 下多余的 xcodebuild clean,macOS APFS 优先使用 cp -c -R 零拷贝克隆源码
- Ad_Hoc 包按「分支 + 版本号」稳定复用 L1/LLVM seed 命中 obj_cache,App_Store 保持每次唯一
- 收紧 _classify_build_error 中 provisioning 关键词并补充协议遵循失败匹配,避免编译错误被误报为描述文件问题
- 更新与补充单元测试(226 passed)
This commit is contained in:
shenlei
2026-11-24 14:26:44 +09:00
parent b133b6c28d
commit dee9e3a4f2
5 changed files with 282 additions and 53 deletions
@@ -4630,6 +4630,43 @@ _GLOBAL_WORKER_AHO = None
_GLOBAL_WORKER_SELECTOR_MAPPING = None
_GLOBAL_WORKER_SWIFT_SIGNATURE_MAPPING = None
_GLOBAL_WORKER_DIRECT_METHOD_MAPPING = None
_GLOBAL_WORKER_VERBOSE = False
def _set_fork_worker_globals(
mapping,
mapping_re,
mapping_aho,
objc_selector_mapping,
swift_signature_mapping,
direct_method_mapping,
verbose: bool,
):
global _GLOBAL_WORKER_MAPPING, _GLOBAL_WORKER_MAPPING_RE, _GLOBAL_WORKER_AHO
global _GLOBAL_WORKER_SELECTOR_MAPPING, _GLOBAL_WORKER_SWIFT_SIGNATURE_MAPPING
global _GLOBAL_WORKER_DIRECT_METHOD_MAPPING, _GLOBAL_WORKER_VERBOSE
_GLOBAL_WORKER_MAPPING = mapping
_GLOBAL_WORKER_MAPPING_RE = mapping_re
_GLOBAL_WORKER_AHO = mapping_aho
_GLOBAL_WORKER_SELECTOR_MAPPING = objc_selector_mapping
_GLOBAL_WORKER_SWIFT_SIGNATURE_MAPPING = swift_signature_mapping
_GLOBAL_WORKER_DIRECT_METHOD_MAPPING = direct_method_mapping
_GLOBAL_WORKER_VERBOSE = bool(verbose)
def _fork_archive_plan_and_write_worker(path: str):
"""archive_mode 下由 fork 子进程直接完成规划与原子写盘,绕过 GIL 并将写盘分散到多进程。"""
_, changed, stats, new_text, _ = plan_file_change(
path,
_GLOBAL_WORKER_MAPPING,
_GLOBAL_WORKER_MAPPING_RE,
objc_selector_mapping=_GLOBAL_WORKER_SELECTOR_MAPPING,
swift_signature_mapping=_GLOBAL_WORKER_SWIFT_SIGNATURE_MAPPING,
mapping_aho=_GLOBAL_WORKER_AHO,
method_direct_mapping=_GLOBAL_WORKER_DIRECT_METHOD_MAPPING,
)
if changed:
atomic_write_text(path, new_text, encoding="utf-8")
return path, True, (stats if _GLOBAL_WORKER_VERBOSE else None)
return path, False, None
def _pool_init(mapping_json_str: str, selector_mapping_json_str: str, swift_signature_mapping_json_str: str, direct_method_mapping_json_str: str):
global _GLOBAL_WORKER_MAPPING, _GLOBAL_WORKER_MAPPING_RE, _GLOBAL_WORKER_AHO, _GLOBAL_WORKER_SELECTOR_MAPPING, _GLOBAL_WORKER_SWIFT_SIGNATURE_MAPPING, _GLOBAL_WORKER_DIRECT_METHOD_MAPPING
@@ -5496,7 +5533,36 @@ def main():
print(f"🔁 总目标文件 {len(all_targets)},需处理 {len(files_to_process)}(基于缓存)")
if args.workers > 1 and len(files_to_process) >= 20:
already_written_in_workers = False
if args.archive_mode and not args.generate_patch_dir and args.workers > 1 and len(files_to_process) >= 20:
_set_fork_worker_globals(
mapping,
mapping_re,
mapping_aho,
objc_selector_mapping,
swift_signature_mapping,
method_direct_mapping,
args.verbose_changes,
)
try:
ctx = multiprocessing.get_context("fork")
with ctx.Pool(processes=args.workers) as pool:
for idx, (path, changed, stats) in enumerate(
pool.imap_unordered(_fork_archive_plan_and_write_worker, files_to_process, chunksize=8),
start=1,
):
if changed:
planned_changes[path] = {"stats": stats or {}}
total_changed += 1
if idx % 50 == 0:
print(f" ... 进度 {idx}/{len(files_to_process)}", flush=True)
already_written_in_workers = True
except (ValueError, OSError):
# 平台不支持 fork 时回退下方线程池分支
planned_changes.clear()
total_changed = 0
if not already_written_in_workers and args.workers > 1 and len(files_to_process) >= 20:
# Avoid returning full file contents over multiprocessing pipes in archive mode.
# Use threads and flush per-file patches to disk when --generate-patch-dir is used
# to reduce memory pressure and allow inspecting progress live.
@@ -5549,7 +5615,7 @@ def main():
planned_changes[path]['original_text'] = original_text
total_changed += 1
if idx % 50 == 0:
print(f" ... 进度 {idx}/{len(files_to_process)}")
print(f" ... 进度 {idx}/{len(files_to_process)}", flush=True)
if write_patches_live:
# finalize manifest
try:
@@ -5561,7 +5627,7 @@ def main():
_log_stage_duration("替换规划", planning_stage_started_at)
_log_stage_duration("本次执行总耗时", total_started_at)
return
else:
elif not already_written_in_workers:
for idx, path in enumerate(files_to_process, start=1):
path, changed, stats, new_text, original_text = plan_file_change(path, mapping, mapping_re, objc_selector_mapping, swift_signature_mapping, mapping_aho, method_direct_mapping)
if changed:
@@ -5573,7 +5639,7 @@ def main():
planned_changes[path]['original_text'] = original_text
total_changed += 1
if idx % 50 == 0:
print(f" ... 进度 {idx}/{len(files_to_process)}")
print(f" ... 进度 {idx}/{len(files_to_process)}", flush=True)
# update cache for processed files
for p in files_to_process:
@@ -5613,7 +5679,9 @@ def main():
write_stage_started_at = time.perf_counter()
changed_files = sorted(planned_changes.keys())
if args.archive_mode:
if already_written_in_workers:
print(" (已在多进程规划阶段完成原子写盘)")
elif args.archive_mode:
direct_write(planned_changes)
else:
transactional_write(planned_changes)