Merge branch 'feat/llvm-obf-m3' into main
This commit is contained in:
@@ -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))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user