export.bat 3.2 KB

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