1 # This script should be sourced, not executed.
3 function realpath_int() {
4 wdir="$PWD"; [ "$PWD" = "/" ] && wdir=""
7 *) scriptdir="$wdir/${0#./}";;
9 scriptdir="${scriptdir%/*}"
14 function idf_export_main() {
15 # The file doesn't have executable permissions, so this shouldn't really happen.
16 # Doing this in case someone tries to chmod +x it and execute...
17 if [[ -n "${BASH_SOURCE}" && ( "${BASH_SOURCE[0]}" == "${0}" ) ]]; then
18 echo "This script should be sourced, not executed:"
19 echo ". ${BASH_SOURCE[0]}"
23 if [[ -z "${IDF_PATH}" ]]
25 # If using bash, try to guess IDF_PATH from script location
26 if [[ -n "${BASH_SOURCE}" ]]
28 if [[ "$OSTYPE" == "darwin"* ]]; then
29 script_dir="$(realpath_int $BASH_SOURCE)"
31 script_name="$(readlink -f $BASH_SOURCE)"
32 script_dir="$(dirname $script_name)"
34 export IDF_PATH="${script_dir}"
36 echo "IDF_PATH must be set before sourcing this script"
43 echo "Adding ESP-IDF tools to PATH..."
44 # Call idf_tools.py to export tool paths
45 export IDF_TOOLS_EXPORT_CMD=${IDF_PATH}/export.sh
46 export IDF_TOOLS_INSTALL_CMD=${IDF_PATH}/install.sh
47 idf_exports=$(${IDF_PATH}/tools/idf_tools.py export) || return 1
50 echo "Checking if Python packages are up to date..."
51 python ${IDF_PATH}/tools/check_python_dependencies.py || return 1
54 # Allow calling some IDF python tools without specifying the full path
55 # ${IDF_PATH}/tools is already added by 'idf_tools.py export'
56 IDF_ADD_PATHS_EXTRAS="${IDF_PATH}/components/esptool_py/esptool"
57 IDF_ADD_PATHS_EXTRAS="${IDF_ADD_PATHS_EXTRAS}:${IDF_PATH}/components/espcoredump"
58 IDF_ADD_PATHS_EXTRAS="${IDF_ADD_PATHS_EXTRAS}:${IDF_PATH}/components/partition_table/"
59 export PATH="${IDF_ADD_PATHS_EXTRAS}:${PATH}"
63 path_prefix=${PATH%%${old_path}}
64 paths="${path_prefix//:/ }"
65 if [ -n "${paths}" ]; then
66 echo "Added the following directories to PATH:"
68 echo "All paths are already set."
70 for path_entry in ${paths}
75 echo "Updated PATH variable:"
84 unset IDF_ADD_PATHS_EXTRAS
87 # Not unsetting IDF_PYTHON_ENV_PATH, it can be used by IDF build system
88 # to check whether we are using a private Python environment
90 echo "Done! You can now compile ESP-IDF projects."
91 echo "Go to the project directory and run:"
100 unset idf_export_main