export.bat 3.8 KB

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