Commit 65a5762c authored by Charles Ferguson's avatar Charles Ferguson
Browse files

Initial implementation of 'clean' action.

The clean action will clear up the project so that there are no files
left behind which should be removed from the environment. At present
we only have the CI specific files being removed, but the framework
for the other languages to be cleaned is also present (unused).
parent 748146e1
...@@ -174,6 +174,20 @@ function tool_config_expansion() { ...@@ -174,6 +174,20 @@ function tool_config_expansion() {
return 0 return 0
} }
##
# Delete an entire directory tree, as safely as possible.
#
# @param $@ Directories to remove.
function rmtree() {
local dirs="$@"
if [[ "$(uname -s)" == 'Darwin' ]] ; then
# On OSX, '--one-file-system' does not exist.
rm -rf "${dirs[@]}"
else
rm -rf --one-file-system "${dirs[@]}"
fi
}
## ##
# Check if a named function exists # Check if a named function exists
# #
...@@ -313,6 +327,10 @@ function all_setup_docs() { ...@@ -313,6 +327,10 @@ function all_setup_docs() {
docs_total=0 docs_total=0
} }
function all_setup_clean() {
echo '>>> Cleaning code'
}
## ##
# Merge all the test result files into a single file, # Merge all the test result files into a single file,
...@@ -343,10 +361,31 @@ function merge_test_results() { ...@@ -343,10 +361,31 @@ function merge_test_results() {
fi fi
} }
function all_run_clean() {
rmtree "${artifact_dir:-ARTIFACT_DIR_UNSET}"
}
function all_end_test() {
function all_process_tests() {
merge_test_results merge_test_results
}
function all_process_coverage() {
# If the file writing fails, it isn't fatal
merge_test_results || true
}
function all_process_clean() {
# Cleaning the log and artifact directory must come last so that
# if the language needs to do something, it can use the existing
# environment (if it needs to), and write logs (although they
# would be cleared away).
rmtree "${log_dir:-LOG_DIR_UNSET}"
rmtree "${environment_dir:-ENVIRONMENT_DIR_UNSET}"
}
function all_end_test() {
if [[ "$tests_failed" != "0" ]] ; then if [[ "$tests_failed" != "0" ]] ; then
echo "<<< Tests FAILED ($tests_failed test files failed, $tests_passed test files passed)" echo "<<< Tests FAILED ($tests_failed test files failed, $tests_passed test files passed)"
exit 1 exit 1
...@@ -357,9 +396,6 @@ function all_end_test() { ...@@ -357,9 +396,6 @@ function all_end_test() {
} }
function all_end_coverage() { function all_end_coverage() {
# If the file writing fails, it isn't fatal
( merge_test_results || true )
echo "Overall Coverage: ${coverage_percentage}% (limit is ${coverage_limit}%)" echo "Overall Coverage: ${coverage_percentage}% (limit is ${coverage_limit}%)"
if [[ "${coverage_percentage}" != '<unknown>' && \ if [[ "${coverage_percentage}" != '<unknown>' && \
"${coverage_percentage%.*}" -lt "${coverage_limit}" ]] ; then "${coverage_percentage%.*}" -lt "${coverage_limit}" ]] ; then
...@@ -391,6 +427,11 @@ function all_end_docs() { ...@@ -391,6 +427,11 @@ function all_end_docs() {
exit 0 exit 0
} }
function all_end_clean() {
echo '<<< Cleaned'
exit 0
}
## ##
# Provide help messages. # Provide help messages.
...@@ -562,15 +603,12 @@ function run_action() { ...@@ -562,15 +603,12 @@ function run_action() {
# Ensure the directories we'll use are present and (where necessary) # Ensure the directories we'll use are present and (where necessary)
# cleaned. # cleaned.
if [[ "$(uname -s)" == 'Darwin' ]] ; then rmtree "${artifact_dir:-ARTIFACT_DIR_UNSET}" "${log_dir:-LOG_DIR_UNSET}"
# On OSX, '--one-file-system' does not exist.
rm -rf "${artifact_dir:-ARTIFACT_DIR_UNSET}" "${log_dir:-LOG_DIR_UNSET}"
else
rm -rf --one-file-system "${artifact_dir:-ARTIFACT_DIR_UNSET}" "${log_dir:-LOG_DIR_UNSET}"
fi
mkdir -p "${environment_dir}" "${artifact_dir}" "${log_dir}" mkdir -p "${environment_dir}" "${artifact_dir}" "${log_dir}"
"all_setup_${action}" "all_setup_${action}"
call_if_function "all_run_${action}"
for lang in $languages ; do for lang in $languages ; do
if active "$lang" "$action" ; then if active "$lang" "$action" ; then
...@@ -591,6 +629,7 @@ function run_action() { ...@@ -591,6 +629,7 @@ function run_action() {
call_if_function "${lang}_process_${action}" call_if_function "${lang}_process_${action}"
fi fi
done done
call_if_function "all_process_${action}"
# Remove any directories we did not use # Remove any directories we did not use
for dir in "${environment_dir}" "${artifact_dir}" "${log_dir}" ; do for dir in "${environment_dir}" "${artifact_dir}" "${log_dir}" ; do
...@@ -611,7 +650,7 @@ for file in $(expand_filenames "${scripts}"'/common.*') ; do ...@@ -611,7 +650,7 @@ for file in $(expand_filenames "${scripts}"'/common.*') ; do
source "${scripts}/common.${file##*.}" source "${scripts}/common.${file##*.}"
done done
actions="test coverage lint docs" actions="test coverage lint docs clean"
# General configuration for all tools. # General configuration for all tools.
config_file="${root}/project.config" config_file="${root}/project.config"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment