Merge branch 'bugfix/export_path_checks_v4.1' into 'release/v4.1'
tools: export.sh: better detection and checking of IDF_PATH (backport v4.1) See merge request espressif/esp-idf!8747
This commit is contained in:
commit
c735e7edf5
1 changed files with 57 additions and 18 deletions
75
export.sh
75
export.sh
|
@ -1,6 +1,6 @@
|
||||||
# This script should be sourced, not executed.
|
# This script should be sourced, not executed.
|
||||||
|
|
||||||
function realpath_int() {
|
realpath_int() {
|
||||||
wdir="$PWD"; [ "$PWD" = "/" ] && wdir=""
|
wdir="$PWD"; [ "$PWD" = "/" ] && wdir=""
|
||||||
arg=$1
|
arg=$1
|
||||||
case "$arg" in
|
case "$arg" in
|
||||||
|
@ -12,44 +12,82 @@ function realpath_int() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function idf_export_main() {
|
idf_export_main() {
|
||||||
# The file doesn't have executable permissions, so this shouldn't really happen.
|
# 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...
|
# Doing this in case someone tries to chmod +x it and execute...
|
||||||
if [[ -n "${BASH_SOURCE}" && ( "${BASH_SOURCE[0]}" == "${0}" ) ]]; then
|
|
||||||
|
# shellcheck disable=SC2128,SC2169,SC2039 # ignore array expansion warning
|
||||||
|
if [ -n "${BASH_SOURCE}" ] && [ "${BASH_SOURCE[0]}" = "${0}" ]
|
||||||
|
then
|
||||||
echo "This script should be sourced, not executed:"
|
echo "This script should be sourced, not executed:"
|
||||||
|
# shellcheck disable=SC2039 # reachable only with bash
|
||||||
echo ". ${BASH_SOURCE[0]}"
|
echo ". ${BASH_SOURCE[0]}"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z "${IDF_PATH}" ]]
|
if [ -z "${IDF_PATH}" ]
|
||||||
then
|
then
|
||||||
# If using bash, try to guess IDF_PATH from script location
|
# IDF_PATH not set in the environment.
|
||||||
if [[ -n "${BASH_SOURCE}" ]]
|
# If using bash or zsh, try to guess IDF_PATH from script location.
|
||||||
|
self_path=""
|
||||||
|
|
||||||
|
# shellcheck disable=SC2128 # ignore array expansion warning
|
||||||
|
if [ -n "${BASH_SOURCE}" ]
|
||||||
then
|
then
|
||||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
self_path="${BASH_SOURCE}"
|
||||||
script_dir="$(realpath_int $BASH_SOURCE)"
|
elif [ -n "${ZSH_VERSION}" ]
|
||||||
|
then
|
||||||
|
self_path="${(%):-%x}"
|
||||||
else
|
else
|
||||||
script_name="$(readlink -f $BASH_SOURCE)"
|
echo "Could not detect IDF_PATH. Please set it before sourcing this script:"
|
||||||
script_dir="$(dirname $script_name)"
|
echo " export IDF_PATH=(add path here)"
|
||||||
fi
|
|
||||||
export IDF_PATH="${script_dir}"
|
|
||||||
else
|
|
||||||
echo "IDF_PATH must be set before sourcing this script"
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# shellcheck disable=SC2169,SC2169,SC2039 # unreachable with 'dash'
|
||||||
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
|
# convert possibly relative path to absolute
|
||||||
|
script_dir="$(realpath_int "${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
|
||||||
|
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
|
||||||
|
if [ ! -d "${IDF_PATH}" ]
|
||||||
|
then
|
||||||
|
echo "IDF_PATH is set to '${IDF_PATH}', but it is not a valid directory."
|
||||||
|
echo "If you have set IDF_PATH manually, check if the path is correct."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
# Check if this path looks like an IDF directory
|
||||||
|
if [ ! -f "${IDF_PATH}/tools/idf.py" ] || [ ! -f "${IDF_PATH}/tools/idf_tools.py" ]
|
||||||
|
then
|
||||||
|
echo "IDF_PATH is set to '${IDF_PATH}', but it doesn't look like an ESP-IDF directory."
|
||||||
|
echo "If you have set IDF_PATH manually, check if the path is correct."
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
old_path=$PATH
|
# The varible might have been set (rather than exported), re-export it to be sure
|
||||||
|
export IDF_PATH="${IDF_PATH}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
old_path="$PATH"
|
||||||
|
|
||||||
echo "Adding ESP-IDF tools to PATH..."
|
echo "Adding ESP-IDF tools to PATH..."
|
||||||
# Call idf_tools.py to export tool paths
|
# Call idf_tools.py to export tool paths
|
||||||
export IDF_TOOLS_EXPORT_CMD=${IDF_PATH}/export.sh
|
export IDF_TOOLS_EXPORT_CMD=${IDF_PATH}/export.sh
|
||||||
export IDF_TOOLS_INSTALL_CMD=${IDF_PATH}/install.sh
|
export IDF_TOOLS_INSTALL_CMD=${IDF_PATH}/install.sh
|
||||||
idf_exports=$(${IDF_PATH}/tools/idf_tools.py export) || return 1
|
idf_exports=$("${IDF_PATH}/tools/idf_tools.py" export) || return 1
|
||||||
eval "${idf_exports}"
|
eval "${idf_exports}"
|
||||||
|
|
||||||
echo "Checking if Python packages are up to date..."
|
echo "Checking if Python packages are up to date..."
|
||||||
python ${IDF_PATH}/tools/check_python_dependencies.py || return 1
|
python "${IDF_PATH}/tools/check_python_dependencies.py" || return 1
|
||||||
|
|
||||||
|
|
||||||
# Allow calling some IDF python tools without specifying the full path
|
# Allow calling some IDF python tools without specifying the full path
|
||||||
|
@ -59,9 +97,10 @@ function idf_export_main() {
|
||||||
IDF_ADD_PATHS_EXTRAS="${IDF_ADD_PATHS_EXTRAS}:${IDF_PATH}/components/partition_table/"
|
IDF_ADD_PATHS_EXTRAS="${IDF_ADD_PATHS_EXTRAS}:${IDF_PATH}/components/partition_table/"
|
||||||
export PATH="${IDF_ADD_PATHS_EXTRAS}:${PATH}"
|
export PATH="${IDF_ADD_PATHS_EXTRAS}:${PATH}"
|
||||||
|
|
||||||
if [[ -n "$BASH" ]]
|
if [ -n "$BASH" ]
|
||||||
then
|
then
|
||||||
path_prefix=${PATH%%${old_path}}
|
path_prefix=${PATH%%${old_path}}
|
||||||
|
# shellcheck disable=SC2169,SC2039 # unreachable with 'dash'
|
||||||
paths="${path_prefix//:/ }"
|
paths="${path_prefix//:/ }"
|
||||||
if [ -n "${paths}" ]; then
|
if [ -n "${paths}" ]; then
|
||||||
echo "Added the following directories to PATH:"
|
echo "Added the following directories to PATH:"
|
||||||
|
|
Loading…
Reference in a new issue