export.bat 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. :: Infer IDF_PATH from script location
  8. set IDF_PATH=%~dp0
  9. set IDF_PATH=%IDF_PATH:~0,-1%
  10. set IDF_TOOLS_PY_PATH=%IDF_PATH%\tools\idf_tools.py
  11. set IDF_TOOLS_JSON_PATH=%IDF_PATH%\tools\tools.json
  12. set IDF_TOOLS_EXPORT_CMD=%IDF_PATH%\export.bat
  13. set IDF_TOOLS_INSTALL_CMD=%IDF_PATH%\install.bat
  14. echo Setting IDF_PATH: %IDF_PATH%
  15. echo.
  16. set "OLD_PATH=%PATH%"
  17. echo Adding ESP-IDF tools to PATH...
  18. :: Export tool paths and environment variables.
  19. :: It is possible to do this without a temporary file (running idf_tools.py from for /r command),
  20. :: but that way it is impossible to get the exit code of idf_tools.py.
  21. set "IDF_TOOLS_EXPORTS_FILE=%TEMP%\idf_export_vars.tmp"
  22. python.exe %IDF_PATH%\tools\idf_tools.py export --format key-value >"%IDF_TOOLS_EXPORTS_FILE%"
  23. if %errorlevel% neq 0 goto :end
  24. for /f "usebackq tokens=1,2 eol=# delims==" %%a in ("%IDF_TOOLS_EXPORTS_FILE%") do (
  25. call set "%%a=%%b"
  26. )
  27. :: This removes OLD_PATH substring from PATH, leaving only the paths which have been added,
  28. :: and prints semicolon-delimited components of the path on separate lines
  29. call set PATH_ADDITIONS=%%PATH:%OLD_PATH%=%%
  30. if "%PATH_ADDITIONS%"=="" call :print_nothing_added
  31. if not "%PATH_ADDITIONS%"=="" echo %PATH_ADDITIONS:;=&echo. %
  32. echo Checking if Python packages are up to date...
  33. python.exe %IDF_PATH%\tools\check_python_dependencies.py
  34. if %errorlevel% neq 0 goto :end
  35. echo.
  36. echo Done! You can now compile ESP-IDF projects.
  37. echo Go to the project directory and run:
  38. echo.
  39. echo idf.py build
  40. echo.
  41. goto :end
  42. :print_nothing_added
  43. echo No directories added to PATH:
  44. echo.
  45. echo %PATH%
  46. echo.
  47. goto :eof
  48. :end
  49. :: Clean up
  50. if not "%IDF_TOOLS_EXPORTS_FILE%"=="" (
  51. del "%IDF_TOOLS_EXPORTS_FILE%" 1>nul 2>nul
  52. )
  53. set IDF_TOOLS_EXPORTS_FILE=
  54. set IDF_TOOLS_EXPORT_CMD=
  55. set IDF_TOOLS_INSTALL_CMD=
  56. set IDF_TOOLS_PY_PATH=
  57. set IDF_TOOLS_JSON_PATH=
  58. set OLD_PATH=
  59. set PATH_ADDITIONS=