2019-04-28 22:37:02 -04:00
|
|
|
# This script should be sourced, not executed.
|
|
|
|
|
2024-08-21 10:34:19 -04:00
|
|
|
# Emergency backup option to use previous export.sh (export_legacy.sh) if the new export approach fails.
|
|
|
|
# To use it, set environmental variable like: export ESP_IDF_LEGACY_EXPORT=1
|
|
|
|
if [ -n "${ESP_IDF_LEGACY_EXPORT-}" ]; then
|
|
|
|
. ./tools/legacy_exports/export_legacy.sh
|
|
|
|
return $?
|
|
|
|
fi
|
|
|
|
|
2023-11-08 10:56:19 -05:00
|
|
|
# shellcheck disable=SC2128,SC2169,SC2039,SC3054 # ignore array expansion warning
|
|
|
|
if [ -n "${BASH_SOURCE-}" ] && [ "${BASH_SOURCE[0]}" = "${0}" ]
|
|
|
|
then
|
|
|
|
echo "This script should be sourced, not executed:"
|
|
|
|
# shellcheck disable=SC2039,SC3054 # reachable only with bash
|
|
|
|
echo ". ${BASH_SOURCE[0]}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Attempt to identify the ESP-IDF directory
|
|
|
|
idf_path="."
|
|
|
|
|
2024-09-16 10:16:38 -04:00
|
|
|
shell_type="detect"
|
|
|
|
|
2023-11-08 10:56:19 -05:00
|
|
|
# shellcheck disable=SC2128,SC2169,SC2039,SC3054,SC3028 # ignore array expansion warning
|
|
|
|
if test -n "${BASH_SOURCE-}"
|
|
|
|
then
|
|
|
|
# shellcheck disable=SC3028,SC3054 # unreachable with 'dash'
|
|
|
|
idf_path=$(dirname "${BASH_SOURCE[0]}")
|
2024-09-16 10:16:38 -04:00
|
|
|
shell_type="bash"
|
2023-11-08 10:56:19 -05:00
|
|
|
elif test -n "${ZSH_VERSION-}"
|
|
|
|
then
|
2023-09-05 05:09:52 -04:00
|
|
|
# shellcheck disable=SC2296 # ignore parameter starts with '{' because it's zsh
|
2023-11-08 10:56:19 -05:00
|
|
|
idf_path=$(dirname "${(%):-%x}")
|
2024-09-16 10:16:38 -04:00
|
|
|
shell_type="zsh"
|
2023-11-08 10:56:19 -05:00
|
|
|
elif test -n "${IDF_PATH-}"
|
|
|
|
then
|
|
|
|
idf_path=$IDF_PATH
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f "${idf_path}/tools/idf.py" ] ||
|
|
|
|
[ ! -f "${idf_path}/tools/idf_tools.py" ] ||
|
2024-06-21 11:13:18 -04:00
|
|
|
[ ! -f "${idf_path}/tools/activate.py" ]
|
2023-11-08 10:56:19 -05:00
|
|
|
then
|
|
|
|
echo "Could not detect IDF_PATH. Please set it before sourcing this script:"
|
|
|
|
echo " export IDF_PATH=(add path here)"
|
|
|
|
unset idf_path
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
. "${idf_path}/tools/detect_python.sh"
|
|
|
|
|
|
|
|
# Evaluate the ESP-IDF environment set up by the activate.py script.
|
2024-09-16 10:16:38 -04:00
|
|
|
idf_exports=$("$ESP_PYTHON" "${idf_path}/tools/activate.py" --export --shell $shell_type)
|
2023-11-08 10:56:19 -05:00
|
|
|
eval "${idf_exports}"
|
|
|
|
unset idf_path
|
|
|
|
return 0
|