Merge branch 'feature/export_bat_exit_codes_v5.2' into 'release/v5.2'

feat(tools): produce correct err code in install/export .bat scripts (v5.2)

See merge request espressif/esp-idf!29544
This commit is contained in:
Roland Dobai 2024-03-12 15:11:51 +08:00
commit f18329b15f
2 changed files with 49 additions and 19 deletions

View File

@ -4,12 +4,20 @@ if defined MSYSTEM (
goto :eof goto :eof
) )
set SCRIPT_EXIT_CODE=0
:: Missing requirements check :: Missing requirements check
set MISSING_REQUIREMENTS= set MISSING_REQUIREMENTS=
python.exe --version >NUL 2>NUL python.exe --version >NUL 2>NUL
if %errorlevel% neq 0 set "MISSING_REQUIREMENTS= python &echo\" if %errorlevel% neq 0 (
set SCRIPT_EXIT_CODE=%errorlevel%
set "MISSING_REQUIREMENTS= python &echo\"
)
git.exe --version >NUL 2>NUL git.exe --version >NUL 2>NUL
if %errorlevel% neq 0 set "MISSING_REQUIREMENTS=%MISSING_REQUIREMENTS% git" if %errorlevel% neq 0 (
set SCRIPT_EXIT_CODE=%errorlevel%
set "MISSING_REQUIREMENTS=%MISSING_REQUIREMENTS% git"
)
if not "%MISSING_REQUIREMENTS%" == "" goto :__error_missing_requirements if not "%MISSING_REQUIREMENTS%" == "" goto :__error_missing_requirements
@ -34,7 +42,10 @@ echo Adding ESP-IDF tools to PATH...
:: but that way it is impossible to get the exit code of idf_tools.py. :: but that way it is impossible to get the exit code of idf_tools.py.
set "IDF_TOOLS_EXPORTS_FILE=%TEMP%\idf_export_vars.tmp" set "IDF_TOOLS_EXPORTS_FILE=%TEMP%\idf_export_vars.tmp"
python.exe "%IDF_PATH%\tools\idf_tools.py" export --format key-value >"%IDF_TOOLS_EXPORTS_FILE%" python.exe "%IDF_PATH%\tools\idf_tools.py" export --format key-value >"%IDF_TOOLS_EXPORTS_FILE%"
if %errorlevel% neq 0 goto :__end if %errorlevel% neq 0 (
set SCRIPT_EXIT_CODE=%errorlevel%
goto :__end
)
for /f "usebackq tokens=1,2 eol=# delims==" %%a in ("%IDF_TOOLS_EXPORTS_FILE%") do ( for /f "usebackq tokens=1,2 eol=# delims==" %%a in ("%IDF_TOOLS_EXPORTS_FILE%") do (
call set "%%a=%%b" call set "%%a=%%b"
@ -55,7 +66,10 @@ DOSKEY parttool.py=python.exe "%IDF_PATH%\components\partition_table\parttool.py
echo Checking if Python packages are up to date... echo Checking if Python packages are up to date...
python.exe "%IDF_PATH%\tools\idf_tools.py" check-python-dependencies python.exe "%IDF_PATH%\tools\idf_tools.py" check-python-dependencies
if %errorlevel% neq 0 goto :__end if %errorlevel% neq 0 (
set SCRIPT_EXIT_CODE=%errorlevel%
goto :__end
)
python.exe "%IDF_PATH%\tools\idf_tools.py" uninstall --dry-run > UNINSTALL_OUTPUT python.exe "%IDF_PATH%\tools\idf_tools.py" uninstall --dry-run > UNINSTALL_OUTPUT
SET /p UNINSTALL=<UNINSTALL_OUTPUT SET /p UNINSTALL=<UNINSTALL_OUTPUT
@ -110,3 +124,4 @@ set OLD_PATH=
set PATH_ADDITIONS= set PATH_ADDITIONS=
set MISSING_REQUIREMENTS= set MISSING_REQUIREMENTS=
set UNINSTALL= set UNINSTALL=
exit /b %SCRIPT_EXIT_CODE%

View File

@ -1,44 +1,58 @@
@echo off @echo off
if defined MSYSTEM ( if defined MSYSTEM (
echo This .bat file is for Windows CMD.EXE shell only. echo This .bat file is for Windows CMD.EXE shell only.
goto :end goto :__end
) )
set SCRIPT_EXIT_CODE=0
:: Missing requirements check :: Missing requirements check
set MISSING_REQUIREMENTS= set MISSING_REQUIREMENTS=
python.exe --version >NUL 2>NUL python.exe --version >NUL 2>NUL
if %errorlevel% neq 0 set "MISSING_REQUIREMENTS= python &echo\" if %errorlevel% neq 0 (
set SCRIPT_EXIT_CODE=%errorlevel%
set "MISSING_REQUIREMENTS= python &echo\"
)
git.exe --version >NUL 2>NUL git.exe --version >NUL 2>NUL
if %errorlevel% neq 0 set "MISSING_REQUIREMENTS=%MISSING_REQUIREMENTS% git" if %errorlevel% neq 0 (
set SCRIPT_EXIT_CODE=%errorlevel%
set "MISSING_REQUIREMENTS=%MISSING_REQUIREMENTS% git"
)
if not "%MISSING_REQUIREMENTS%" == "" goto :error_missing_requirements if not "%MISSING_REQUIREMENTS%" == "" goto :__error_missing_requirements
:: Infer IDF_PATH from script location :: Infer IDF_PATH from script location
set IDF_PATH=%~dp0 set IDF_PATH=%~dp0
set IDF_PATH=%IDF_PATH:~0,-1% set IDF_PATH=%IDF_PATH:~0,-1%
:: Print help if requested :: Print help if requested
if /I "%1" == "/?" goto :help if /I "%1" == "/?" goto :__help
if /I "%1" == "-h" goto :help if /I "%1" == "-h" goto :__help
if /I "%1" == "--help" goto :help if /I "%1" == "--help" goto :__help
for /f "delims=" %%i in ('python.exe "%IDF_PATH%\tools\install_util.py" extract targets "%*"') do set TARGETS=%%i for /f "delims=" %%i in ('python.exe "%IDF_PATH%\tools\install_util.py" extract targets "%*"') do set TARGETS=%%i
echo Installing ESP-IDF tools echo Installing ESP-IDF tools
python.exe "%IDF_PATH%\tools\idf_tools.py" install --targets=%TARGETS% python.exe "%IDF_PATH%\tools\idf_tools.py" install --targets=%TARGETS%
if %errorlevel% neq 0 goto :end if %errorlevel% neq 0 (
set SCRIPT_EXIT_CODE=%errorlevel%
goto :__end
)
for /f "delims=" %%i in ('python.exe "%IDF_PATH%\tools\install_util.py" extract features "%*"') do set FEATURES=%%i for /f "delims=" %%i in ('python.exe "%IDF_PATH%\tools\install_util.py" extract features "%*"') do set FEATURES=%%i
echo Setting up Python environment echo Setting up Python environment
python.exe "%IDF_PATH%\tools\idf_tools.py" install-python-env --features=%FEATURES% python.exe "%IDF_PATH%\tools\idf_tools.py" install-python-env --features=%FEATURES%
if %errorlevel% neq 0 goto :end if %errorlevel% neq 0 (
set SCRIPT_EXIT_CODE=%errorlevel%
goto :__end
)
echo All done! You can now run: echo All done! You can now run:
echo export.bat echo export.bat
goto :end goto :__end
:error_missing_requirements :__error_missing_requirements
echo. echo.
echo Error^: The following tools are not installed in your environment. echo Error^: The following tools are not installed in your environment.
echo. echo.
@ -47,10 +61,11 @@ goto :end
echo Please use the Windows Tool installer for setting up your environment. echo Please use the Windows Tool installer for setting up your environment.
echo Download link: https://dl.espressif.com/dl/esp-idf/ echo Download link: https://dl.espressif.com/dl/esp-idf/
echo For more details please visit our website: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/windows-setup.html echo For more details please visit our website: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/windows-setup.html
goto :end goto :__end
:help :__help
python.exe "%IDF_PATH%\tools\install_util.py" print_help bat python.exe "%IDF_PATH%\tools\install_util.py" print_help bat
goto :end goto :__end
:end :__end
exit /b %SCRIPT_EXIT_CODE%