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