tools: Switching between ESP-IDF versions

Support switching between ESP-IDF versions on UNIX systems.
This commit is contained in:
Marek Fiala
2021-11-08 17:55:03 +01:00
parent b02ac9cab9
commit df16a45d7a
5 changed files with 267 additions and 102 deletions

View File

@@ -17,6 +17,25 @@ __verbose() {
echo "$@"
}
__script_dir(){
# shellcheck disable=SC2169,SC2169,SC2039 # unreachable with 'dash'
if [[ "$OSTYPE" == "darwin"* ]]; then
# convert possibly relative path to absolute
script_dir="$(__realpath "${self_path}")"
# resolve any ../ references to make the path shorter
script_dir="$(cd "${script_dir}" || exit 1; pwd)"
else
# convert to full path and get the directory name of that
script_name="$(readlink -f "${self_path}")"
script_dir="$(dirname "${script_name}")"
fi
if [ "$script_dir" = '.' ]
then
script_dir="$(pwd)"
fi
echo "$script_dir"
}
__main() {
# The file doesn't have executable permissions, so this shouldn't really happen.
# Doing this in case someone tries to chmod +x it and execute...
@@ -49,21 +68,17 @@ __main() {
return 1
fi
# shellcheck disable=SC2169,SC2169,SC2039 # unreachable with 'dash'
if [[ "$OSTYPE" == "darwin"* ]]; then
# convert possibly relative path to absolute
script_dir="$(__realpath "${self_path}")"
# resolve any ../ references to make the path shorter
script_dir="$(cd "${script_dir}" || exit 1; pwd)"
else
# convert to full path and get the directory name of that
script_name="$(readlink -f "${self_path}")"
script_dir="$(dirname "${script_name}")"
fi
script_dir=$(__script_dir)
export IDF_PATH="${script_dir}"
echo "Setting IDF_PATH to '${IDF_PATH}'"
else
# IDF_PATH came from the environment, check if the path is valid
script_dir=$(__script_dir)
if [ ! "${IDF_PATH}" = "${script_dir}" ]
then
echo "Resetting IDF_PATH from '${IDF_PATH}' to '${script_dir}' "
export IDF_PATH="${script_dir}"
fi
if [ ! -d "${IDF_PATH}" ]
then
echo "IDF_PATH is set to '${IDF_PATH}', but it is not a valid directory."
@@ -90,26 +105,29 @@ __main() {
echo "Checking Python compatibility"
"$ESP_PYTHON" "${IDF_PATH}/tools/python_version_checker.py"
__verbose "Checking other ESP-IDF version."
idf_unset=$("$ESP_PYTHON" "${IDF_PATH}/tools/idf_tools.py" export --unset) || return 1
eval "${idf_unset}"
__verbose "Adding ESP-IDF tools to PATH..."
# Call idf_tools.py to export tool paths
export IDF_TOOLS_EXPORT_CMD=${IDF_PATH}/export.sh
export IDF_TOOLS_INSTALL_CMD=${IDF_PATH}/install.sh
idf_exports=$("$ESP_PYTHON" "${IDF_PATH}/tools/idf_tools.py" export) || return 1
eval "${idf_exports}"
__verbose "Using Python interpreter in $(which python)"
__verbose "Checking if Python packages are up to date..."
python "${IDF_PATH}/tools/idf_tools.py" check-python-dependencies || return 1
# Allow calling some IDF python tools without specifying the full path
# ${IDF_PATH}/tools is already added by 'idf_tools.py export'
IDF_ADD_PATHS_EXTRAS="${IDF_PATH}/components/esptool_py/esptool"
IDF_ADD_PATHS_EXTRAS="${IDF_ADD_PATHS_EXTRAS}:${IDF_PATH}/components/espcoredump"
IDF_ADD_PATHS_EXTRAS="${IDF_ADD_PATHS_EXTRAS}:${IDF_PATH}/components/partition_table"
IDF_ADD_PATHS_EXTRAS="${IDF_ADD_PATHS_EXTRAS}:${IDF_PATH}/components/app_update"
idf_exports=$("$ESP_PYTHON" "${IDF_PATH}/tools/idf_tools.py" export --add_paths_extras=${IDF_ADD_PATHS_EXTRAS}) || return 1
eval "${idf_exports}"
export PATH="${IDF_ADD_PATHS_EXTRAS}:${PATH}"
__verbose "Using Python interpreter in $(which python)"
__verbose "Checking if Python packages are up to date..."
python "${IDF_PATH}/tools/idf_tools.py" check-python-dependencies || return 1
if [ -n "$BASH" ]
then
path_prefix=${PATH%%${old_path}}
@@ -156,6 +174,7 @@ __cleanup() {
unset path_entry
unset IDF_ADD_PATHS_EXTRAS
unset idf_exports
unset idf_unset
unset ESP_PYTHON
unset SOURCE_ZSH
unset SOURCE_BASH