From d65e3c8f4e1cfa52dfe73ea51804eca766998aec Mon Sep 17 00:00:00 2001 From: Marek Fiala Date: Fri, 23 Feb 2024 17:17:47 +0100 Subject: [PATCH] feat(tools): produce correct err code in export/install .bat scripts Plus unify labels to begin with underscore --- export.bat | 23 +++++++++++++++++++---- install.bat | 35 +++++++++++++++++++++++++---------- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/export.bat b/export.bat index 048a89ffd8..eb841b8c69 100644 --- a/export.bat +++ b/export.bat @@ -5,12 +5,20 @@ if defined MSYSTEM ( goto :eof ) +set SCRIPT_EXIT_CODE=0 + :: Missing requirements check set MISSING_REQUIREMENTS= 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 -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 @@ -32,7 +40,10 @@ echo Adding ESP-IDF tools to PATH... :: 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" 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 ( call set "%%a=%%b" @@ -53,7 +64,10 @@ DOSKEY parttool.py=python.exe "%IDF_PATH%\components\partition_table\parttool.py echo Checking if Python packages are up to date... python.exe "%IDF_PATH%\tools\check_python_dependencies.py" -if %errorlevel% neq 0 goto :__end +if %errorlevel% neq 0 ( + set SCRIPT_EXIT_CODE=%errorlevel% + goto :__end +) echo. echo Done! You can now compile ESP-IDF projects. @@ -95,3 +109,4 @@ set IDF_TOOLS_JSON_PATH= set OLD_PATH= set PATH_ADDITIONS= set MISSING_REQUIREMENTS= +exit /b %SCRIPT_EXIT_CODE% diff --git a/install.bat b/install.bat index df058f1ef1..9b9c0a2223 100644 --- a/install.bat +++ b/install.bat @@ -2,17 +2,25 @@ if defined MSYSTEM ( echo This .bat file is for Windows CMD.EXE shell only. When using MSYS, run: echo ./install.sh. - goto end + goto :__end ) +set SCRIPT_EXIT_CODE=0 + :: Missing requirements check set MISSING_REQUIREMENTS= 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 -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 set IDF_PATH=%~dp0 @@ -23,17 +31,23 @@ if NOT "%1"=="" set TARGETS=%* echo Installing ESP-IDF tools 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 +) echo Setting up Python environment python.exe "%IDF_PATH%\tools\idf_tools.py" install-python-env -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 export.bat -goto :end +goto :__end -:error_missing_requirements +:__error_missing_requirements echo. echo Error^: The following tools are not installed in your environment. echo. @@ -42,6 +56,7 @@ goto :end echo Please use the Windows Tool installer for setting up your environment. 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 - goto :end + goto :__end -:end +:__end +exit /b %SCRIPT_EXIT_CODE%