export.bat 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. @echo off
  2. if defined MSYSTEM (
  3. echo This .bat file is for Windows CMD.EXE shell only. When using MSYS, run:
  4. echo . ./export.sh.
  5. goto :eof
  6. )
  7. :: Missing requirements check
  8. set MISSING_REQUIREMENTS=
  9. python.exe --version >NUL 2>NUL
  10. if %errorlevel% neq 0 set "MISSING_REQUIREMENTS= python &echo\"
  11. git.exe --version >NUL 2>NUL
  12. if %errorlevel% neq 0 set "MISSING_REQUIREMENTS=%MISSING_REQUIREMENTS% git"
  13. if not "%MISSING_REQUIREMENTS%" == "" goto :error_missing_requirements
  14. set PREFIX=python.exe %IDF_PATH%
  15. DOSKEY idf.py=%PREFIX%\tools\idf.py $*
  16. DOSKEY esptool.py=%PREFIX%\components\esptool_py\esptool\esptool.py $*
  17. DOSKEY espefuse.py=%PREFIX%\components\esptool_py\esptool\espefuse.py $*
  18. DOSKEY otatool.py=%PREFIX%\components\app_update\otatool.py $*
  19. DOSKEY parttool.py=%PREFIX%\components\partition_table\parttool.py $*
  20. :: Infer IDF_PATH from script location
  21. set IDF_PATH=%~dp0
  22. set IDF_PATH=%IDF_PATH:~0,-1%
  23. set IDF_TOOLS_PY_PATH=%IDF_PATH%\tools\idf_tools.py
  24. set IDF_TOOLS_JSON_PATH=%IDF_PATH%\tools\tools.json
  25. set IDF_TOOLS_EXPORT_CMD=%IDF_PATH%\export.bat
  26. set IDF_TOOLS_INSTALL_CMD=%IDF_PATH%\install.bat
  27. echo Setting IDF_PATH: %IDF_PATH%
  28. echo.
  29. set "OLD_PATH=%PATH%"
  30. echo Adding ESP-IDF tools to PATH...
  31. :: Export tool paths and environment variables.
  32. :: It is possible to do this without a temporary file (running idf_tools.py from for /r command),
  33. :: but that way it is impossible to get the exit code of idf_tools.py.
  34. set "IDF_TOOLS_EXPORTS_FILE=%TEMP%\idf_export_vars.tmp"
  35. python.exe %IDF_PATH%\tools\idf_tools.py export --format key-value >"%IDF_TOOLS_EXPORTS_FILE%"
  36. if %errorlevel% neq 0 goto :end
  37. for /f "usebackq tokens=1,2 eol=# delims==" %%a in ("%IDF_TOOLS_EXPORTS_FILE%") do (
  38. call set "%%a=%%b"
  39. )
  40. :: This removes OLD_PATH substring from PATH, leaving only the paths which have been added,
  41. :: and prints semicolon-delimited components of the path on separate lines
  42. call set PATH_ADDITIONS=%%PATH:%OLD_PATH%=%%
  43. if "%PATH_ADDITIONS%"=="" call :print_nothing_added
  44. if not "%PATH_ADDITIONS%"=="" echo %PATH_ADDITIONS:;=&echo. %
  45. echo Checking if Python packages are up to date...
  46. python.exe %IDF_PATH%\tools\check_python_dependencies.py
  47. if %errorlevel% neq 0 goto :end
  48. echo.
  49. echo Done! You can now compile ESP-IDF projects.
  50. echo Go to the project directory and run:
  51. echo.
  52. echo idf.py build
  53. echo.
  54. goto :end
  55. :print_nothing_added
  56. echo No directories added to PATH:
  57. echo.
  58. echo %PATH%
  59. echo.
  60. goto :eof
  61. :error_missing_requirements
  62. echo.
  63. echo Error^: The following tools are not installed in your environment.
  64. echo.
  65. echo %MISSING_REQUIREMENTS%
  66. echo.
  67. echo Please use the Windows Tool installer for setting up your environment.
  68. echo Download link: https://dl.espressif.com/dl/esp-idf/
  69. echo For more details please visit our website: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/windows-setup.html
  70. goto :end
  71. :end
  72. :: Clean up
  73. if not "%IDF_TOOLS_EXPORTS_FILE%"=="" (
  74. del "%IDF_TOOLS_EXPORTS_FILE%" 1>nul 2>nul
  75. )
  76. set IDF_TOOLS_EXPORTS_FILE=
  77. set IDF_TOOLS_EXPORT_CMD=
  78. set IDF_TOOLS_INSTALL_CMD=
  79. set IDF_TOOLS_PY_PATH=
  80. set IDF_TOOLS_JSON_PATH=
  81. set OLD_PATH=
  82. set PATH_ADDITIONS=
  83. set MISSING_REQUIREMENTS=