From 4bbe58515fe711c1b864ab3bc944c43b5842e2d0 Mon Sep 17 00:00:00 2001 From: Aditya Gurajada Date: Fri, 3 Nov 2023 10:56:05 -0700 Subject: [PATCH] (#215) Prevent rm_non_git_files from rm'ing user's config/env-files This commit attempts to improve the behaviour of the rm_non_git_files sub-command of run_example.sh . The objective of this command is to clean-up build-outputs and other [stale] artifacts that may have been produced by a prior execution of this script. We may be, inadvertently, also deleting user's config-/env-files that reside in the project's sub-tree. This commit changes the behaviour of rm_non_git_files to now only delete the files registered in the .gitignore list. Also, now "--dry-run rm_non_git_files" will only print an info message without actually deleting all affected files. --- sample_apps/run_example.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sample_apps/run_example.sh b/sample_apps/run_example.sh index f3ed4b34..146256ea 100755 --- a/sample_apps/run_example.sh +++ b/sample_apps/run_example.sh @@ -194,7 +194,7 @@ function usage() { echo " To run an individual step of the ${SampleAppName} : ./${Me} ${SampleAppName} " echo " " # Indentation to align with previous output lines. - echo " Cleanup stale artifacts from build area : ./${Me} rm_non_git_files" + echo " Cleanup artifacts and stale outputs from build area : ./${Me} rm_non_git_files" echo " Show the environment used to build-and-run a program: ./${Me} ${SampleAppName} show_env" local test_app="simple_app_under_oe" @@ -203,7 +203,7 @@ function usage() { echo " Setup and run the simple_app_under_oe program : ./${Me} --dry-run ${test_app}" echo " Setup simple_app_under_oe program : ./${Me} --dry-run ${test_app} setup" echo " Run and test the simple_app_under_oe program : ./${Me} --dry-run ${test_app} run_test" - echo " Cleanup stale artifacts from build area : ./${Me} --dry-run rm_non_git_files" + echo " Cleanup artifacts and outputs from build area : ./${Me} --dry-run rm_non_git_files" echo " " echo "Options meant for developer usage:" echo " --no-cleanup : When errors occur, suppress executing cleanup.sh, which will kill active processes." @@ -641,10 +641,16 @@ function run_popd() { # Deep-clean the build-env to remove artifacts (e.g. generated files, binaries # etc.) that may have been produced by other steps. We run this to ensure # that this script will run successfully w/o any dependencies on executing -# some prior steps. +# some prior steps. This function will rm files that are listed in the +# .gitignore file for this project. This way we won't delete any user's +# config-/env-files saved for this project. # ########################################################################### function rm_non_git_files() { run_cmd + echo "${Me}: Delete all files not tracked by git that are also ignored." + if [ $DryRun -eq 1 ]; then + return + fi run_pushd "${CERT_PROTO}" local MbedTLS_dir_exists=0 @@ -674,12 +680,6 @@ function rm_non_git_files() { Islet_lib_exists=1 fi - echo "${Me}: Delete all files not tracked by git" - - # shellcheck disable=SC2046 - run_cmd rm -rf $(git ls-files . --exclude-standard --others) - - echo "${Me}: Delete all files not tracked by git that are also ignored" # shellcheck disable=SC2046 run_cmd rm -rf $(git ls-files . --exclude-standard --others --ignored)