[patch] 修改打包固定项缓存复用 提升打包效率

This commit is contained in:
2025-10-13 14:58:56 +08:00
parent 7d9297616f
commit 303c33b44d
2 changed files with 22 additions and 1 deletions

View File

@@ -135,6 +135,10 @@ jobs:
- name: Build production executable
if: success()
shell: powershell
# Optional: Set FORCE_FULL_CLEAN=true to force complete rebuild (clears build cache)
# Default: Incremental build mode (preserves build cache for faster builds)
# env:
# FORCE_FULL_CLEAN: "true"
run: |
Write-Host "==========================================";
Write-Host "Step 4.5: Build production executable";

View File

@@ -9,6 +9,11 @@ import subprocess
import shutil
from pathlib import Path
# Build optimization: Control whether to force full clean
# Set environment variable FORCE_FULL_CLEAN=true to clean both dist and build directories
# Default: false (incremental build, faster)
FORCE_FULL_CLEAN = os.getenv('FORCE_FULL_CLEAN', 'false').lower() == 'true'
def clean_build():
"""清理构建目录"""
@@ -22,7 +27,16 @@ def clean_build():
print("Waiting for file handles to release...")
time.sleep(0.5)
dirs_to_clean = ['dist', 'build']
# Build optimization: Preserve build cache for faster incremental builds
# The build directory contains PyInstaller analysis cache
# Preserving it can reduce build time from ~7min to ~3min
if FORCE_FULL_CLEAN:
dirs_to_clean = ['dist', 'build']
print("FORCE_FULL_CLEAN enabled - cleaning all directories including build cache")
else:
dirs_to_clean = ['dist']
print("Incremental build mode - preserving build cache for faster builds")
for dir_name in dirs_to_clean:
print(f"Checking directory: {dir_name}")
if os.path.exists(dir_name):
@@ -56,6 +70,9 @@ def build_with_command():
'--name=MultiPlatformGUI', # 直接使用最终目录名
'--onedir', # 相当于 --exclude-binaries
'--windowed', # 相当于 -w
'--noconfirm', # Build optimization: Skip confirmation prompts
'--log-level=WARN', # Build optimization: Reduce log output (only warnings and errors)
'--noupx', # Build optimization: Skip UPX compression (saves time, minimal size impact)
'--icon=static/ai_assistant_icon_64.png', # 添加主程序图标
'--add-data=config.py;.',
'--add-data=exe_file_logger.py;.',