Correct export.sh failure exit code and cleanup

In failure cases, when idf_export_main() returns 1 (failure),
the export.sh script returns 0 (success). This makes it very
difficult to detect failure when writing scripts that use
export.sh. Furthermore, idf_export_main() does not clean up all
internal variables and functions in failure cases.

Move all cleanup steps into a cleanup function and pass
the return value from idf_export_main() to the cleanup
function so it can return with that same return value.

Signed-off-by: Marek Fiala <marek.fiala@espressif.com>

Closes https://github.com/espressif/esp-idf/pull/5744
This commit is contained in:
Jen Chitty 2020-08-17 12:08:32 -07:00 committed by bot
parent 8dd6d9fa5f
commit 6c564bd690

View File

@ -126,7 +126,15 @@ __main() {
__verbose " ${PATH}"
fi
# Clean up
__verbose "Done! You can now compile ESP-IDF projects."
__verbose "Go to the project directory and run:"
__verbose ""
__verbose " idf.py build"
__verbose ""
}
__cleanup() {
unset old_path
unset paths
unset path_prefix
@ -135,16 +143,19 @@ __main() {
unset idf_exports
unset ESP_PYTHON
unset __realpath
unset __main
unset __verbose
unset __enable_autocomplete
unset __cleanup
# Not unsetting IDF_PYTHON_ENV_PATH, it can be used by IDF build system
# to check whether we are using a private Python environment
__verbose "Done! You can now compile ESP-IDF projects."
__verbose "Go to the project directory and run:"
__verbose ""
__verbose " idf.py build"
__verbose ""
return $1
}
__enable_autocomplete() {
click_version="$(python -c 'import click; print(click.__version__.split(".")[0])')"
if [[ click_version -lt 8 ]]
@ -171,8 +182,4 @@ __enable_autocomplete() {
__main
__enable_autocomplete
unset __realpath
unset __main
unset __verbose
unset __enable_autocomplete
__cleanup $?