From 6c564bd6903ec233106454c9faf4db5dd2074018 Mon Sep 17 00:00:00 2001 From: Jen Chitty Date: Mon, 17 Aug 2020 12:08:32 -0700 Subject: [PATCH] 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 Closes https://github.com/espressif/esp-idf/pull/5744 --- export.sh | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/export.sh b/export.sh index 7fd6e09159..3dfdc66997 100644 --- a/export.sh +++ b/export.sh @@ -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 $?