fix(flash-gui): 窗口构建期隐藏改为延迟显示, 修复双击'闪退'; 打包改 onedir 提速
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
组装 DAPLink Flash 发布包: exe + 内置 OpenOCD 工具链 → 文件夹 + zip(解压即用)
|
||||
组装 DAPLink Flash 发布包: 程序目录(exe + 内置 OpenOCD 工具链) → zip(解压即用)
|
||||
================================================================
|
||||
release/ 本身就是可直接使用的完整文件夹(exe + toolchain/ + 说明),
|
||||
再原样压成 zip —— 两者内容始终一致。
|
||||
release/DAPLinkFlash/ 本身就是可直接使用的完整文件夹
|
||||
(exe + _internal/ + toolchain/ + 说明), 再原样压成 zip —— 内容始终一致。
|
||||
|
||||
zip 解压后根目录为 DAPLinkFlash/, 与 exe 运行目录结构一致:
|
||||
DAPLinkFlash/
|
||||
├── DAPLinkFlash.exe 主程序(先运行 build_exe.py 打包)
|
||||
├── _internal/ PyInstaller onedir 运行库
|
||||
├── toolchain/openocd/ 内置 OpenOCD(bin + scripts, GUI 自动定位)
|
||||
└── README.md 使用说明
|
||||
|
||||
@@ -35,6 +36,7 @@ SRC = os.path.dirname(os.path.abspath(__file__))
|
||||
BASE = os.path.dirname(SRC)
|
||||
RELEASE = os.path.join(BASE, 'release')
|
||||
APP_NAME = 'DAPLinkFlash'
|
||||
APP_DIR = os.path.join(RELEASE, APP_NAME) # onedir 输出目录 = 解压后的程序文件夹
|
||||
|
||||
|
||||
def detect_version():
|
||||
@@ -68,8 +70,8 @@ def resolve_openocd_src(explicit):
|
||||
|
||||
|
||||
def copy_toolchain(openocd_src):
|
||||
"""复制 bin(openocd.exe + 运行 DLL)与 openocd/scripts 到 release/toolchain/"""
|
||||
dst_root = os.path.join(RELEASE, 'toolchain', 'openocd')
|
||||
"""复制 bin(openocd.exe + 运行 DLL)与 openocd/scripts 到程序目录 toolchain/"""
|
||||
dst_root = os.path.join(APP_DIR, 'toolchain', 'openocd')
|
||||
if os.path.isdir(dst_root):
|
||||
shutil.rmtree(dst_root)
|
||||
count = 0
|
||||
@@ -92,31 +94,29 @@ def main():
|
||||
args = ap.parse_args()
|
||||
|
||||
version = (args.version or detect_version()).lstrip('v')
|
||||
exe = os.path.join(RELEASE, APP_NAME + '.exe')
|
||||
exe = os.path.join(APP_DIR, APP_NAME + '.exe')
|
||||
readme = os.path.join(BASE, 'README.md')
|
||||
if not os.path.exists(exe):
|
||||
sys.exit(f'缺少 release/{APP_NAME}.exe, 先运行: python build_exe.py')
|
||||
sys.exit(f'缺少 {APP_DIR}/{APP_NAME}.exe, 先运行: python build_exe.py')
|
||||
if not os.path.exists(readme):
|
||||
sys.exit(f'缺少 {readme}')
|
||||
openocd_src = resolve_openocd_src(args.openocd_src)
|
||||
|
||||
n_files = copy_toolchain(openocd_src)
|
||||
shutil.copy2(readme, os.path.join(RELEASE, 'README.md'))
|
||||
shutil.copy2(readme, os.path.join(APP_DIR, 'README.md'))
|
||||
|
||||
zip_name = f'{APP_NAME}-v{version}-win64.zip'
|
||||
zip_path = os.path.join(RELEASE, zip_name)
|
||||
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as z:
|
||||
z.write(exe, f'{APP_NAME}/{APP_NAME}.exe')
|
||||
z.write(os.path.join(RELEASE, 'README.md'), f'{APP_NAME}/README.md')
|
||||
tool_root = os.path.join(RELEASE, 'toolchain')
|
||||
for root, _dirs, files in os.walk(tool_root):
|
||||
for root, _dirs, files in os.walk(APP_DIR):
|
||||
for f in files:
|
||||
if f == 'flash_gui_settings.json': # 本机运行配置不随包分发
|
||||
continue
|
||||
full = os.path.join(root, f)
|
||||
z.write(full, os.path.join(APP_NAME, os.path.relpath(full, RELEASE)))
|
||||
z.write(full, os.path.join(APP_NAME, os.path.relpath(full, APP_DIR)))
|
||||
|
||||
exe_mb = os.path.getsize(exe) / 1024 / 1024
|
||||
zip_mb = os.path.getsize(zip_path) / 1024 / 1024
|
||||
print(f'发布文件夹: {RELEASE} (exe {exe_mb:.1f} MB + 内置工具链 {n_files} 个文件, 平铺即用)')
|
||||
print(f'发布文件夹: {APP_DIR} (exe + _internal + 内置工具链 {n_files} 个文件, 平铺即用)')
|
||||
print(f'发布包: {zip_path} ({zip_mb:.1f} MB)')
|
||||
print('下一步上传: python publish_gitea.py', zip_name)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user