export.bat 3.2 KB

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