Skip to content

Commit 46ba89c

Browse files
committed
Merge branch 'feature/export_bat_exit_codes_v5.1' into 'release/v5.1'
feat(tools): produce correct err code in install/export .bat scripts (v5.1) See merge request espressif/esp-idf!29545
2 parents f93025b + b3b87e1 commit 46ba89c

File tree

2 files changed

+44
-14
lines changed

2 files changed

+44
-14
lines changed

export.bat

+19-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@ if defined MSYSTEM (
44
goto :eof
55
)
66

7+
set SCRIPT_EXIT_CODE=0
8+
79
:: Missing requirements check
810
set MISSING_REQUIREMENTS=
911
python.exe --version >NUL 2>NUL
10-
if %errorlevel% neq 0 set "MISSING_REQUIREMENTS= python &echo\"
12+
if %errorlevel% neq 0 (
13+
set SCRIPT_EXIT_CODE=%errorlevel%
14+
set "MISSING_REQUIREMENTS= python &echo\"
15+
)
1116
git.exe --version >NUL 2>NUL
12-
if %errorlevel% neq 0 set "MISSING_REQUIREMENTS=%MISSING_REQUIREMENTS% git"
17+
if %errorlevel% neq 0 (
18+
set SCRIPT_EXIT_CODE=%errorlevel%
19+
set "MISSING_REQUIREMENTS=%MISSING_REQUIREMENTS% git"
20+
)
1321

1422
if not "%MISSING_REQUIREMENTS%" == "" goto :__error_missing_requirements
1523

@@ -34,7 +42,10 @@ echo Adding ESP-IDF tools to PATH...
3442
:: but that way it is impossible to get the exit code of idf_tools.py.
3543
set "IDF_TOOLS_EXPORTS_FILE=%TEMP%\idf_export_vars.tmp"
3644
python.exe "%IDF_PATH%\tools\idf_tools.py" export --format key-value >"%IDF_TOOLS_EXPORTS_FILE%"
37-
if %errorlevel% neq 0 goto :__end
45+
if %errorlevel% neq 0 (
46+
set SCRIPT_EXIT_CODE=%errorlevel%
47+
goto :__end
48+
)
3849

3950
for /f "usebackq tokens=1,2 eol=# delims==" %%a in ("%IDF_TOOLS_EXPORTS_FILE%") do (
4051
call set "%%a=%%b"
@@ -55,7 +66,10 @@ DOSKEY parttool.py=python.exe "%IDF_PATH%\components\partition_table\parttool.py
5566

5667
echo Checking if Python packages are up to date...
5768
python.exe "%IDF_PATH%\tools\idf_tools.py" check-python-dependencies
58-
if %errorlevel% neq 0 goto :__end
69+
if %errorlevel% neq 0 (
70+
set SCRIPT_EXIT_CODE=%errorlevel%
71+
goto :__end
72+
)
5973

6074
python.exe "%IDF_PATH%\tools\idf_tools.py" uninstall --dry-run > UNINSTALL_OUTPUT
6175
SET /p UNINSTALL=<UNINSTALL_OUTPUT
@@ -110,3 +124,4 @@ set OLD_PATH=
110124
set PATH_ADDITIONS=
111125
set MISSING_REQUIREMENTS=
112126
set UNINSTALL=
127+
exit /b %SCRIPT_EXIT_CODE%

install.bat

+25-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
@echo off
22
if defined MSYSTEM (
33
echo This .bat file is for Windows CMD.EXE shell only.
4-
goto end
4+
goto :__end
55
)
66

7+
set SCRIPT_EXIT_CODE=0
8+
79
:: Missing requirements check
810
set MISSING_REQUIREMENTS=
911
python.exe --version >NUL 2>NUL
10-
if %errorlevel% neq 0 set "MISSING_REQUIREMENTS= python &echo\"
12+
if %errorlevel% neq 0 (
13+
set SCRIPT_EXIT_CODE=%errorlevel%
14+
set "MISSING_REQUIREMENTS= python &echo\"
15+
)
1116
git.exe --version >NUL 2>NUL
12-
if %errorlevel% neq 0 set "MISSING_REQUIREMENTS=%MISSING_REQUIREMENTS% git"
17+
if %errorlevel% neq 0 (
18+
set SCRIPT_EXIT_CODE=%errorlevel%
19+
set "MISSING_REQUIREMENTS=%MISSING_REQUIREMENTS% git"
20+
)
1321

14-
if not "%MISSING_REQUIREMENTS%" == "" goto :error_missing_requirements
22+
if not "%MISSING_REQUIREMENTS%" == "" goto :__error_missing_requirements
1523

1624
:: Infer IDF_PATH from script location
1725
set IDF_PATH=%~dp0
@@ -21,19 +29,25 @@ for /f "delims=" %%i in ('python.exe "%IDF_PATH%\tools\install_util.py" extract
2129

2230
echo Installing ESP-IDF tools
2331
python.exe "%IDF_PATH%\tools\idf_tools.py" install --targets=%TARGETS%
24-
if %errorlevel% neq 0 goto :end
32+
if %errorlevel% neq 0 (
33+
set SCRIPT_EXIT_CODE=%errorlevel%
34+
goto :__end
35+
)
2536

2637
for /f "delims=" %%i in ('python.exe "%IDF_PATH%\tools\install_util.py" extract features "%*"') do set FEATURES=%%i
2738

2839
echo Setting up Python environment
2940
python.exe "%IDF_PATH%\tools\idf_tools.py" install-python-env --features=%FEATURES%
30-
if %errorlevel% neq 0 goto :end
41+
if %errorlevel% neq 0 (
42+
set SCRIPT_EXIT_CODE=%errorlevel%
43+
goto :__end
44+
)
3145

3246
echo All done! You can now run:
3347
echo export.bat
34-
goto :end
48+
goto :__end
3549

36-
:error_missing_requirements
50+
:__error_missing_requirements
3751
echo.
3852
echo Error^: The following tools are not installed in your environment.
3953
echo.
@@ -42,6 +56,7 @@ goto :end
4256
echo Please use the Windows Tool installer for setting up your environment.
4357
echo Download link: https://dl.espressif.com/dl/esp-idf/
4458
echo For more details please visit our website: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/windows-setup.html
45-
goto :end
59+
goto :__end
4660

47-
:end
61+
:__end
62+
exit /b %SCRIPT_EXIT_CODE%

0 commit comments

Comments
 (0)