export.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # This script should be sourced, not executed.
  2. function idf_export_main() {
  3. # The file doesn't have executable permissions, so this shouldn't really happen.
  4. # Doing this in case someone tries to chmod +x it and execute...
  5. if [[ -n "${BASH_SOURCE}" && ( "${BASH_SOURCE[0]}" == "${0}" ) ]]; then
  6. echo "This script should be sourced, not executed:"
  7. echo ". ${BASH_SOURCE[0]}"
  8. return 1
  9. fi
  10. if [[ -z "${IDF_PATH}" ]]
  11. then
  12. # If using bash, try to guess IDF_PATH from script location
  13. if [[ -n "${BASH_SOURCE}" ]]
  14. then
  15. script_name="$(readlink -f $BASH_SOURCE)"
  16. export IDF_PATH="$(dirname ${script_name})"
  17. else
  18. echo "IDF_PATH must be set before sourcing this script"
  19. return 1
  20. fi
  21. fi
  22. old_path=$PATH
  23. echo "Adding ESP-IDF tools to PATH..."
  24. # Call idf_tools.py to export tool paths
  25. export IDF_TOOLS_EXPORT_CMD=${IDF_PATH}/export.sh
  26. export IDF_TOOLS_INSTALL_CMD=${IDF_PATH}/install.sh
  27. idf_exports=$(${IDF_PATH}/tools/idf_tools.py export) || return 1
  28. eval "${idf_exports}"
  29. echo "Checking if Python packages are up to date..."
  30. python ${IDF_PATH}/tools/check_python_dependencies.py || return 1
  31. # Allow calling some IDF python tools without specifying the full path
  32. # ${IDF_PATH}/tools is already added by 'idf_tools.py export'
  33. IDF_ADD_PATHS_EXTRAS="${IDF_PATH}/components/esptool_py/esptool"
  34. IDF_ADD_PATHS_EXTRAS="${IDF_ADD_PATHS_EXTRAS}:${IDF_PATH}/components/espcoredump"
  35. IDF_ADD_PATHS_EXTRAS="${IDF_ADD_PATHS_EXTRAS}:${IDF_PATH}/components/partition_table/"
  36. export PATH="${IDF_ADD_PATHS_EXTRAS}:${PATH}"
  37. if [[ -n "$BASH" ]]
  38. then
  39. path_prefix=${PATH%%${old_path}}
  40. paths="${path_prefix//:/ }"
  41. if [ -n "${paths}" ]; then
  42. echo "Added the following directories to PATH:"
  43. else
  44. echo "All paths are already set."
  45. fi
  46. for path_entry in ${paths}
  47. do
  48. echo " ${path_entry}"
  49. done
  50. else
  51. echo "Updated PATH variable:"
  52. echo " ${PATH}"
  53. fi
  54. # Clean up
  55. unset old_path
  56. unset paths
  57. unset path_prefix
  58. unset path_entry
  59. unset IDF_ADD_PATHS_EXTRAS
  60. unset idf_exports
  61. # Not unsetting IDF_PYTHON_ENV_PATH, it can be used by IDF build system
  62. # to check whether we are using a private Python environment
  63. echo "Done! You can now compile ESP-IDF projects."
  64. echo "Go to the project directory and run:"
  65. echo ""
  66. echo " idf.py build"
  67. echo ""
  68. }
  69. idf_export_main
  70. unset idf_export_main