Merge branch 'feat/llvm-obf-m3' into main

This commit is contained in:
shenlei
2026-11-24 12:10:44 +09:00
23 changed files with 3340 additions and 359 deletions
+37
View File
@@ -1441,3 +1441,40 @@ async def delete_project(project_id: str):
del root["projects"][project_id]
_write_root(root)
return {"message": "项目已删除"}
@router.get("/toolchain")
async def get_toolchain_info():
"""查看当前打包机 Xcode 与 iOSGuard LLVM opt 工具链缓存状态(仅管理员)。"""
from ..services.toolchain_manager import get_toolchain_status
return await get_toolchain_status()
@router.post("/toolchain/refresh")
async def refresh_toolchain(request: Request):
"""手动触发 Xcode / opt 工具链校验与更新,可选传 {\"force_rebuild\": true}(仅管理员)。"""
from ..services.toolchain_manager import discover_toolchain_resolver, ensure_toolchain
force_rebuild = False
try:
body = await request.json()
if isinstance(body, dict):
force_rebuild = bool(body.get("force_rebuild", False))
except Exception:
pass
resolver = discover_toolchain_resolver()
if resolver is None:
raise HTTPException(
status_code=400,
detail="未找到 iOSGuard 工具链脚本,请先同步 Readoor 源码或配置 IG_TOOLCHAIN_SOURCE_DIR",
)
try:
return await ensure_toolchain(
resolver,
force_rebuild=force_rebuild,
notify_on_event=True,
)
except Exception as exc:
raise HTTPException(status_code=500, detail=str(exc)) from exc
+22 -6
View File
@@ -12,6 +12,7 @@ from fastapi.responses import FileResponse
from starlette.background import BackgroundTask
from sqlalchemy.orm import Session
from ..config import ARTIFACTS_DIR
from ..database import get_db
from ..models import Task
from ..schemas import TaskCreate, TaskResponse
@@ -57,8 +58,11 @@ async def create_task(task: TaskCreate, request: Request, user: dict = Depends(g
project_id = config["_project"]
from ..projects import get_definition
if task.obfuscation and not get_definition(project_id, config)["obfuscation"]:
supports_obfuscation = bool(get_definition(project_id, config)["obfuscation"])
if task.obfuscation and not supports_obfuscation:
raise HTTPException(status_code=400, detail="该项目不支持代码混淆")
# 记录用户勾选;分支 build_policy.json 声明强制混淆时,打包阶段会覆盖为启用并写回。
effective_obfuscation = bool(task.obfuscation) and supports_obfuscation
# 分支与 Tag 不允许重名,按名字即可确定要检出的引用类型
from .config import get_ref_type
@@ -74,7 +78,7 @@ async def create_task(task: TaskCreate, request: Request, user: dict = Depends(g
scheme_id=task.scheme_id,
scheme_name=scheme.get("displayName") or scheme_name,
exclude_symbols=task.build_type == "App_Store" and task.exclude_symbols,
obfuscation=task.obfuscation,
obfuscation=effective_obfuscation,
branch=task.branch,
ref_type=ref_type,
status="pending",
@@ -178,6 +182,9 @@ async def cancel_task(task_id: str, request: Request, user: dict = Depends(get_c
build_path = Path(task.build_dir)
if build_path.exists():
shutil.rmtree(build_path, ignore_errors=True)
task_artifacts = ARTIFACTS_DIR / task_id
if task_artifacts.exists():
shutil.rmtree(task_artifacts, ignore_errors=True)
return {"message": "任务已取消"}
@@ -242,11 +249,14 @@ async def delete_task(task_id: str, request: Request, user: dict = Depends(get_c
if log_path.exists():
log_path.unlink()
# 删除构建目录
# 删除构建目录及持久化产物目录
if task.build_dir:
build_path = Path(task.build_dir)
if build_path.exists():
shutil.rmtree(build_path, ignore_errors=True)
task_artifacts = ARTIFACTS_DIR / task_id
if task_artifacts.exists():
shutil.rmtree(task_artifacts, ignore_errors=True)
from ..services.audit_log import record_operation
record_operation(db, user, "task_deleted", request=request, task=task)
@@ -372,16 +382,22 @@ async def download_dsym(task_id: str, request: Request, user: dict = Depends(get
raise HTTPException(status_code=502, detail=f"生成下载链接失败:{exc}") from exc
return {"url": download_url}
# .dSYM 是目录(macOS bundle),需要压缩为 zip 再下载
# .dSYM 是目录(macOS bundle 或包含 App + IGArchiveGuard.framework 的 dSYMs 目录),需要压缩为 zip 再下载
if os.path.isdir(dsym_path):
zip_path = os.path.join(tempfile.gettempdir(), os.path.basename(dsym_path) + ".zip")
fd, zip_path = tempfile.mkstemp(suffix=".zip")
os.close(fd)
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zf:
for root, dirs, files in os.walk(dsym_path):
for f in files:
full = os.path.join(root, f)
arcname = os.path.relpath(full, os.path.dirname(dsym_path))
zf.write(full, arcname)
return FileResponse(zip_path, filename=os.path.basename(zip_path), media_type="application/zip")
return FileResponse(
zip_path,
filename=os.path.basename(dsym_path) + ".zip",
media_type="application/zip",
background=BackgroundTask(os.remove, zip_path),
)
return FileResponse(dsym_path, filename=os.path.basename(dsym_path))