]> granicus.if.org Git - esp-idf/blob - export.sh
Merge branch 'bugfix/ws_client_fix_static_analysis_warnings' into 'master'
[esp-idf] / export.sh
1 # This script should be sourced, not executed.
2
3 function realpath_int() {
4     wdir="$PWD"; [ "$PWD" = "/" ] && wdir=""
5     arg=$1
6     case "$arg" in
7         /*) scriptdir="${arg}";;
8         *) scriptdir="$wdir/${arg#./}";;
9     esac
10     scriptdir="${scriptdir%/*}"
11     echo "$scriptdir"
12 }
13
14
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]}"
21         return 1
22     fi
23
24     if [[ -z "${IDF_PATH}" ]]
25     then
26         # If using bash, try to guess IDF_PATH from script location
27         if [[ -n "${BASH_SOURCE}" ]]
28         then
29             if [[ "$OSTYPE" == "darwin"* ]]; then
30                 script_dir="$(realpath_int $BASH_SOURCE)"
31             else
32                 script_name="$(readlink -f $BASH_SOURCE)"
33                 script_dir="$(dirname $script_name)"
34             fi
35             export IDF_PATH="${script_dir}"
36         else
37             echo "IDF_PATH must be set before sourcing this script"
38             return 1
39         fi
40     fi
41
42     old_path=$PATH
43
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
49     eval "${idf_exports}"
50
51     echo "Checking if Python packages are up to date..."
52     python ${IDF_PATH}/tools/check_python_dependencies.py || return 1
53
54
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}"
61
62     if [[ -n "$BASH" ]]
63     then
64         path_prefix=${PATH%%${old_path}}
65         paths="${path_prefix//:/ }"
66         if [ -n "${paths}" ]; then
67             echo "Added the following directories to PATH:"
68         else
69             echo "All paths are already set."
70         fi
71         for path_entry in ${paths}
72         do
73             echo "  ${path_entry}"
74         done
75     else
76         echo "Updated PATH variable:"
77         echo "  ${PATH}"
78     fi
79
80     # Clean up
81     unset old_path
82     unset paths
83     unset path_prefix
84     unset path_entry
85     unset IDF_ADD_PATHS_EXTRAS
86     unset idf_exports
87
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
90
91     echo "Done! You can now compile ESP-IDF projects."
92     echo "Go to the project directory and run:"
93     echo ""
94     echo "  idf.py build"
95     echo ""
96 }
97
98 idf_export_main
99
100 unset realpath_int
101 unset idf_export_main