feat(flash-gui): cfgs 自定义 cfg 机制 + 全操作 SRST 连接序列 + 整包 0.11 工具链
This commit is contained in:
@@ -15,8 +15,11 @@ zip 解压后根目录为 DAPLinkFlash/, 与 exe 运行目录结构一致:
|
||||
|
||||
OpenOCD 来源(--openocd-src > 环境变量 OPENOCD_SRC > 自动探测):
|
||||
1. FlashTool/toolchain/openocd (随仓库自带, 若已 vendor)
|
||||
2. D:/toolchain/openocd (开发机本机安装)
|
||||
目录布局: <src>/bin/openocd.exe + <src>/openocd/scripts/
|
||||
2. D:/toolchain/xpack-openocd-0.11.0-3
|
||||
3. D:/toolchain/openocd
|
||||
整个工具链目录原样打包(不挑文件); scripts 布局自动兼容
|
||||
xpack 0.11(scripts/) 与 0.12(openocd/scripts/)两种。
|
||||
程序目录还会带一个空的 cfgs/ 目录(放自定义 OpenOCD cfg, 界面下拉可选)。
|
||||
|
||||
用法:
|
||||
python package_release.py 版本号自动取最近 git tag(DAPLinkFlash-v*)
|
||||
@@ -52,37 +55,52 @@ def detect_version():
|
||||
|
||||
|
||||
def resolve_openocd_src(explicit):
|
||||
"""定位 OpenOCD 工具链源目录, 校验布局并返回路径"""
|
||||
"""定位 OpenOCD 工具链源目录(bin/openocd.exe 必在, scripts 布局兼容两种)"""
|
||||
candidates = [explicit, os.environ.get('OPENOCD_SRC'),
|
||||
os.path.join(BASE, 'toolchain', 'openocd'),
|
||||
r'D:/toolchain/xpack-openocd-0.11.0-3',
|
||||
r'D:/toolchain/openocd']
|
||||
for cand in candidates:
|
||||
if not cand:
|
||||
continue
|
||||
exe = os.path.join(cand, 'bin', 'openocd.exe')
|
||||
if not os.path.isfile(os.path.join(cand, 'bin', 'openocd.exe')):
|
||||
continue
|
||||
scripts = os.path.join(cand, 'openocd', 'scripts')
|
||||
if os.path.isfile(exe) and os.path.isdir(scripts):
|
||||
if not os.path.isdir(scripts):
|
||||
scripts = os.path.join(cand, 'scripts')
|
||||
if os.path.isdir(scripts):
|
||||
print(f'OpenOCD 工具链来源: {os.path.abspath(cand)}')
|
||||
return os.path.abspath(cand)
|
||||
sys.exit('未找到 OpenOCD 工具链(需 bin/openocd.exe + openocd/scripts/):\n'
|
||||
' python package_release.py <版本> --openocd-src <toolchain/openocd 目录>\n'
|
||||
sys.exit('未找到 OpenOCD 工具链(需 bin/openocd.exe + scripts/):\n'
|
||||
' python package_release.py <版本> --openocd-src <openocd 根目录>\n'
|
||||
' 或设置环境变量 OPENOCD_SRC')
|
||||
|
||||
|
||||
def copy_toolchain(openocd_src):
|
||||
"""复制 bin(openocd.exe + 运行 DLL)与 openocd/scripts 到程序目录 toolchain/"""
|
||||
"""整个工具链目录原样复制到程序目录 toolchain/openocd(不挑文件)"""
|
||||
dst_root = os.path.join(APP_DIR, 'toolchain', 'openocd')
|
||||
if os.path.isdir(dst_root):
|
||||
shutil.rmtree(dst_root)
|
||||
count = 0
|
||||
for sub in ('bin', os.path.join('openocd', 'scripts')):
|
||||
src = os.path.join(openocd_src, sub)
|
||||
dst = os.path.join(dst_root, sub)
|
||||
os.makedirs(os.path.dirname(dst), exist_ok=True)
|
||||
shutil.copytree(src, dst)
|
||||
for _root, _dirs, files in os.walk(dst):
|
||||
count += len(files)
|
||||
return count
|
||||
shutil.copytree(openocd_src, dst_root)
|
||||
return sum(len(fs) for _r, _d, fs in os.walk(dst_root))
|
||||
|
||||
|
||||
CFGS_README = (
|
||||
"把自定义 OpenOCD cfg 文件放到本目录(任意文件名.cfg)。\n"
|
||||
"DAPLink Flash 的 \"Target 配置\"/\"Interface 配置\" 下拉框会自动列出\n"
|
||||
"cfgs/<文件名>, 选中即用; 选择会被记住。\n"
|
||||
)
|
||||
|
||||
|
||||
def ensure_cfgs_dir():
|
||||
"""程序目录建 cfgs/ + 说明文件"""
|
||||
d = os.path.join(APP_DIR, 'cfgs')
|
||||
os.makedirs(d, exist_ok=True)
|
||||
readme = os.path.join(d, '说明-把cfg放这里.txt')
|
||||
if not os.path.exists(readme):
|
||||
with open(readme, 'w', encoding='utf-8') as f:
|
||||
f.write(CFGS_README)
|
||||
return d
|
||||
|
||||
|
||||
def main():
|
||||
@@ -103,7 +121,18 @@ def main():
|
||||
openocd_src = resolve_openocd_src(args.openocd_src)
|
||||
|
||||
n_files = copy_toolchain(openocd_src)
|
||||
ensure_cfgs_dir()
|
||||
shutil.copy2(readme, os.path.join(APP_DIR, 'README.md'))
|
||||
# 用户自定义 cfg 目录(存在才打包): 界面 Target/Interface 下拉可选用
|
||||
src_cfgs = os.path.join(BASE, 'cfgs')
|
||||
n_cfgs = 0
|
||||
if os.path.isdir(src_cfgs):
|
||||
dst_cfgs = os.path.join(APP_DIR, 'cfgs')
|
||||
if os.path.isdir(dst_cfgs):
|
||||
shutil.rmtree(dst_cfgs)
|
||||
shutil.copytree(src_cfgs, dst_cfgs)
|
||||
n_cfgs = sum(len(fs) for _r, _d, fs in os.walk(dst_cfgs))
|
||||
print(f'自定义 cfg: 复制 {n_cfgs} 个到发布包 cfgs/')
|
||||
|
||||
zip_name = f'{APP_NAME}-v{version}-win64.zip'
|
||||
zip_path = os.path.join(RELEASE, zip_name)
|
||||
@@ -116,7 +145,9 @@ def main():
|
||||
z.write(full, os.path.join(APP_NAME, os.path.relpath(full, APP_DIR)))
|
||||
|
||||
zip_mb = os.path.getsize(zip_path) / 1024 / 1024
|
||||
print(f'发布文件夹: {APP_DIR} (exe + _internal + 内置工具链 {n_files} 个文件, 平铺即用)')
|
||||
print(f'发布文件夹: {APP_DIR} (exe + _internal + 内置工具链 {n_files} 个文件'
|
||||
+ (f' + 自定义 cfg {n_cfgs} 个' if n_cfgs else '')
|
||||
+ ', 平铺即用)')
|
||||
print(f'发布包: {zip_path} ({zip_mb:.1f} MB)')
|
||||
print('下一步上传: python publish_gitea.py', zip_name)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user