2019-04-29 02:37:02 +00:00
|
|
|
# This script should be sourced, not executed.
|
|
|
|
|
2020-06-08 17:14:48 +00:00
|
|
|
realpath_int() {
|
2019-07-16 13:38:40 +00:00
|
|
|
wdir="$PWD"; [ "$PWD" = "/" ] && wdir=""
|
2019-07-28 08:04:36 +00:00
|
|
|
arg=$1
|
|
|
|
case "$arg" in
|
|
|
|
/*) scriptdir="${arg}";;
|
|
|
|
*) scriptdir="$wdir/${arg#./}";;
|
2019-07-16 13:38:40 +00:00
|
|
|
esac
|
|
|
|
scriptdir="${scriptdir%/*}"
|
|
|
|
echo "$scriptdir"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-08 17:14:48 +00:00
|
|
|
idf_export_main() {
|
2019-04-29 02:37:02 +00:00
|
|
|
# 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...
|
2020-06-08 17:14:48 +00:00
|
|
|
|
|
|
|
# shellcheck disable=SC2128,SC2169,SC2039 # ignore array expansion warning
|
|
|
|
if [ -n "${BASH_SOURCE}" ] && [ "${BASH_SOURCE[0]}" = "${0}" ]
|
|
|
|
then
|
2019-04-29 02:37:02 +00:00
|
|
|
echo "This script should be sourced, not executed:"
|
2020-06-08 17:14:48 +00:00
|
|
|
# shellcheck disable=SC2039 # reachable only with bash
|
2019-04-29 02:37:02 +00:00
|
|
|
echo ". ${BASH_SOURCE[0]}"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2020-06-08 17:14:48 +00:00
|
|
|
if [ -z "${IDF_PATH}" ]
|
2019-04-29 02:37:02 +00:00
|
|
|
then
|
2020-04-02 17:05:58 +00:00
|
|
|
# IDF_PATH not set in the environment.
|
|
|
|
# If using bash or zsh, try to guess IDF_PATH from script location.
|
|
|
|
self_path=""
|
2020-06-08 17:14:48 +00:00
|
|
|
|
|
|
|
# shellcheck disable=SC2128 # ignore array expansion warning
|
|
|
|
if [ -n "${BASH_SOURCE}" ]
|
2019-04-29 02:37:02 +00:00
|
|
|
then
|
2020-04-02 17:05:58 +00:00
|
|
|
self_path="${BASH_SOURCE}"
|
2020-06-08 17:14:48 +00:00
|
|
|
elif [ -n "${ZSH_VERSION}" ]
|
2020-04-02 17:05:58 +00:00
|
|
|
then
|
|
|
|
self_path="${(%):-%x}"
|
2019-04-29 02:37:02 +00:00
|
|
|
else
|
2020-04-02 17:05:58 +00:00
|
|
|
echo "Could not detect IDF_PATH. Please set it before sourcing this script:"
|
|
|
|
echo " export IDF_PATH=(add path here)"
|
2019-04-29 02:37:02 +00:00
|
|
|
return 1
|
|
|
|
fi
|
2020-04-02 17:05:58 +00:00
|
|
|
|
2020-06-08 17:14:48 +00:00
|
|
|
# shellcheck disable=SC2169,SC2169,SC2039 # unreachable with 'dash'
|
2020-04-02 17:05:58 +00:00
|
|
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
|
|
# convert possibly relative path to absolute
|
2020-06-08 17:14:48 +00:00
|
|
|
script_dir="$(realpath_int "${self_path}")"
|
2020-04-02 17:05:58 +00:00
|
|
|
# resolve any ../ references to make the path shorter
|
2020-06-08 17:14:48 +00:00
|
|
|
script_dir="$(cd "${script_dir}" || exit 1; pwd)"
|
2020-04-02 17:05:58 +00:00
|
|
|
else
|
|
|
|
# convert to full path and get the directory name of that
|
2020-06-08 17:14:48 +00:00
|
|
|
script_name="$(readlink -f "${self_path}")"
|
|
|
|
script_dir="$(dirname "${script_name}")"
|
2020-04-02 17:05:58 +00:00
|
|
|
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
|
2020-06-08 17:14:48 +00:00
|
|
|
if [ ! -d "${IDF_PATH}" ]
|
2020-04-02 17:05:58 +00:00
|
|
|
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
|
2020-06-08 17:14:48 +00:00
|
|
|
if [ ! -f "${IDF_PATH}/tools/idf.py" ] || [ ! -f "${IDF_PATH}/tools/idf_tools.py" ]
|
2020-04-02 17:05:58 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
# The varible might have been set (rather than exported), re-export it to be sure
|
|
|
|
export IDF_PATH="${IDF_PATH}"
|
2019-04-29 02:37:02 +00:00
|
|
|
fi
|
|
|
|
|
2020-04-02 17:05:58 +00:00
|
|
|
old_path="$PATH"
|
2019-04-29 02:37:02 +00:00
|
|
|
|
|
|
|
echo "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
|
2020-06-08 17:14:48 +00:00
|
|
|
idf_exports=$("${IDF_PATH}/tools/idf_tools.py" export) || return 1
|
2019-04-29 02:37:02 +00:00
|
|
|
eval "${idf_exports}"
|
|
|
|
|
|
|
|
echo "Checking if Python packages are up to date..."
|
2020-06-08 17:14:48 +00:00
|
|
|
python "${IDF_PATH}/tools/check_python_dependencies.py" || return 1
|
2019-04-29 02:37:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
# 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/"
|
|
|
|
export PATH="${IDF_ADD_PATHS_EXTRAS}:${PATH}"
|
|
|
|
|
2020-06-08 17:14:48 +00:00
|
|
|
if [ -n "$BASH" ]
|
2019-04-29 02:37:02 +00:00
|
|
|
then
|
|
|
|
path_prefix=${PATH%%${old_path}}
|
2020-06-08 17:14:48 +00:00
|
|
|
# shellcheck disable=SC2169,SC2039 # unreachable with 'dash'
|
2019-04-29 02:37:02 +00:00
|
|
|
paths="${path_prefix//:/ }"
|
|
|
|
if [ -n "${paths}" ]; then
|
|
|
|
echo "Added the following directories to PATH:"
|
|
|
|
else
|
|
|
|
echo "All paths are already set."
|
|
|
|
fi
|
|
|
|
for path_entry in ${paths}
|
|
|
|
do
|
|
|
|
echo " ${path_entry}"
|
|
|
|
done
|
|
|
|
else
|
|
|
|
echo "Updated PATH variable:"
|
|
|
|
echo " ${PATH}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Clean up
|
|
|
|
unset old_path
|
|
|
|
unset paths
|
|
|
|
unset path_prefix
|
|
|
|
unset path_entry
|
|
|
|
unset IDF_ADD_PATHS_EXTRAS
|
|
|
|
unset idf_exports
|
2019-07-16 13:38:40 +00:00
|
|
|
|
2019-04-29 02:37:02 +00:00
|
|
|
# Not unsetting IDF_PYTHON_ENV_PATH, it can be used by IDF build system
|
|
|
|
# to check whether we are using a private Python environment
|
|
|
|
|
|
|
|
echo "Done! You can now compile ESP-IDF projects."
|
|
|
|
echo "Go to the project directory and run:"
|
|
|
|
echo ""
|
|
|
|
echo " idf.py build"
|
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
|
|
|
|
idf_export_main
|
|
|
|
|
2019-07-16 13:38:40 +00:00
|
|
|
unset realpath_int
|
2019-04-29 02:37:02 +00:00
|
|
|
unset idf_export_main
|