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