mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
6f3241a34b
Explicitly set shell type in export.sh for bash and zsh -Most of the issues reported with the updated export scripts are related to shell detection. Since we already know the shell type for commonly used ones like bash or zsh, we can pass the shell type directly to the activate script. This should hopefully resolve the shell detection problems for most users. This update also modifies the shell type detection to rely solely on psutil.Process().cmdline() rather than psutil.Process().exe(). This change aims to resolve permission issues that may occur if, for example, the Python binary has certain capabilities assigned. Move shell completion to the init script - Currently we are expanding the autocompletion in the activate script and adding the expanded commands into the init script. To avoid concerns about shell versions, move the entire expansion to the init script.
57 lines
1.7 KiB
Bash
57 lines
1.7 KiB
Bash
# This script should be sourced, not executed.
|
|
|
|
# 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
|
|
|
|
# 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="."
|
|
|
|
shell_type="detect"
|
|
|
|
# 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]}")
|
|
shell_type="bash"
|
|
elif test -n "${ZSH_VERSION-}"
|
|
then
|
|
# shellcheck disable=SC2296 # ignore parameter starts with '{' because it's zsh
|
|
idf_path=$(dirname "${(%):-%x}")
|
|
shell_type="zsh"
|
|
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" ] ||
|
|
[ ! -f "${idf_path}/tools/activate.py" ]
|
|
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.
|
|
idf_exports=$("$ESP_PYTHON" "${idf_path}/tools/activate.py" --export --shell $shell_type)
|
|
eval "${idf_exports}"
|
|
unset idf_path
|
|
return 0
|