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