本地工具路径DTU_*环境变量改造落地:10处调用点去硬编码+变量优先解析,本机全链路验证通过,文档同步收口,requirements补pre-commit

This commit is contained in:
2026-10-02 22:14:49 +08:00
parent b96d649e62
commit 33a4aa4945
30 changed files with 4074 additions and 2917 deletions
+1 -1
View File
@@ -58,7 +58,7 @@
## ⚠️ 注意
- `build.bat` **硬编码本机 Keil 路径** `C:\Keil_v5\UV4\UV4.exe`(换机需改)
- 工具路径经 `DTU_*` 环境变量解析(`DTU_KEIL_UV4` = UV4.exe 完整路径,`DTU_STLINK_CLI` = ST-LINK_CLI.exe 完整路径;换机设变量即可,**无需改脚本**;契约见 `docs/环境与部署/本地工具路径环境变量方案.md`)
- 本目录被 pre-commit 门禁**排除**
- 启动文件的 `Heap_Size = 512B` 是**自研代码禁用 `malloc` 的根因**(见 `AGENTS.md`)
-1
View File
@@ -1 +0,0 @@
@echo off && cd /d "%~dp0" && C:\Keil_v5\UV4\UV4.exe -r "STM32F407-Demo.uvprojx" -t STM32F407-Demo -j0
+21 -1
View File
@@ -1,11 +1,31 @@
@echo off
setlocal
set UV4=C:\Keil_v5\UV4\UV4.exe
set PROJ=%~dp0STM32F407-Demo.uvprojx
set LOG=%~dp0build_log.txt
set TARGET=STM32F407-Demo
:: UV4 location: env var DTU_KEIL_UV4 = full path of UV4.exe.
:: Required on any MCU build machine; there is NO machine-default fallback
:: (no C:\Keil_v5 guess). Set it once per machine, user scope (no admin):
:: [Environment]::SetEnvironmentVariable('DTU_KEIL_UV4', 'D:\Tools\Keil\UV4\UV4.exe', 'User')
:: then reopen the terminal. Full contract: the DTU_* env var plan document
:: in docs/ (local tool path env vars plan).
if defined DTU_KEIL_UV4 goto uv4_set
echo BUILD_FAIL: environment variable DTU_KEIL_UV4 is not set
echo Set it to the full path of UV4.exe, e.g.:
echo [Environment]::SetEnvironmentVariable('DTU_KEIL_UV4', 'D:\Tools\Keil\UV4\UV4.exe', 'User')
exit /b 2
:uv4_set
if exist "%DTU_KEIL_UV4%" goto uv4_ok
echo ENV_ERROR: DTU_KEIL_UV4 is set but does not exist: "%DTU_KEIL_UV4%"
echo Fix the variable value. No fallback to another UV4 install is attempted.
exit /b 2
:uv4_ok
set UV4=%DTU_KEIL_UV4%
:: UV4 is single-instance: if an IDE process is alive, this -b call may be
:: forwarded to it (exit code is lost, GUI may open). Warn only; never kill.
tasklist /fi "imagename eq UV4.exe" /nh | find /i "UV4.exe" >nul
+17 -1
View File
@@ -1,11 +1,27 @@
@echo off
setlocal
set UV4=C:\Keil_v5\UV4\UV4.exe
set PROJ=%~dp0STM32F407-Demo.uvprojx
set LOG=%~dp0download_log.txt
set TARGET=STM32F407-Demo
:: UV4 location: env var DTU_KEIL_UV4 = full path of UV4.exe (same contract
:: as build.bat; required, no machine-default fallback).
if defined DTU_KEIL_UV4 goto uv4_set
echo DOWNLOAD_FAIL: environment variable DTU_KEIL_UV4 is not set
echo Set it to the full path of UV4.exe, e.g.:
echo [Environment]::SetEnvironmentVariable('DTU_KEIL_UV4', 'D:\Tools\Keil\UV4\UV4.exe', 'User')
exit /b 2
:uv4_set
if exist "%DTU_KEIL_UV4%" goto uv4_ok
echo ENV_ERROR: DTU_KEIL_UV4 is set but does not exist: "%DTU_KEIL_UV4%"
echo Fix the variable value. No fallback to another UV4 install is attempted.
exit /b 2
:uv4_ok
set UV4=%DTU_KEIL_UV4%
"%UV4%" -f "%PROJ%" -t%TARGET% -j0 -o "%LOG%"
findstr /C:"Application running" "%LOG%" >nul
+31 -4
View File
@@ -1,11 +1,38 @@
@echo off
setlocal
set STLINK=C:\Program Files (x86)\STMicroelectronics\STM32 ST-LINK Utility\ST-LINK Utility\ST-LINK_CLI.exe
if not exist "%STLINK%" (
echo RESET_FAIL: ST-LINK_CLI not found at "%STLINK%"
exit /b 2
:: ST-LINK CLI location: env var DTU_STLINK_CLI = full path of ST-LINK_CLI.exe.
:: Explicit value is used as-is (invalid value = hard error, no silent fallback);
:: when unset, fall back to PATH (where ST-LINK_CLI.exe).
set "STLINK="
if defined DTU_STLINK_CLI goto stlink_check
where ST-LINK_CLI.exe >nul 2>&1
if errorlevel 1 goto stlink_missing
for /f "delims=" %%i in ('where ST-LINK_CLI.exe 2^>nul') do (
if not defined STLINK set "STLINK=%%i"
)
if not defined STLINK goto stlink_missing
goto stlink_done
:stlink_check
if exist "%DTU_STLINK_CLI%" goto stlink_done
echo ENV_ERROR: DTU_STLINK_CLI is set but does not exist: "%DTU_STLINK_CLI%"
echo Fix the variable value. No fallback to PATH or other installs is attempted.
exit /b 2
:stlink_missing
echo ENV_ERROR: ST-LINK_CLI.exe not found (DTU_STLINK_CLI unset and not on PATH)
echo Set it to the full path of ST-LINK_CLI.exe, e.g.:
echo [Environment]::SetEnvironmentVariable('DTU_STLINK_CLI', 'C:\Tools\STLink\ST-LINK_CLI.exe', 'User')
exit /b 2
:stlink_done
if not defined STLINK set "STLINK=%DTU_STLINK_CLI%"
if exist "%STLINK%" goto stlink_ready
echo RESET_FAIL: ST-LINK_CLI not found at "%STLINK%"
exit /b 2
:stlink_ready
if "%~1"=="" goto :reset_run
if /i "%~1"=="hard" goto :hard