From 898a96e908027cdcbb541465ed15d134bc6efc31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Fri, 15 Nov 2019 18:35:06 +0100 Subject: [PATCH 01/22] CI: run unit tests before integration tests --- maintainer/CI/build_cmake.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/maintainer/CI/build_cmake.sh b/maintainer/CI/build_cmake.sh index eb4da004345..5c6f4d4abf5 100755 --- a/maintainer/CI/build_cmake.sh +++ b/maintainer/CI/build_cmake.sh @@ -251,8 +251,9 @@ fi if [ ${run_checks} = true ]; then start "TEST" - # integration and unit tests + # unit tests and integration tests if [ ${make_check} = true ]; then + make -j${build_procs} check_unit_tests ${make_params} || exit 1 if [ -z "${run_tests}" ]; then if [ ${check_odd_only} = true ]; then make -j${build_procs} check_python_parallel_odd ${make_params} || exit 1 @@ -269,7 +270,6 @@ if [ ${run_checks} = true ]; then ctest --timeout 60 --output-on-failure -R ${t} || exit 1 done fi - make -j${build_procs} check_unit_tests ${make_params} || exit 1 fi # tutorial tests From bcbdfb620276f7f29d58aaab953f8708720160ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Fri, 15 Nov 2019 19:03:31 +0100 Subject: [PATCH 02/22] Use || instead of -o POSIX does not specify test for > 4 arguments: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html shellcheck rule: SC2166 --- maintainer/CI/build_cmake.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/maintainer/CI/build_cmake.sh b/maintainer/CI/build_cmake.sh index 5c6f4d4abf5..478bc0ecfc3 100755 --- a/maintainer/CI/build_cmake.sh +++ b/maintainer/CI/build_cmake.sh @@ -55,12 +55,12 @@ function set_default_value { exit 1 fi local -r value="${!varname}" - if [ "${default}" = true -o "${default}" = false ]; then + if [ "${default}" = true ] || [ "${default}" = false ]; then # cast boolean values to true/false local -r val=$(echo "${value}" | tr '[:upper:]' '[:lower:]') - if [ "${val}" = false -o "${val}" = "off" -o "${val}" = 0 -o "${val}" = "no" ]; then + if [ "${val}" = false ] || [ "${val}" = "off" ] || [ "${val}" = 0 ] || [ "${val}" = "no" ]; then eval "${varname}=false" - elif [ "${val}" = true -o "${val}" = "on" -o "${val}" = 1 -o "${val}" = "yes" ]; then + elif [ "${val}" = true ] || [ "${val}" = "on" ] || [ "${val}" = 1 ] || [ "${val}" = "yes" ]; then eval "${varname}=true" elif [ -z "${val}" ]; then eval "${varname}='${default}'" @@ -101,7 +101,7 @@ set_default_value with_scafacos true set_default_value test_timeout 300 set_default_value hide_gpu false -if [ ${make_check} = true -o ${make_check_tutorials} = true -o ${make_check_samples} = true -o ${make_check_benchmarks} = true ]; then +if [ ${make_check} = true ] || [ ${make_check_tutorials} = true ] || [ ${make_check_samples} = true ] || [ ${make_check_benchmarks} = true ]; then run_checks=true else run_checks=false @@ -241,7 +241,7 @@ end "BUILD" # check for exit function, which should never be called from shared library # can't do this on CUDA though because nvcc creates a host function that just calls exit for each device function -if [ ${with_cuda} = false -o "$(echo ${NVCC} | grep -o clang)" = "clang" ]; then +if [ ${with_cuda} = false ] || [ "$(echo ${NVCC} | grep -o clang)" = "clang" ]; then if nm -o -C $(find . -name *.so) | grep '[^a-z]exit@@GLIBC'; then echo "Found calls to exit() function in shared libraries." exit 1 From 512794069a3b0ad0c3e7bcbb761fff8f318da21a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 18 Nov 2019 10:56:09 +0100 Subject: [PATCH 03/22] Use new-style command substitutions POSIX allows both the legacy `cmd` and the new-style $(cmd) syntaxes: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_03 However, POSIX recommends using the new-style syntax, as it has less restrictions and allows nesting without escape characters: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xcu_chap02.html#tag_23_02_06_03 shellcheck rule: SC2006 --- maintainer/CI/doc_warnings.sh | 2 +- maintainer/CI/dox_warnings.sh | 4 ++-- maintainer/add_missing_headers.sh | 14 +++++++------- maintainer/find_missing_header.sh | 10 +++++----- maintainer/update_header.sh | 20 ++++++++++---------- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/maintainer/CI/doc_warnings.sh b/maintainer/CI/doc_warnings.sh index 7dd5c02ab79..035e28b6bdd 100755 --- a/maintainer/CI/doc_warnings.sh +++ b/maintainer/CI/doc_warnings.sh @@ -22,7 +22,7 @@ # broken links are found in .rst files, the putative line numbers are # printed, otherwise the .html files are printed without line number. -[ -z "${srcdir}" ] && srcdir=`realpath ..` +[ -z "${srcdir}" ] && srcdir=$(realpath ..) # Pattern for :class:`foo` commands to non-existent 'foo' classes/functions. # They are formatted by Sphinx just like regular links to functions, but are diff --git a/maintainer/CI/dox_warnings.sh b/maintainer/CI/dox_warnings.sh index 9b786b302d4..75f1a8cbe8e 100755 --- a/maintainer/CI/dox_warnings.sh +++ b/maintainer/CI/dox_warnings.sh @@ -19,13 +19,13 @@ # This script generates a log of all Doxygen warnings that require fixing. -dox_version=`doxygen --version` +dox_version=$(doxygen --version) if [ "${dox_version}" != "1.8.13" ] && [ "${dox_version}" != "1.8.11" ]; then echo "Doxygen version ${dox_version} not supported" exit 1 fi -[ -z "${srcdir}" ] && srcdir=`realpath ..` +[ -z "${srcdir}" ] && srcdir=$(realpath ..) # prepare Doxyfile for the XML version cp doc/doxygen/Doxyfile doc/doxygen/Doxyfile.bak diff --git a/maintainer/add_missing_headers.sh b/maintainer/add_missing_headers.sh index d7a6e1e2d26..9255f817ecf 100755 --- a/maintainer/add_missing_headers.sh +++ b/maintainer/add_missing_headers.sh @@ -20,14 +20,14 @@ # This needs to be run from the top-level directory # Get files without headers -all_files=`maintainer/files_with_header.sh` -files_to_check=`grep -iL copyright ${all_files}` -py_files=`echo ${files_to_check} | tr " " "\n" | grep -P '\.(pyx?|pxd|sh)$'` -cpp_files=`echo ${files_to_check} | tr " " "\n" | grep -P '\.([c|h]pp|cuh?|dox)$'` +all_files=$(maintainer/files_with_header.sh) +files_to_check=$(grep -iL copyright ${all_files}) +py_files=$(echo ${files_to_check} | tr " " "\n" | grep -P '\.(pyx?|pxd|sh)$') +cpp_files=$(echo ${files_to_check} | tr " " "\n" | grep -P '\.([c|h]pp|cuh?|dox)$') -tmp=`mktemp` +tmp=$(mktemp) # process python/cython/bash files -for f in `echo ${py_files}`; do +for f in $(echo ${py_files}); do head -n1 ${f} | grep -q '^#!' if [ $? = 0 ]; then # preserve shebang on first line @@ -40,7 +40,7 @@ for f in `echo ${py_files}`; do cp ${tmp} ${f} done # process c++/cuda/doxygen files -for f in `echo ${cpp_files}`; do +for f in $(echo ${cpp_files}); do (echo '/*' sed -e 's/^/ * /' maintainer/header_template.txt | sed 's/ $//' echo ' */' diff --git a/maintainer/find_missing_header.sh b/maintainer/find_missing_header.sh index 89bf9559a5f..ecb929b6f5b 100755 --- a/maintainer/find_missing_header.sh +++ b/maintainer/find_missing_header.sh @@ -20,14 +20,14 @@ # check for missing GPL and copyright headers # -files=`sh maintainer/files_with_header.sh` -num_files=`echo $files | wc -w` -current_year=`date +%Y` +files=$(sh maintainer/files_with_header.sh) +num_files=$(echo $files | wc -w) +current_year=$(date +%Y) echo "Examining $num_files files." echo -missing_current_copyright=`egrep -IL "Copyright.*$current_year" $files` +missing_current_copyright=$(egrep -IL "Copyright.*$current_year" $files) echo "Copyright disclaimer missing the current year $current_year" echo "--------------------------------------------------" @@ -49,7 +49,7 @@ echo echo "Missing GPL/simple header" echo "-------------------------" -nolicense=`egrep -IL "((ESPResSo|This program) is free software|Copying and distribution of this file)" $files` +nolicense=$(egrep -IL "((ESPResSo|This program) is free software|Copying and distribution of this file)" $files) if [ -n "$nolicense" ]; then echo $nolicense else diff --git a/maintainer/update_header.sh b/maintainer/update_header.sh index 6786d67e56f..44f052712fc 100755 --- a/maintainer/update_header.sh +++ b/maintainer/update_header.sh @@ -27,24 +27,24 @@ # # To review the diff: # $> git diff --word-diff-regex=. -U0 | grep -Po 'Copyright.+' | sort | uniq -files=`sh maintainer/files_with_header.sh` -num_files=`echo $files | wc -w` -current_year=`date +%Y` +files=$(sh maintainer/files_with_header.sh) +num_files=$(echo $files | wc -w) +current_year=$(date +%Y) echo "Examining $num_files files." echo "Files with copyright disclaimer(s)..." -files=`egrep -l "Copyright" $files` -num_files=`echo $files | wc -w` +files=$(egrep -l "Copyright" $files) +num_files=$(echo $files | wc -w) echo " $num_files files." echo "Files that are missing the current year ($current_year) in the copyright disclaimer(s)..." -files=`egrep -L "Copyright.*$current_year" $files` +files=$(egrep -L "Copyright.*$current_year" $files) for file in $files; do echo " $file" done -noyear_files=`egrep -l "Copyright.*The ESPResSo project" $files` +noyear_files=$(egrep -l "Copyright.*The ESPResSo project" $files) echo " Adding current year to project copyright disclaimer..." echo " \"$current_year\"" for file in $noyear_files; do @@ -52,14 +52,14 @@ for file in $noyear_files; do sed -i -r -e "s/Copyright \(C\) ([0-9,]*)(-20[0-9][0-9])? .*The ESPR/Copyright (C) \1-$current_year The ESPR/" $file done -noproject_files=`egrep -L "Copyright.*The ESPResSo project" $files` +noproject_files=$(egrep -L "Copyright.*The ESPResSo project" $files) echo "Files that are missing the project copyright disclaimer..." -num_files=`echo $noproject_files | wc -w` +num_files=$(echo $noproject_files | wc -w) echo " $num_files files." echo " Adding project copyright disclaimer..." disclaimer="Copyright (C) $current_year The ESPResSo project" echo " \"$disclaimer\"" -tmpfile=`mktemp` +tmpfile=$(mktemp) for file in $noproject_files; do echo " $file" perl -pe "if (!\$done) { s/^(.*)Copyright/\1$disclaimer\n\1Copyright/ and \$done=1; }" $file > $tmpfile From c36db70fb1b707ced9baa9f681cae69e908a5918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 18 Nov 2019 13:40:26 +0100 Subject: [PATCH 04/22] Add braces around shell variables --- maintainer/CI/build_cmake.sh | 16 +++---- maintainer/CI/build_docker.sh | 22 ++++----- maintainer/CI/doc_warnings.sh | 14 +++--- maintainer/CI/dox_warnings.sh | 2 +- maintainer/CI/fix_style.sh | 36 +++++++------- maintainer/add_missing_headers.sh | 2 +- maintainer/find_missing_header.sh | 24 +++++----- .../find_potentially_missing_authors.sh | 2 +- maintainer/gh_close_issue.sh | 6 +-- maintainer/gh_create_issue.sh | 4 +- maintainer/gh_post_status.sh | 8 ++-- maintainer/missing_tests.sh | 10 ++-- maintainer/update_header.sh | 48 +++++++++---------- testsuite/cmake/BashUnitTests.sh | 48 +++++++++---------- 14 files changed, 121 insertions(+), 121 deletions(-) diff --git a/maintainer/CI/build_cmake.sh b/maintainer/CI/build_cmake.sh index 478bc0ecfc3..24d16f7c536 100755 --- a/maintainer/CI/build_cmake.sh +++ b/maintainer/CI/build_cmake.sh @@ -21,7 +21,7 @@ set -e # output value of env variables function outp { - for p in $*; do + for p in ${*}; do echo " ${p}=${!p}" done } @@ -29,26 +29,26 @@ function outp { # start a block function start { echo "==================================================" - echo "START $1" + echo "START ${1}" echo "==================================================" } # end a block function end { echo "==================================================" - echo "END $1" + echo "END ${1}" echo "==================================================" } # set a default value to empty environment variables # cast boolean values to true/false function set_default_value { - if [ "$#" != 2 ]; then - echo "set_default_value() takes 2 arguments (varname, default), got $#" + if [ "${#}" != 2 ]; then + echo "set_default_value() takes 2 arguments (varname, default), got ${#}" exit 1 fi - local -r varname="$1" - local -r default="$2" + local -r varname="${1}" + local -r default="${2}" local -r varname_alphabet=$(echo "${varname}" | tr -d '[:alnum:]_') if [ ! -z "${varname_alphabet}" ]; then echo "variable name '${varname}' contains unauthorized symbols" @@ -235,7 +235,7 @@ end "CONFIGURE" # BUILD start "BUILD" -make -k -j${build_procs} || make -k -j1 || exit $? +make -k -j${build_procs} || make -k -j1 || exit ${?} end "BUILD" diff --git a/maintainer/CI/build_docker.sh b/maintainer/CI/build_docker.sh index f6e057b280a..562967d29d6 100755 --- a/maintainer/CI/build_docker.sh +++ b/maintainer/CI/build_docker.sh @@ -18,20 +18,20 @@ ENV_FILE=$(mktemp esXXXXXXX.env) -cat > $ENV_FILE < ${ENV_FILE} <&1 | grep -qFo "autopep8 $AUTOPEP8_VER (pycodestyle: $PYCODESTYLE_VER)"; then - echo -e "Could not find autopep8 $AUTOPEP8_VER with pycodestyle $PYCODESTYLE_VER\n$AUTOPEP8 is $($AUTOPEP8 --version 2>&1)" +if ! ${AUTOPEP8} --version 2>&1 | grep -qFo "autopep8 ${AUTOPEP8_VER} (pycodestyle: ${PYCODESTYLE_VER})"; then + echo -e "Could not find autopep8 ${AUTOPEP8_VER} with pycodestyle ${PYCODESTYLE_VER}\n${AUTOPEP8} is $(${AUTOPEP8} --version 2>&1)" exit 2 fi -find . \( -name '*.hpp' -o -name '*.cpp' -o -name '*.cu' -o -name '*.cuh' \) -not -path './libs/*' | xargs -r -n 5 -P 8 $CLANGFORMAT -i -style=file || exit 3 -find . \( -name '*.py' -o -name '*.pyx' -o -name '*.pxd' \) -not -path './libs/*' | xargs -r -n 5 -P 8 $AUTOPEP8 --ignore=E266,W291,W293 --in-place --aggressive || exit 3 +find . \( -name '*.hpp' -o -name '*.cpp' -o -name '*.cu' -o -name '*.cuh' \) -not -path './libs/*' | xargs -r -n 5 -P 8 ${CLANGFORMAT} -i -style=file || exit 3 +find . \( -name '*.py' -o -name '*.pyx' -o -name '*.pxd' \) -not -path './libs/*' | xargs -r -n 5 -P 8 ${AUTOPEP8} --ignore=E266,W291,W293 --in-place --aggressive || exit 3 find . -type f -executable ! -name '*.sh' ! -name '*.py' ! -name '*.sh.in' ! -name pypresso.cmakein -not -path './.git/*' | xargs -r -n 5 -P 8 chmod -x || exit 3 -if [ "$CI" != "" ]; then +if [ "${CI}" != "" ]; then git --no-pager diff > style.patch maintainer/gh_post_style_patch.py || exit 1 fi git diff-index --quiet HEAD -- -if [ $? = 1 ]; then - if [ "$CI" != "" ]; then - echo "Failed style check. Download $CI_JOB_URL/artifacts/raw/style.patch to see which changes are necessary." >&2 +if [ ${?} = 1 ]; then + if [ "${CI}" != "" ]; then + echo "Failed style check. Download ${CI_JOB_URL}/artifacts/raw/style.patch to see which changes are necessary." >&2 else echo "Failed style check" >&2 fi @@ -66,11 +66,11 @@ fi pylint_command () { if hash pylint 2> /dev/null; then - pylint "$@" + pylint "${@}" elif hash pylint3 2> /dev/null; then - pylint3 "$@" + pylint3 "${@}" elif hash pylint-3 2> /dev/null; then - pylint-3 "$@" + pylint-3 "${@}" else echo "pylint not found" >&2 exit 1 @@ -79,8 +79,8 @@ pylint_command () { pylint_command --score=no --reports=no --output-format=text src doc maintainer testsuite samples | tee pylint.log errors=$(grep -P '^[a-z]+/.+?.py:[0-9]+:[0-9]+: [CRWEF][0-9]+:' pylint.log | wc -l) -if [ "$CI" != "" ]; then - maintainer/gh_post_pylint.py ${errors} pylint.log || exit 1 +if [ "${CI}" != "" ]; then + maintainer/gh_post_pylint.py "${errors}" pylint.log || exit 1 fi if [ ${errors} != 0 ]; then echo "Failed pylint check: ${errors} errors" >&2 diff --git a/maintainer/add_missing_headers.sh b/maintainer/add_missing_headers.sh index 9255f817ecf..cc3fec157f7 100755 --- a/maintainer/add_missing_headers.sh +++ b/maintainer/add_missing_headers.sh @@ -29,7 +29,7 @@ tmp=$(mktemp) # process python/cython/bash files for f in $(echo ${py_files}); do head -n1 ${f} | grep -q '^#!' - if [ $? = 0 ]; then + if [ ${?} = 0 ]; then # preserve shebang on first line (head -n1 ${f} sed -e 's/^/# /' maintainer/header_template.txt | sed 's/ $//' diff --git a/maintainer/find_missing_header.sh b/maintainer/find_missing_header.sh index ecb929b6f5b..807884937cd 100755 --- a/maintainer/find_missing_header.sh +++ b/maintainer/find_missing_header.sh @@ -21,18 +21,18 @@ # files=$(sh maintainer/files_with_header.sh) -num_files=$(echo $files | wc -w) +num_files=$(echo ${files} | wc -w) current_year=$(date +%Y) -echo "Examining $num_files files." +echo "Examining ${num_files} files." echo -missing_current_copyright=$(egrep -IL "Copyright.*$current_year" $files) +missing_current_copyright=$(egrep -IL "Copyright.*${current_year}" ${files}) -echo "Copyright disclaimer missing the current year $current_year" +echo "Copyright disclaimer missing the current year ${current_year}" echo "--------------------------------------------------" -if [ -n "$missing_current_copyright" ]; then - egrep -Il "Copyright" $missing_current_copyright +if [ -n "${missing_current_copyright}" ]; then + egrep -Il "Copyright" ${missing_current_copyright} else echo "NONE" fi @@ -40,8 +40,8 @@ echo echo "Missing copyright disclaimer" echo "----------------------------" -if [ -n "$missing_current_copyright" ]; then - egrep -IL "Copyright" $missing_current_copyright +if [ -n "${missing_current_copyright}" ]; then + egrep -IL "Copyright" ${missing_current_copyright} else echo "NONE" fi @@ -49,15 +49,15 @@ echo echo "Missing GPL/simple header" echo "-------------------------" -nolicense=$(egrep -IL "((ESPResSo|This program) is free software|Copying and distribution of this file)" $files) -if [ -n "$nolicense" ]; then - echo $nolicense +nolicense=$(egrep -IL "((ESPResSo|This program) is free software|Copying and distribution of this file)" ${files}) +if [ -n "${nolicense}" ]; then + echo ${nolicense} else echo "NONE" fi echo -if [ -n "$nolicense" ] || [ -n "$missing_current_copyright" ]; then +if [ -n "${nolicense}" ] || [ -n "${missing_current_copyright}" ]; then exit 1 fi diff --git a/maintainer/find_potentially_missing_authors.sh b/maintainer/find_potentially_missing_authors.sh index 814509c57c7..87da67edd35 100755 --- a/maintainer/find_potentially_missing_authors.sh +++ b/maintainer/find_potentially_missing_authors.sh @@ -29,6 +29,6 @@ sed -e 's/ <.*//'| sort -u| while read author do - grep -i "$author" AUTHORS >/dev/null || echo Missing: $author + grep -i "${author}" AUTHORS >/dev/null || echo Missing: ${author} done diff --git a/maintainer/gh_close_issue.sh b/maintainer/gh_close_issue.sh index 1df1eac2adf..167c709637b 100755 --- a/maintainer/gh_close_issue.sh +++ b/maintainer/gh_close_issue.sh @@ -21,11 +21,11 @@ ISSUE_NUMBER=$(curl -s -G https://api.github.com/search/issues \ --data-urlencode "q=\"CI failed for merged PR\" org:espressomd repo:espresso is:open is:issue in:title" \ --data-urlencode "q=${CI_PIPELINE_ID} org:espressomd repo:espresso is:open is:issue in:body" | jq '.items[0] .number') -if [ "$ISSUE_NUMBER" != "null" ]; then -curl -s "https://api.github.com/repos/espressomd/espresso/issues/$ISSUE_NUMBER" \ +if [ "${ISSUE_NUMBER}" != "null" ]; then +curl -s "https://api.github.com/repos/espressomd/espresso/issues/${ISSUE_NUMBER}" \ -H "Accept: application/vnd.github.full+json" \ -H "Content-Type: application/json" \ - -H "Authorization: token $GITHUB_TOKEN" \ + -H "Authorization: token ${GITHUB_TOKEN}" \ -X PATCH \ -d "{\"state\": \"closed\" }" fi diff --git a/maintainer/gh_create_issue.sh b/maintainer/gh_create_issue.sh index 4598c5d8317..58d20f398da 100755 --- a/maintainer/gh_create_issue.sh +++ b/maintainer/gh_create_issue.sh @@ -22,6 +22,6 @@ URL=$(echo "https://gitlab.icp.uni-stuttgart.de/espressomd/espresso/pipelines/${ curl -s "https://api.github.com/repos/espressomd/espresso/issues" \ -H "Accept: application/vnd.github.full+json" \ -H "Content-Type: application/json" \ - -H "Authorization: token $GITHUB_TOKEN" \ + -H "Authorization: token ${GITHUB_TOKEN}" \ -X POST \ - -d "{\"title\": \"CI build failed for merged PR\", \"body\": \"$URL\" }" + -d "{\"title\": \"CI build failed for merged PR\", \"body\": \"${URL}\" }" diff --git a/maintainer/gh_post_status.sh b/maintainer/gh_post_status.sh index 9a3c38a3713..e09eaf20530 100755 --- a/maintainer/gh_post_status.sh +++ b/maintainer/gh_post_status.sh @@ -17,12 +17,12 @@ # along with this program. If not, see . # -[ "$#" -eq 1 ] || exit -1 +[ "${#}" -eq 1 ] || exit -1 GIT_COMMIT=$(git rev-parse HEAD) URL=$(echo "https://gitlab.icp.uni-stuttgart.de/espressomd/espresso/pipelines/${CI_PIPELINE_ID}") -STATUS="$1" -curl "https://api.github.com/repos/espressomd/espresso/statuses/$GIT_COMMIT?access_token=$GITHUB_TOKEN" \ +STATUS="${1}" +curl "https://api.github.com/repos/espressomd/espresso/statuses/${GIT_COMMIT}?access_token=${GITHUB_TOKEN}" \ -H "Content-Type: application/json" \ -X POST \ - -d "{\"state\": \"$STATUS\", \"context\": \"ICP GitLab CI\", \"target_url\": \"$URL\"}" + -d "{\"state\": \"${STATUS}\", \"context\": \"ICP GitLab CI\", \"target_url\": \"${URL}\"}" diff --git a/maintainer/missing_tests.sh b/maintainer/missing_tests.sh index f73921c08e5..af88dee3ce5 100755 --- a/maintainer/missing_tests.sh +++ b/maintainer/missing_tests.sh @@ -19,15 +19,15 @@ for T in *.py; do - if grep -q "$T" CMakeLists.txt; then + if grep -q "${T}" CMakeLists.txt; then continue; else - GIT_STATUS=$(git status --porcelain -- "$T") - if [[ $GIT_STATUS == ??* ]]; then - echo "File '$T' is not tracked." + GIT_STATUS=$(git status --porcelain -- "${T}") + if [[ ${GIT_STATUS} == ??* ]]; then + echo "File '${T}' is not tracked." continue; else - echo "File '$T' is missing in CMakeLists.txt."; + echo "File '${T}' is missing in CMakeLists.txt."; fi fi done diff --git a/maintainer/update_header.sh b/maintainer/update_header.sh index 44f052712fc..5e6ce04ddeb 100755 --- a/maintainer/update_header.sh +++ b/maintainer/update_header.sh @@ -28,42 +28,42 @@ # To review the diff: # $> git diff --word-diff-regex=. -U0 | grep -Po 'Copyright.+' | sort | uniq files=$(sh maintainer/files_with_header.sh) -num_files=$(echo $files | wc -w) +num_files=$(echo ${files} | wc -w) current_year=$(date +%Y) -echo "Examining $num_files files." +echo "Examining ${num_files} files." echo "Files with copyright disclaimer(s)..." -files=$(egrep -l "Copyright" $files) -num_files=$(echo $files | wc -w) -echo " $num_files files." +files=$(egrep -l "Copyright" ${files}) +num_files=$(echo ${files} | wc -w) +echo " ${num_files} files." -echo "Files that are missing the current year ($current_year) in the copyright disclaimer(s)..." -files=$(egrep -L "Copyright.*$current_year" $files) -for file in $files; do - echo " $file" +echo "Files that are missing the current year (${current_year}) in the copyright disclaimer(s)..." +files=$(egrep -L "Copyright.*${current_year}" ${files}) +for file in ${files}; do + echo " ${file}" done -noyear_files=$(egrep -l "Copyright.*The ESPResSo project" $files) +noyear_files=$(egrep -l "Copyright.*The ESPResSo project" ${files}) echo " Adding current year to project copyright disclaimer..." -echo " \"$current_year\"" -for file in $noyear_files; do - echo " $file" - sed -i -r -e "s/Copyright \(C\) ([0-9,]*)(-20[0-9][0-9])? .*The ESPR/Copyright (C) \1-$current_year The ESPR/" $file +echo " \"${current_year}\"" +for file in ${noyear_files}; do + echo " ${file}" + sed -i -r -e "s/Copyright \(C\) ([0-9,]*)(-20[0-9][0-9])? .*The ESPR/Copyright (C) \1-${current_year} The ESPR/" ${file} done -noproject_files=$(egrep -L "Copyright.*The ESPResSo project" $files) +noproject_files=$(egrep -L "Copyright.*The ESPResSo project" ${files}) echo "Files that are missing the project copyright disclaimer..." -num_files=$(echo $noproject_files | wc -w) -echo " $num_files files." +num_files=$(echo ${noproject_files} | wc -w) +echo " ${num_files} files." echo " Adding project copyright disclaimer..." -disclaimer="Copyright (C) $current_year The ESPResSo project" -echo " \"$disclaimer\"" +disclaimer="Copyright (C) ${current_year} The ESPResSo project" +echo " \"${disclaimer}\"" tmpfile=$(mktemp) -for file in $noproject_files; do - echo " $file" - perl -pe "if (!\$done) { s/^(.*)Copyright/\1$disclaimer\n\1Copyright/ and \$done=1; }" $file > $tmpfile - cat $tmpfile > $file +for file in ${noproject_files}; do + echo " ${file}" + perl -pe "if (!\$done) { s/^(.*)Copyright/\1${disclaimer}\n\1Copyright/ and \$done=1; }" ${file} > ${tmpfile} + cat ${tmpfile} > ${file} done -rm $tmpfile +rm ${tmpfile} diff --git a/testsuite/cmake/BashUnitTests.sh b/testsuite/cmake/BashUnitTests.sh index 9b090ff8c04..27e59f2ed1d 100755 --- a/testsuite/cmake/BashUnitTests.sh +++ b/testsuite/cmake/BashUnitTests.sh @@ -171,9 +171,9 @@ function try_catch() { detect_open_mpi || return 1 ( set -e # exit from current subshell on first error - "$@" + "${@}" ) - return $? + return ${?} } ## @brief Try/Catch statement in Bash without output to the terminal @@ -185,9 +185,9 @@ function try_catch_silent() { detect_open_mpi || return 1 ( set -e # exit from current subshell on first error - "$@" 1>/dev/null 2>/dev/null + "${@}" 1>/dev/null 2>/dev/null ) - return $? + return ${?} } ## @brief Try/Catch statement in Bash while logging stdout/stderr @@ -201,9 +201,9 @@ function try_catch_capture_output() { rm -f ${TMPNAME} ( set -e # exit from current subshell on first error - "$@" 2>>${TMPNAME} 1>>${TMPNAME} + "${@}" 2>>${TMPNAME} 1>>${TMPNAME} ) - return $? + return ${?} } ## @} @@ -214,7 +214,7 @@ function run_set_up() { if [ "$(type -t set_up)" = "function" ] then try_catch set_up - local -r retcode=$? + local -r retcode=${?} if [ "${retcode}" -ne "0" ] then stderr "Failed to run set_up()" @@ -231,7 +231,7 @@ function run_tear_down() { if [ "$(type -t tear_down)" = "function" ] then try_catch tear_down - local retcode=$? + local retcode=${?} if [ "${retcode}" -ne "0" ] then stderr "Failed to run tear_down()" @@ -272,7 +272,7 @@ readonly TMPNAME=$(mktemp -u) ## Print the test name and clear @ref error_log ## @param $1 Test name function start_test_block() { - local label=$1 + local label=${1} echo -n "${label} " error_log=() } @@ -297,7 +297,7 @@ function log_success() { ## @brief Log a failed assertion ## @param $* Description of the failure function log_failure() { - local message=$* + local message=${*} echo -n 'x' error_log+=("${message}") error_counter=$((error_counter + 1)) @@ -339,8 +339,8 @@ function run_test_suite() { ## @param $1 Filepath ## @param $2 Message on failure (optional) function assert_file_exists() { - local -r filepath=$1 - local message=$2 + local -r filepath=${1} + local message=${2} if [ -z "${message}" ] then message="file not found: ${filepath}" @@ -358,9 +358,9 @@ function assert_file_exists() { ## @param $2 Expected result ## @param $3 Message on failure (optional) function assert_string_equal() { - local -r result=$1 - local -r expected=$2 - local message=$3 + local -r result=${1} + local -r expected=${2} + local message=${3} if [ -z "${message}" ] then message="${result} != ${expected}" @@ -378,9 +378,9 @@ function assert_string_equal() { ## @param $2 Expected result ## @param $3 Message on failure (optional) function assert_equal() { - local -r result=$1 - local -r expected=$2 - local message=$3 + local -r result=${1} + local -r expected=${2} + local message=${3} if [ -z "${message}" ] then message="${result} != ${expected}" @@ -397,8 +397,8 @@ function assert_equal() { ## @param $1 Obtained result ## @param $2 Message on failure (optional) function assert_non_zero() { - local -r result=$1 - local message=$2 + local -r result=${1} + local message=${2} if [ -z "${message}" ] then message="${result} == 0" @@ -415,8 +415,8 @@ function assert_non_zero() { ## @param $1 Obtained result ## @param $2 Message on failure (optional) function assert_zero() { - local -r result=$1 - local message=$2 + local -r result=${1} + local message=${2} if [ -z "${message}" ] then message="${result} != 0" @@ -434,8 +434,8 @@ function assert_zero() { ## Cannot be used in a script run by Open MPI (see \ref TryCatch). ## @param $@ Command to run, possibly with modifiers function assert_return_code() { - try_catch_capture_output "$@" - local -r retcode=$? + try_catch_capture_output "${@}" + local -r retcode=${?} if [ "${retcode}" -eq "0" ] then log_success From e289050d0af8242347da4319579a0c10c99ae9ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 18 Nov 2019 14:19:56 +0100 Subject: [PATCH 05/22] Double quote string variables shellcheck rule: SC2086 --- maintainer/CI/build_cmake.sh | 62 +++++++++---------- maintainer/CI/build_docker.sh | 8 +-- maintainer/CI/doc_warnings.sh | 16 ++--- maintainer/CI/dox_warnings.sh | 8 +-- maintainer/CI/fix_style.sh | 12 ++-- maintainer/add_missing_headers.sh | 18 +++--- .../find_potentially_missing_authors.sh | 2 +- maintainer/update_header.sh | 8 +-- testsuite/cmake/BashUnitTests.sh | 36 +++++------ testsuite/cmake/test_install.sh | 2 +- 10 files changed, 86 insertions(+), 86 deletions(-) diff --git a/maintainer/CI/build_cmake.sh b/maintainer/CI/build_cmake.sh index 24d16f7c536..59bcd53e98b 100755 --- a/maintainer/CI/build_cmake.sh +++ b/maintainer/CI/build_cmake.sh @@ -76,7 +76,7 @@ function set_default_value { # handle environment variables set_default_value insource false -set_default_value srcdir $(pwd) +set_default_value srcdir "$(pwd)" set_default_value cmake_params "" set_default_value with_fftw true set_default_value with_python_interface true @@ -101,7 +101,7 @@ set_default_value with_scafacos true set_default_value test_timeout 300 set_default_value hide_gpu false -if [ ${make_check} = true ] || [ ${make_check_tutorials} = true ] || [ ${make_check_samples} = true ] || [ ${make_check_benchmarks} = true ]; then +if [ "${make_check}" = true ] || [ "${make_check_tutorials}" = true ] || [ "${make_check_samples}" = true ] || [ "${make_check_benchmarks}" = true ]; then run_checks=true else run_checks=false @@ -109,13 +109,13 @@ fi # If there are no user-provided flags, default # ones are added according to ${with_coverage} -nvcc_flags=${cxx_flags} +nvcc_flags="${cxx_flags}" if [ -z "${cxx_flags}" ]; then - if ${with_coverage}; then + if [ "${with_coverage}" = true ]; then cxx_flags="-Og" nvcc_flags="-O3" else - if [ ${run_checks} = true ]; then + if [ "${run_checks}" = true ]; then cxx_flags="-O3" nvcc_flags="-O3" else @@ -125,7 +125,7 @@ if [ -z "${cxx_flags}" ]; then fi fi -if [ ${with_coverage} = true ]; then +if [ "${with_coverage}" = true ]; then bash <(curl -s https://codecov.io/env) &> /dev/null; fi @@ -133,20 +133,20 @@ cmake_params="-DCMAKE_BUILD_TYPE=${build_type} -DWARNINGS_ARE_ERRORS=ON -DTEST_N cmake_params="${cmake_params} -DCMAKE_CXX_FLAGS=${cxx_flags} -DCUDA_NVCC_FLAGS=${nvcc_flags}" cmake_params="${cmake_params} -DCMAKE_INSTALL_PREFIX=/tmp/espresso-unit-tests" cmake_params="${cmake_params} -DTEST_TIMEOUT=${test_timeout}" -if [ ${with_ccache} = true ]; then +if [ "${with_ccache}" = true ]; then cmake_params="${cmake_params} -DWITH_CCACHE=ON" fi -if [ ${with_scafacos} = true ]; then +if [ "${with_scafacos}" = true ]; then cmake_params="${cmake_params} -DWITH_SCAFACOS=ON" fi command -v nvidia-smi && nvidia-smi || true -if [ ${hide_gpu} = true ]; then +if [ "${hide_gpu}" = true ]; then echo "Hiding gpu from Cuda via CUDA_VISIBLE_DEVICES" export CUDA_VISIBLE_DEVICES="" fi -if [ ${insource} = true ]; then +if [ "${insource}" = true ]; then builddir="${srcdir}" elif [ -z "${builddir}" ]; then builddir="${srcdir}/build" @@ -162,55 +162,55 @@ outp insource srcdir builddir \ build_procs check_procs \ with_cuda with_ccache -if [ ${insource} = false ]; then +if [ "${insource}" = false ]; then if [ ! -d "${builddir}" ]; then echo "Creating ${builddir}..." mkdir -p "${builddir}" fi fi -if [ ${insource} = false ]; then +if [ "${insource}" = false ]; then cd "${builddir}" fi # load MPI module if necessary if [ -f "/etc/os-release" ]; then grep -q suse /etc/os-release && source /etc/profile.d/modules.sh && module load gnu-openmpi - grep -q 'rhel\|fedora' /etc/os-release && for f in /etc/profile.d/*module*.sh; do source ${f}; done && module load mpi + grep -q 'rhel\|fedora' /etc/os-release && for f in /etc/profile.d/*module*.sh; do source "${f}"; done && module load mpi fi # CONFIGURE start "CONFIGURE" -if [ ${with_fftw} = true ]; then +if [ "${with_fftw}" = true ]; then : else cmake_params="-DCMAKE_DISABLE_FIND_PACKAGE_FFTW3=ON ${cmake_params}" fi -if [ ${with_python_interface} = true ]; then +if [ "${with_python_interface}" = true ]; then cmake_params="-DWITH_PYTHON=ON ${cmake_params}" else cmake_params="-DWITH_PYTHON=OFF ${cmake_params}" fi -if [ ${with_coverage} = true ]; then +if [ "${with_coverage}" = true ]; then cmake_params="-DWITH_COVERAGE=ON ${cmake_params}" fi -if [ ${with_asan} = true ]; then +if [ "${with_asan}" = true ]; then cmake_params="-DWITH_ASAN=ON ${cmake_params}" fi -if [ ${with_ubsan} = true ]; then +if [ "${with_ubsan}" = true ]; then cmake_params="-DWITH_UBSAN=ON ${cmake_params}" fi -if [ ${with_static_analysis} = true ]; then +if [ "${with_static_analysis}" = true ]; then cmake_params="-DWITH_CLANG_TIDY=ON ${cmake_params}" fi -if [ ${with_cuda} = true ]; then +if [ "${with_cuda}" = true ]; then : else cmake_params="-DWITH_CUDA=OFF ${cmake_params}" @@ -241,25 +241,25 @@ end "BUILD" # check for exit function, which should never be called from shared library # can't do this on CUDA though because nvcc creates a host function that just calls exit for each device function -if [ ${with_cuda} = false ] || [ "$(echo ${NVCC} | grep -o clang)" = "clang" ]; then +if [ "${with_cuda}" = false ] || [ "$(echo ${NVCC} | grep -o clang)" = "clang" ]; then if nm -o -C $(find . -name *.so) | grep '[^a-z]exit@@GLIBC'; then echo "Found calls to exit() function in shared libraries." exit 1 fi fi -if [ ${run_checks} = true ]; then +if [ "${run_checks}" = true ]; then start "TEST" # unit tests and integration tests - if [ ${make_check} = true ]; then + if [ "${make_check}" = true ]; then make -j${build_procs} check_unit_tests ${make_params} || exit 1 if [ -z "${run_tests}" ]; then - if [ ${check_odd_only} = true ]; then + if [ "${check_odd_only}" = true ]; then make -j${build_procs} check_python_parallel_odd ${make_params} || exit 1 - elif [ ${check_gpu_only} = true ]; then + elif [ "${check_gpu_only}" = true ]; then make -j${build_procs} check_python_gpu ${make_params} || exit 1 - elif [ ${check_skip_long} = true ]; then + elif [ "${check_skip_long}" = true ]; then make -j${build_procs} check_python_skip_long ${make_params} || exit 1 else make -j${build_procs} check_python ${make_params} || exit 1 @@ -267,23 +267,23 @@ if [ ${run_checks} = true ]; then else make python_tests ${make_params} for t in ${run_tests}; do - ctest --timeout 60 --output-on-failure -R ${t} || exit 1 + ctest --timeout 60 --output-on-failure -R "${t}" || exit 1 done fi fi # tutorial tests - if [ ${make_check_tutorials} = true ]; then + if [ "${make_check_tutorials}" = true ]; then make -j${build_procs} check_tutorials ${make_params} || exit 1 fi # sample tests - if [ ${make_check_samples} = true ]; then + if [ "${make_check_samples}" = true ]; then make -j${build_procs} check_samples ${make_params} || exit 1 fi # benchmark tests - if [ ${make_check_benchmarks} = true ]; then + if [ "${make_check_benchmarks}" = true ]; then make -j${build_procs} check_benchmarks ${make_params} || exit 1 fi @@ -301,7 +301,7 @@ else end "TEST" fi -if [ ${with_coverage} = true ]; then +if [ "${with_coverage}" = true ]; then cd "${builddir}" lcov -q --directory . --ignore-errors graph --capture --output-file coverage.info # capture coverage info lcov -q --remove coverage.info '/usr/*' --output-file coverage.info # filter out system diff --git a/maintainer/CI/build_docker.sh b/maintainer/CI/build_docker.sh index 562967d29d6..229fb13df6c 100755 --- a/maintainer/CI/build_docker.sh +++ b/maintainer/CI/build_docker.sh @@ -18,7 +18,7 @@ ENV_FILE=$(mktemp esXXXXXXX.env) -cat > ${ENV_FILE} < "${ENV_FILE}" <&1 | grep -qFo "autopep8 ${AUTOPEP8_VER} (pycodestyle: ${PYCODESTYLE_VER})"; then +if ! "${AUTOPEP8}" --version 2>&1 | grep -qFo "autopep8 ${AUTOPEP8_VER} (pycodestyle: ${PYCODESTYLE_VER})"; then echo -e "Could not find autopep8 ${AUTOPEP8_VER} with pycodestyle ${PYCODESTYLE_VER}\n${AUTOPEP8} is $(${AUTOPEP8} --version 2>&1)" exit 2 fi -find . \( -name '*.hpp' -o -name '*.cpp' -o -name '*.cu' -o -name '*.cuh' \) -not -path './libs/*' | xargs -r -n 5 -P 8 ${CLANGFORMAT} -i -style=file || exit 3 -find . \( -name '*.py' -o -name '*.pyx' -o -name '*.pxd' \) -not -path './libs/*' | xargs -r -n 5 -P 8 ${AUTOPEP8} --ignore=E266,W291,W293 --in-place --aggressive || exit 3 +find . \( -name '*.hpp' -o -name '*.cpp' -o -name '*.cu' -o -name '*.cuh' \) -not -path './libs/*' | xargs -r -n 5 -P 8 "${CLANGFORMAT}" -i -style=file || exit 3 +find . \( -name '*.py' -o -name '*.pyx' -o -name '*.pxd' \) -not -path './libs/*' | xargs -r -n 5 -P 8 "${AUTOPEP8}" --ignore=E266,W291,W293 --in-place --aggressive || exit 3 find . -type f -executable ! -name '*.sh' ! -name '*.py' ! -name '*.sh.in' ! -name pypresso.cmakein -not -path './.git/*' | xargs -r -n 5 -P 8 chmod -x || exit 3 if [ "${CI}" != "" ]; then @@ -53,7 +53,7 @@ if [ "${CI}" != "" ]; then maintainer/gh_post_style_patch.py || exit 1 fi git diff-index --quiet HEAD -- -if [ ${?} = 1 ]; then +if [ "${?}" = 1 ]; then if [ "${CI}" != "" ]; then echo "Failed style check. Download ${CI_JOB_URL}/artifacts/raw/style.patch to see which changes are necessary." >&2 else @@ -82,7 +82,7 @@ errors=$(grep -P '^[a-z]+/.+?.py:[0-9]+:[0-9]+: [CRWEF][0-9]+:' pylint.log | wc if [ "${CI}" != "" ]; then maintainer/gh_post_pylint.py "${errors}" pylint.log || exit 1 fi -if [ ${errors} != 0 ]; then +if [ "${errors}" != 0 ]; then echo "Failed pylint check: ${errors} errors" >&2 exit 1 else diff --git a/maintainer/add_missing_headers.sh b/maintainer/add_missing_headers.sh index cc3fec157f7..bde67fa244a 100755 --- a/maintainer/add_missing_headers.sh +++ b/maintainer/add_missing_headers.sh @@ -28,24 +28,24 @@ cpp_files=$(echo ${files_to_check} | tr " " "\n" | grep -P '\.([c|h]pp|cuh?|dox) tmp=$(mktemp) # process python/cython/bash files for f in $(echo ${py_files}); do - head -n1 ${f} | grep -q '^#!' - if [ ${?} = 0 ]; then + head -n1 "${f}" | grep -q '^#!' + if [ "${?}" = 0 ]; then # preserve shebang on first line - (head -n1 ${f} + (head -n1 "${f}" sed -e 's/^/# /' maintainer/header_template.txt | sed 's/ $//' - tail -n+2 ${f}) > ${tmp} + tail -n+2 "${f}") > "${tmp}" else - (sed -e 's/^/# /' maintainer/header_template.txt | sed 's/ $//'; cat ${f}) > ${tmp} + (sed -e 's/^/# /' maintainer/header_template.txt | sed 's/ $//'; cat "${f}") > "${tmp}" fi - cp ${tmp} ${f} + cp "${tmp}" "${f}" done # process c++/cuda/doxygen files for f in $(echo ${cpp_files}); do (echo '/*' sed -e 's/^/ * /' maintainer/header_template.txt | sed 's/ $//' echo ' */' - cat ${f}) > ${tmp} - cp ${tmp} ${f} + cat "${f}") > "${tmp}" + cp "${tmp}" "${f}" done -rm ${tmp} +rm "${tmp}" diff --git a/maintainer/find_potentially_missing_authors.sh b/maintainer/find_potentially_missing_authors.sh index 87da67edd35..4f68d996ce6 100755 --- a/maintainer/find_potentially_missing_authors.sh +++ b/maintainer/find_potentially_missing_authors.sh @@ -29,6 +29,6 @@ sed -e 's/ <.*//'| sort -u| while read author do - grep -i "${author}" AUTHORS >/dev/null || echo Missing: ${author} + grep -i "${author}" AUTHORS >/dev/null || echo "Missing: ${author}" done diff --git a/maintainer/update_header.sh b/maintainer/update_header.sh index 5e6ce04ddeb..3ee96133765 100755 --- a/maintainer/update_header.sh +++ b/maintainer/update_header.sh @@ -49,7 +49,7 @@ echo " Adding current year to project copyright disclaimer..." echo " \"${current_year}\"" for file in ${noyear_files}; do echo " ${file}" - sed -i -r -e "s/Copyright \(C\) ([0-9,]*)(-20[0-9][0-9])? .*The ESPR/Copyright (C) \1-${current_year} The ESPR/" ${file} + sed -i -r -e "s/Copyright \(C\) ([0-9,]*)(-20[0-9][0-9])? .*The ESPR/Copyright (C) \1-${current_year} The ESPR/" "${file}" done noproject_files=$(egrep -L "Copyright.*The ESPResSo project" ${files}) @@ -62,8 +62,8 @@ echo " \"${disclaimer}\"" tmpfile=$(mktemp) for file in ${noproject_files}; do echo " ${file}" - perl -pe "if (!\$done) { s/^(.*)Copyright/\1${disclaimer}\n\1Copyright/ and \$done=1; }" ${file} > ${tmpfile} - cat ${tmpfile} > ${file} + perl -pe "if (!\$done) { s/^(.*)Copyright/\1${disclaimer}\n\1Copyright/ and \$done=1; }" "${file}" > "${tmpfile}" + cat "${tmpfile}" > "${file}" done -rm ${tmpfile} +rm "${tmpfile}" diff --git a/testsuite/cmake/BashUnitTests.sh b/testsuite/cmake/BashUnitTests.sh index 27e59f2ed1d..ebf87c8a7d9 100755 --- a/testsuite/cmake/BashUnitTests.sh +++ b/testsuite/cmake/BashUnitTests.sh @@ -198,10 +198,10 @@ function try_catch_silent() { ## @returns Error code returned by the command function try_catch_capture_output() { detect_open_mpi || return 1 - rm -f ${TMPNAME} + rm -f "${TMPNAME}" ( set -e # exit from current subshell on first error - "${@}" 2>>${TMPNAME} 1>>${TMPNAME} + "${@}" 2>>"${TMPNAME}" 1>>"${TMPNAME}" ) return ${?} } @@ -227,7 +227,7 @@ function run_set_up() { ## @brief Run the tear_down() function if it exists ## @returns Error code returned by tear_down() function run_tear_down() { - rm -f ${TMPNAME} + rm -f "${TMPNAME}" if [ "$(type -t tear_down)" = "function" ] then try_catch tear_down @@ -272,7 +272,7 @@ readonly TMPNAME=$(mktemp -u) ## Print the test name and clear @ref error_log ## @param $1 Test name function start_test_block() { - local label=${1} + local label="${1}" echo -n "${label} " error_log=() } @@ -297,7 +297,7 @@ function log_success() { ## @brief Log a failed assertion ## @param $* Description of the failure function log_failure() { - local message=${*} + local message="${*}" echo -n 'x' error_log+=("${message}") error_counter=$((error_counter + 1)) @@ -339,8 +339,8 @@ function run_test_suite() { ## @param $1 Filepath ## @param $2 Message on failure (optional) function assert_file_exists() { - local -r filepath=${1} - local message=${2} + local -r filepath="${1}" + local message="${2}" if [ -z "${message}" ] then message="file not found: ${filepath}" @@ -358,9 +358,9 @@ function assert_file_exists() { ## @param $2 Expected result ## @param $3 Message on failure (optional) function assert_string_equal() { - local -r result=${1} - local -r expected=${2} - local message=${3} + local -r result="${1}" + local -r expected="${2}" + local message="${3}" if [ -z "${message}" ] then message="${result} != ${expected}" @@ -378,9 +378,9 @@ function assert_string_equal() { ## @param $2 Expected result ## @param $3 Message on failure (optional) function assert_equal() { - local -r result=${1} - local -r expected=${2} - local message=${3} + local -r result="${1}" + local -r expected="${2}" + local message="${3}" if [ -z "${message}" ] then message="${result} != ${expected}" @@ -397,8 +397,8 @@ function assert_equal() { ## @param $1 Obtained result ## @param $2 Message on failure (optional) function assert_non_zero() { - local -r result=${1} - local message=${2} + local -r result="${1}" + local message="${2}" if [ -z "${message}" ] then message="${result} == 0" @@ -415,8 +415,8 @@ function assert_non_zero() { ## @param $1 Obtained result ## @param $2 Message on failure (optional) function assert_zero() { - local -r result=${1} - local message=${2} + local -r result="${1}" + local message="${2}" if [ -z "${message}" ] then message="${result} != 0" @@ -441,7 +441,7 @@ function assert_return_code() { log_success else local message="non-zero return code (${retcode}) for command \`$*\`" - local logfile=$(cat ${TMPNAME} | sed 's/^/ /') + local logfile=$(cat "${TMPNAME}" | sed 's/^/ /') log_failure "${message}"$'\n'"${logfile}" fi } diff --git a/testsuite/cmake/test_install.sh b/testsuite/cmake/test_install.sh index 10768cb3c60..07e24b99331 100755 --- a/testsuite/cmake/test_install.sh +++ b/testsuite/cmake/test_install.sh @@ -27,7 +27,7 @@ function test_install() { "@PYTHON_DIR@/espressomd/_init.so" \ "@PYTHON_DIR@/espressomd/__init__.py" ) - for filepath in ${filepaths[@]}; do + for filepath in "${filepaths[@]}"; do assert_file_exists "${filepath}" done From a4341a16ebf67d9217870bb515d94f719a315583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 18 Nov 2019 14:49:01 +0100 Subject: [PATCH 06/22] Formatting --- maintainer/CI/build_cmake.sh | 2 +- maintainer/CI/doc_warnings.sh | 5 +- maintainer/CI/fix_style.sh | 2 +- maintainer/add_missing_headers.sh | 1 - maintainer/find_missing_header.sh | 13 ++-- .../find_potentially_missing_authors.sh | 18 +++--- maintainer/gh_close_issue.sh | 12 ++-- maintainer/missing_tests.sh | 27 ++++----- maintainer/update_header.sh | 1 - testsuite/cmake/BashUnitTests.sh | 60 +++++++------------ 10 files changed, 56 insertions(+), 85 deletions(-) diff --git a/maintainer/CI/build_cmake.sh b/maintainer/CI/build_cmake.sh index 59bcd53e98b..c08d54e5a73 100755 --- a/maintainer/CI/build_cmake.sh +++ b/maintainer/CI/build_cmake.sh @@ -126,7 +126,7 @@ if [ -z "${cxx_flags}" ]; then fi if [ "${with_coverage}" = true ]; then - bash <(curl -s https://codecov.io/env) &> /dev/null; + bash <(curl -s https://codecov.io/env) &> /dev/null fi cmake_params="-DCMAKE_BUILD_TYPE=${build_type} -DWARNINGS_ARE_ERRORS=ON -DTEST_NP:INT=${check_procs} ${cmake_params}" diff --git a/maintainer/CI/doc_warnings.sh b/maintainer/CI/doc_warnings.sh index 2baff4ee454..5beb8c988a1 100755 --- a/maintainer/CI/doc_warnings.sh +++ b/maintainer/CI/doc_warnings.sh @@ -42,10 +42,9 @@ if [ "${?}" = "0" ]; then rm -f doc_warnings.log~ touch doc_warnings.log~ found="false" - grep -rPno --include \*.html --exclude-dir=_modules "${regex_sphinx_broken_link}" doc/sphinx/html/ | sort | uniq | while read -r line - do + grep -rPno --include \*.html --exclude-dir=_modules "${regex_sphinx_broken_link}" doc/sphinx/html/ | sort | uniq | while read -r line; do # extract link target - reference=$(echo "${line}" | sed -r 's|^.+(.+)$|\1|' | sed 's/()$//') + reference=$(echo "${line}" | sed -r 's|^.+(.+)$|\1|' | sed 's/()$//') # skip if broken link refers to a standard Python type or to a # class/function from an imported module other than espressomd is_standard_type_or_module="false" diff --git a/maintainer/CI/fix_style.sh b/maintainer/CI/fix_style.sh index 5323a5bd390..08145f2835c 100755 --- a/maintainer/CI/fix_style.sh +++ b/maintainer/CI/fix_style.sh @@ -46,7 +46,7 @@ fi find . \( -name '*.hpp' -o -name '*.cpp' -o -name '*.cu' -o -name '*.cuh' \) -not -path './libs/*' | xargs -r -n 5 -P 8 "${CLANGFORMAT}" -i -style=file || exit 3 find . \( -name '*.py' -o -name '*.pyx' -o -name '*.pxd' \) -not -path './libs/*' | xargs -r -n 5 -P 8 "${AUTOPEP8}" --ignore=E266,W291,W293 --in-place --aggressive || exit 3 -find . -type f -executable ! -name '*.sh' ! -name '*.py' ! -name '*.sh.in' ! -name pypresso.cmakein -not -path './.git/*' | xargs -r -n 5 -P 8 chmod -x || exit 3 +find . -type f -executable ! -name '*.sh' ! -name '*.py' ! -name '*.sh.in' ! -name pypresso.cmakein -not -path './.git/*' | xargs -r -n 5 -P 8 chmod -x || exit 3 if [ "${CI}" != "" ]; then git --no-pager diff > style.patch diff --git a/maintainer/add_missing_headers.sh b/maintainer/add_missing_headers.sh index bde67fa244a..f3145bfa216 100755 --- a/maintainer/add_missing_headers.sh +++ b/maintainer/add_missing_headers.sh @@ -48,4 +48,3 @@ for f in $(echo ${cpp_files}); do cp "${tmp}" "${f}" done rm "${tmp}" - diff --git a/maintainer/find_missing_header.sh b/maintainer/find_missing_header.sh index 807884937cd..953d35b4f16 100755 --- a/maintainer/find_missing_header.sh +++ b/maintainer/find_missing_header.sh @@ -1,21 +1,21 @@ #! /bin/bash -x # Copyright (C) 2012-2019 The ESPResSo project # Copyright (C) 2012 Olaf Lenz -# +# # This file is part of ESPResSo. -# +# # ESPResSo is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # ESPResSo is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# along with this program. If not, see . # # check for missing GPL and copyright headers # @@ -59,5 +59,4 @@ echo if [ -n "${nolicense}" ] || [ -n "${missing_current_copyright}" ]; then exit 1 -fi - +fi diff --git a/maintainer/find_potentially_missing_authors.sh b/maintainer/find_potentially_missing_authors.sh index 4f68d996ce6..6d5e534603a 100755 --- a/maintainer/find_potentially_missing_authors.sh +++ b/maintainer/find_potentially_missing_authors.sh @@ -22,13 +22,11 @@ # This has to be run from the root directory of the source tree -git log| -grep -i ^author| -cut -f2- -d\ | -sed -e 's/ <.*//'| -sort -u| -while read author -do - grep -i "${author}" AUTHORS >/dev/null || echo "Missing: ${author}" -done - +git log | + grep -i ^author | + cut -f2- -d\ | + sed -e 's/ <.*//' | + sort -u | + while read author; do + grep -i "${author}" AUTHORS >/dev/null || echo "Missing: ${author}" + done diff --git a/maintainer/gh_close_issue.sh b/maintainer/gh_close_issue.sh index 167c709637b..2b44dcf072a 100755 --- a/maintainer/gh_close_issue.sh +++ b/maintainer/gh_close_issue.sh @@ -22,10 +22,10 @@ ISSUE_NUMBER=$(curl -s -G https://api.github.com/search/issues \ --data-urlencode "q=${CI_PIPELINE_ID} org:espressomd repo:espresso is:open is:issue in:body" | jq '.items[0] .number') if [ "${ISSUE_NUMBER}" != "null" ]; then -curl -s "https://api.github.com/repos/espressomd/espresso/issues/${ISSUE_NUMBER}" \ - -H "Accept: application/vnd.github.full+json" \ - -H "Content-Type: application/json" \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -X PATCH \ - -d "{\"state\": \"closed\" }" + curl -s "https://api.github.com/repos/espressomd/espresso/issues/${ISSUE_NUMBER}" \ + -H "Accept: application/vnd.github.full+json" \ + -H "Content-Type: application/json" \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -X PATCH \ + -d "{\"state\": \"closed\" }" fi diff --git a/maintainer/missing_tests.sh b/maintainer/missing_tests.sh index af88dee3ce5..a782e4fe87f 100755 --- a/maintainer/missing_tests.sh +++ b/maintainer/missing_tests.sh @@ -17,19 +17,16 @@ # along with this program. If not, see . # -for T in *.py; -do - if grep -q "${T}" CMakeLists.txt; then - continue; - else - GIT_STATUS=$(git status --porcelain -- "${T}") - if [[ ${GIT_STATUS} == ??* ]]; then - echo "File '${T}' is not tracked." - continue; - else - echo "File '${T}' is missing in CMakeLists.txt."; - fi - fi +for T in *.py; do + if grep -q "${T}" CMakeLists.txt; then + continue + else + GIT_STATUS=$(git status --porcelain -- "${T}") + if [[ ${GIT_STATUS} == ??* ]]; then + echo "File '${T}' is not tracked." + continue + else + echo "File '${T}' is missing in CMakeLists.txt." + fi + fi done - - diff --git a/maintainer/update_header.sh b/maintainer/update_header.sh index 3ee96133765..12e3e75ef79 100755 --- a/maintainer/update_header.sh +++ b/maintainer/update_header.sh @@ -66,4 +66,3 @@ for file in ${noproject_files}; do cat "${tmpfile}" > "${file}" done rm "${tmpfile}" - diff --git a/testsuite/cmake/BashUnitTests.sh b/testsuite/cmake/BashUnitTests.sh index ebf87c8a7d9..9b826861b45 100755 --- a/testsuite/cmake/BashUnitTests.sh +++ b/testsuite/cmake/BashUnitTests.sh @@ -117,11 +117,9 @@ function stderr() { ## If functions named `test_*` are already declared in the current environment, ## stop unit testing now. We don't want to run them and create side effects. function check_namespace() { - if [ ! -z "$(declare -F | sed -r 's/declare +-f +//' | grep -P '^test_')" ] - then + if [ ! -z "$(declare -F | sed -r 's/declare +-f +//' | grep -P '^test_')" ]; then stderr 'Functions named test_* already exist:' - for test in $(declare -F | sed -r 's/declare +-f +//' | grep -P "^test_") - do + for test in $(declare -F | sed -r 's/declare +-f +//' | grep -P "^test_"); do stderr " ${test}" done exit 1 @@ -153,8 +151,7 @@ check_namespace function detect_open_mpi() { if [ -z "${OMPI_COMM_WORLD_SIZE}" ] && [ -z "${OMPI_COMM_WORLD_RANK}" ] \ && [ -z "${OMPI_COMM_WORLD_LOCAL_RANK}" ] && [ -z "${OMPI_UNIVERSE_SIZE}" ] \ - && [ -z "${OMPI_COMM_WORLD_LOCAL_SIZE}" ] && [ -z "${OMPI_COMM_WORLD_NODE_RANK}" ] - then + && [ -z "${OMPI_COMM_WORLD_LOCAL_SIZE}" ] && [ -z "${OMPI_COMM_WORLD_NODE_RANK}" ]; then return 0 else error_log+=("Runtime error: cannot run this job from MPI, there is a conflict with") @@ -211,8 +208,7 @@ function try_catch_capture_output() { ## @brief Run the set_up() function if it exists ## @returns Error code returned by setUp() function run_set_up() { - if [ "$(type -t set_up)" = "function" ] - then + if [ "$(type -t set_up)" = "function" ]; then try_catch set_up local -r retcode=${?} if [ "${retcode}" -ne "0" ] @@ -228,12 +224,10 @@ function run_set_up() { ## @returns Error code returned by tear_down() function run_tear_down() { rm -f "${TMPNAME}" - if [ "$(type -t tear_down)" = "function" ] - then + if [ "$(type -t tear_down)" = "function" ]; then try_catch tear_down local retcode=${?} - if [ "${retcode}" -ne "0" ] - then + if [ "${retcode}" -ne "0" ]; then stderr "Failed to run tear_down()" exit ${retcode} fi @@ -243,8 +237,7 @@ function run_tear_down() { ## @brief Run the tests function run_tests() { - for test in $(declare -F | sed -r 's/declare +-f +//' | grep -P "^test_") - do + for test in $(declare -F | sed -r 's/declare +-f +//' | grep -P "^test_"); do start_test_block "${test#test_}" ${test} end_test_block @@ -282,8 +275,7 @@ function start_test_block() { ## Print a newline character and print all error messages in @ref error_log function end_test_block() { echo "" - for (( i=0; i<${#error_log[@]}; i++ )); - do + for (( i=0; i<${#error_log[@]}; i++ )); do stderr " ${error_log[i]}" done } @@ -319,8 +311,7 @@ function run_test_suite() { run_set_up run_tests run_tear_down - if [ "${error_counter}" -ne 0 ] - then + if [ "${error_counter}" -ne 0 ]; then stderr "Found ${error_counter} errors in ${total_tests} tests" exit 1 else @@ -341,12 +332,10 @@ function run_test_suite() { function assert_file_exists() { local -r filepath="${1}" local message="${2}" - if [ -z "${message}" ] - then + if [ -z "${message}" ]; then message="file not found: ${filepath}" fi - if [ -f "${filepath}" ] - then + if [ -f "${filepath}" ]; then log_success else log_failure "${message}" @@ -361,12 +350,10 @@ function assert_string_equal() { local -r result="${1}" local -r expected="${2}" local message="${3}" - if [ -z "${message}" ] - then + if [ -z "${message}" ]; then message="${result} != ${expected}" fi - if [ "${result}" = "${expected}" ] - then + if [ "${result}" = "${expected}" ]; then log_success else log_failure "${message}" @@ -381,12 +368,10 @@ function assert_equal() { local -r result="${1}" local -r expected="${2}" local message="${3}" - if [ -z "${message}" ] - then + if [ -z "${message}" ]; then message="${result} != ${expected}" fi - if [ "${result}" -eq "${expected}" ] - then + if [ "${result}" -eq "${expected}" ]; then log_success else log_failure "${message}" @@ -399,12 +384,10 @@ function assert_equal() { function assert_non_zero() { local -r result="${1}" local message="${2}" - if [ -z "${message}" ] - then + if [ -z "${message}" ]; then message="${result} == 0" fi - if [ "${result}" -ne "0" ] - then + if [ "${result}" -ne "0" ]; then log_success else log_failure "${message}" @@ -417,12 +400,10 @@ function assert_non_zero() { function assert_zero() { local -r result="${1}" local message="${2}" - if [ -z "${message}" ] - then + if [ -z "${message}" ]; then message="${result} != 0" fi - if [ "${result}" -eq "0" ] - then + if [ "${result}" -eq "0" ]; then log_success else log_failure "${message}" @@ -436,8 +417,7 @@ function assert_zero() { function assert_return_code() { try_catch_capture_output "${@}" local -r retcode=${?} - if [ "${retcode}" -eq "0" ] - then + if [ "${retcode}" -eq "0" ]; then log_success else local message="non-zero return code (${retcode}) for command \`$*\`" From 59e4438d6c731612b433cdc0b82e10ad326db8c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 18 Nov 2019 14:53:54 +0100 Subject: [PATCH 07/22] Fix script logic The original pattern wouldn't work if a filename was the suffix of another, e.g. `lb.py` would be marked as used in the CMakeLists.txt because of a match at the line `python_test(FILE engine_lb.py)`. The new pattern is also not a regular expression: the dot in the file extension doesn't match any character, only the dot character. --- maintainer/missing_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maintainer/missing_tests.sh b/maintainer/missing_tests.sh index a782e4fe87f..60c35721142 100755 --- a/maintainer/missing_tests.sh +++ b/maintainer/missing_tests.sh @@ -18,7 +18,7 @@ # for T in *.py; do - if grep -q "${T}" CMakeLists.txt; then + if grep -qF " ${T}" CMakeLists.txt; then continue else GIT_STATUS=$(git status --porcelain -- "${T}") From 8ba479cd47487b49a93211bc6d881c995391fac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 18 Nov 2019 15:47:43 +0100 Subject: [PATCH 08/22] Use POSIX grep Replace deprecated `egrep` by `grep -E`. shellcheck rule: SC2196 --- maintainer/files_with_header.sh | 18 +++++++++--------- maintainer/find_missing_header.sh | 8 ++++---- maintainer/update_header.sh | 8 ++++---- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/maintainer/files_with_header.sh b/maintainer/files_with_header.sh index 15d1a088e04..6537aeed4e2 100755 --- a/maintainer/files_with_header.sh +++ b/maintainer/files_with_header.sh @@ -18,12 +18,12 @@ # git ls-files --exclude-standard | -egrep -v '\.(blk|gz|data|dat|tab|chk|jpg|png|pdf|fig|gif|xcf|bib|vtf|vtk|svg|ico|eps)$' | -egrep -v '^testsuite/configs/|^old/|^cmake/|^libs/' | -egrep -v '(ChangeLog|AUTHORS|COPYING|NEWS|README|INSTALL)' | -egrep -v '(\.gitignore|pkgIndex\.tcl)' | -egrep -v '(config/config\.guess|config/config\.sub|config/install-sh)' | -egrep -v '(Doxyfile|latexmk\.1|latexmkrc|assemble_quickref\.awk|doc/misc/homepage/palette\.html)' | -egrep -v '(src/features\.def)' | -egrep -v '(featurelist)' | -egrep -v '(\.cproject|\.project|\.settings)' +grep -vE '\.(blk|gz|data|dat|tab|chk|jpg|png|pdf|fig|gif|xcf|bib|vtf|vtk|svg|ico|eps)$' | +grep -vE '^testsuite/configs/|^old/|^cmake/|^libs/' | +grep -vE '(ChangeLog|AUTHORS|COPYING|NEWS|README|INSTALL)' | +grep -vE '(\.gitignore|pkgIndex\.tcl)' | +grep -vE '(config/config\.guess|config/config\.sub|config/install-sh)' | +grep -vE '(Doxyfile|latexmk\.1|latexmkrc|assemble_quickref\.awk|doc/misc/homepage/palette\.html)' | +grep -vE '(src/features\.def)' | +grep -vE '(featurelist)' | +grep -vE '(\.cproject|\.project|\.settings)' diff --git a/maintainer/find_missing_header.sh b/maintainer/find_missing_header.sh index 953d35b4f16..ec5a525d999 100755 --- a/maintainer/find_missing_header.sh +++ b/maintainer/find_missing_header.sh @@ -27,12 +27,12 @@ current_year=$(date +%Y) echo "Examining ${num_files} files." echo -missing_current_copyright=$(egrep -IL "Copyright.*${current_year}" ${files}) +missing_current_copyright=$(grep -ILE "Copyright.*${current_year}" ${files}) echo "Copyright disclaimer missing the current year ${current_year}" echo "--------------------------------------------------" if [ -n "${missing_current_copyright}" ]; then - egrep -Il "Copyright" ${missing_current_copyright} + grep -IlE "Copyright" ${missing_current_copyright} else echo "NONE" fi @@ -41,7 +41,7 @@ echo echo "Missing copyright disclaimer" echo "----------------------------" if [ -n "${missing_current_copyright}" ]; then - egrep -IL "Copyright" ${missing_current_copyright} + grep -ILE "Copyright" ${missing_current_copyright} else echo "NONE" fi @@ -49,7 +49,7 @@ echo echo "Missing GPL/simple header" echo "-------------------------" -nolicense=$(egrep -IL "((ESPResSo|This program) is free software|Copying and distribution of this file)" ${files}) +nolicense=$(grep -ILE "((ESPResSo|This program) is free software|Copying and distribution of this file)" ${files}) if [ -n "${nolicense}" ]; then echo ${nolicense} else diff --git a/maintainer/update_header.sh b/maintainer/update_header.sh index 12e3e75ef79..e972e3bce57 100755 --- a/maintainer/update_header.sh +++ b/maintainer/update_header.sh @@ -34,17 +34,17 @@ current_year=$(date +%Y) echo "Examining ${num_files} files." echo "Files with copyright disclaimer(s)..." -files=$(egrep -l "Copyright" ${files}) +files=$(grep -lE "Copyright" ${files}) num_files=$(echo ${files} | wc -w) echo " ${num_files} files." echo "Files that are missing the current year (${current_year}) in the copyright disclaimer(s)..." -files=$(egrep -L "Copyright.*${current_year}" ${files}) +files=$(grep -LE "Copyright.*${current_year}" ${files}) for file in ${files}; do echo " ${file}" done -noyear_files=$(egrep -l "Copyright.*The ESPResSo project" ${files}) +noyear_files=$(grep -lE "Copyright.*The ESPResSo project" ${files}) echo " Adding current year to project copyright disclaimer..." echo " \"${current_year}\"" for file in ${noyear_files}; do @@ -52,7 +52,7 @@ for file in ${noyear_files}; do sed -i -r -e "s/Copyright \(C\) ([0-9,]*)(-20[0-9][0-9])? .*The ESPR/Copyright (C) \1-${current_year} The ESPR/" "${file}" done -noproject_files=$(egrep -L "Copyright.*The ESPResSo project" ${files}) +noproject_files=$(grep -LE "Copyright.*The ESPResSo project" ${files}) echo "Files that are missing the project copyright disclaimer..." num_files=$(echo ${noproject_files} | wc -w) echo " ${num_files} files." From b15e032f152b7e2ebf44b8a03de132e95cd266ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 18 Nov 2019 16:09:28 +0100 Subject: [PATCH 09/22] Remove inexistent files from patterns --- maintainer/files_with_header.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/maintainer/files_with_header.sh b/maintainer/files_with_header.sh index 6537aeed4e2..a1c5e743239 100755 --- a/maintainer/files_with_header.sh +++ b/maintainer/files_with_header.sh @@ -21,9 +21,8 @@ git ls-files --exclude-standard | grep -vE '\.(blk|gz|data|dat|tab|chk|jpg|png|pdf|fig|gif|xcf|bib|vtf|vtk|svg|ico|eps)$' | grep -vE '^testsuite/configs/|^old/|^cmake/|^libs/' | grep -vE '(ChangeLog|AUTHORS|COPYING|NEWS|README|INSTALL)' | -grep -vE '(\.gitignore|pkgIndex\.tcl)' | -grep -vE '(config/config\.guess|config/config\.sub|config/install-sh)' | +grep -vE '(\.gitignore)' | grep -vE '(Doxyfile|latexmk\.1|latexmkrc|assemble_quickref\.awk|doc/misc/homepage/palette\.html)' | -grep -vE '(src/features\.def)' | +grep -vE '(src/config/features\.def)' | grep -vE '(featurelist)' | grep -vE '(\.cproject|\.project|\.settings)' From 96c7fedb5a0394e8b332d350613fb29405c75d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 18 Nov 2019 16:11:08 +0100 Subject: [PATCH 10/22] Add new files in patterns --- maintainer/files_with_header.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/maintainer/files_with_header.sh b/maintainer/files_with_header.sh index a1c5e743239..5e56fc95e72 100755 --- a/maintainer/files_with_header.sh +++ b/maintainer/files_with_header.sh @@ -18,10 +18,11 @@ # git ls-files --exclude-standard | -grep -vE '\.(blk|gz|data|dat|tab|chk|jpg|png|pdf|fig|gif|xcf|bib|vtf|vtk|svg|ico|eps)$' | +grep -vE '\.(blk|gz|npz|data|dat|tab|chk|jpg|png|pdf|fig|gif|xcf|css|bib|vtf|vtk|svg|ico|eps|rst|ipynb)$' | grep -vE '^testsuite/configs/|^old/|^cmake/|^libs/' | grep -vE '(ChangeLog|AUTHORS|COPYING|NEWS|README|INSTALL)' | -grep -vE '(\.gitignore)' | +grep -vE '(\.gitmodules|\.github|\.gitignore|\.codecov\.yml|\.gitlab-ci\.yml|\.travis\.yml|bors\.toml)' | +grep -vE '(\.clang-format|\.clang-tidy|\.pylintrc|tools/ubsan-suppressions\.txt)' | grep -vE '(Doxyfile|latexmk\.1|latexmkrc|assemble_quickref\.awk|doc/misc/homepage/palette\.html)' | grep -vE '(src/config/features\.def)' | grep -vE '(featurelist)' | From 6d1aafcc2de5bde54ece86f59ebef05ed205289a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 18 Nov 2019 16:11:50 +0100 Subject: [PATCH 11/22] Fix broken stdout --- maintainer/find_missing_header.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/maintainer/find_missing_header.sh b/maintainer/find_missing_header.sh index ec5a525d999..8fd55b32347 100755 --- a/maintainer/find_missing_header.sh +++ b/maintainer/find_missing_header.sh @@ -1,4 +1,4 @@ -#! /bin/bash -x +#!/bin/bash # Copyright (C) 2012-2019 The ESPResSo project # Copyright (C) 2012 Olaf Lenz # @@ -51,7 +51,7 @@ echo "Missing GPL/simple header" echo "-------------------------" nolicense=$(grep -ILE "((ESPResSo|This program) is free software|Copying and distribution of this file)" ${files}) if [ -n "${nolicense}" ]; then - echo ${nolicense} + ls -1 ${nolicense} else echo "NONE" fi From d744ba165666ce79c6430fa0c72c097de0bfd5ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 18 Nov 2019 16:44:19 +0100 Subject: [PATCH 12/22] Fix broken script --- maintainer/update_header.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/maintainer/update_header.sh b/maintainer/update_header.sh index e972e3bce57..6c77c48aba1 100755 --- a/maintainer/update_header.sh +++ b/maintainer/update_header.sh @@ -34,23 +34,23 @@ current_year=$(date +%Y) echo "Examining ${num_files} files." echo "Files with copyright disclaimer(s)..." -files=$(grep -lE "Copyright" ${files}) -num_files=$(echo ${files} | wc -w) +disclaimer_files=$(grep -lE "Copyright" ${files}) +num_files=$(echo ${disclaimer_files} | wc -w) echo " ${num_files} files." echo "Files that are missing the current year (${current_year}) in the copyright disclaimer(s)..." -files=$(grep -LE "Copyright.*${current_year}" ${files}) -for file in ${files}; do - echo " ${file}" -done - -noyear_files=$(grep -lE "Copyright.*The ESPResSo project" ${files}) -echo " Adding current year to project copyright disclaimer..." -echo " \"${current_year}\"" -for file in ${noyear_files}; do - echo " ${file}" - sed -i -r -e "s/Copyright \(C\) ([0-9,]*)(-20[0-9][0-9])? .*The ESPR/Copyright (C) \1-${current_year} The ESPR/" "${file}" -done +noyear_files=$(grep -LE "Copyright.*${current_year}" ${disclaimer_files}) +if [ ! -z "${noyear_files}" ]; then + for file in ${noyear_files}; do + echo " ${file}" + done + noyear_files=$(grep -lE "Copyright.*The ESPResSo project" ${noyear_files}) + echo " Adding current year to project copyright disclaimer..." + for file in ${noyear_files}; do + echo " ${file}" + sed -i -r -e "s/Copyright \(C\) ([0-9,]*)(-20[0-9][0-9])? .*The ESPR/Copyright (C) \1-${current_year} The ESPR/" "${file}" + done +fi noproject_files=$(grep -LE "Copyright.*The ESPResSo project" ${files}) echo "Files that are missing the project copyright disclaimer..." From 984b061645a80f5e184eabf077a43ffddb0c26b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 18 Nov 2019 16:44:40 +0100 Subject: [PATCH 13/22] Update shebangs Add a shebang in all shell scripts. Downgrade shebangs from Bash to Dash (sh) in small scripts that don't use Bash-specific syntax. Use the most portable shebang (`#!/usr/bin/env `) to include the user $PATH in the search path. shellcheck rule: SC2148 --- maintainer/CI/build_docker.sh | 2 +- maintainer/CI/fix_style.sh | 5 +++-- maintainer/add_missing_headers.sh | 2 +- maintainer/benchmarks/runner.sh | 2 +- maintainer/benchmarks/suite.sh | 2 +- maintainer/files_with_header.sh | 1 + maintainer/find_missing_header.sh | 4 ++-- maintainer/find_potentially_missing_authors.sh | 1 + maintainer/missing_tests.sh | 2 +- maintainer/update_header.sh | 3 ++- 10 files changed, 14 insertions(+), 10 deletions(-) diff --git a/maintainer/CI/build_docker.sh b/maintainer/CI/build_docker.sh index 229fb13df6c..37e0274820c 100755 --- a/maintainer/CI/build_docker.sh +++ b/maintainer/CI/build_docker.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (C) 2016-2019 The ESPResSo project # # This file is part of ESPResSo. diff --git a/maintainer/CI/fix_style.sh b/maintainer/CI/fix_style.sh index 08145f2835c..2bb314b5a70 100755 --- a/maintainer/CI/fix_style.sh +++ b/maintainer/CI/fix_style.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env sh # Copyright (C) 2018-2019 The ESPResSo project # # This file is part of ESPResSo. @@ -40,7 +40,8 @@ fi AUTOPEP8="$(which autopep8)" if ! "${AUTOPEP8}" --version 2>&1 | grep -qFo "autopep8 ${AUTOPEP8_VER} (pycodestyle: ${PYCODESTYLE_VER})"; then - echo -e "Could not find autopep8 ${AUTOPEP8_VER} with pycodestyle ${PYCODESTYLE_VER}\n${AUTOPEP8} is $(${AUTOPEP8} --version 2>&1)" + echo "Could not find autopep8 ${AUTOPEP8_VER} with pycodestyle ${PYCODESTYLE_VER}" + echo "${AUTOPEP8} is $(${AUTOPEP8} --version 2>&1)" exit 2 fi diff --git a/maintainer/add_missing_headers.sh b/maintainer/add_missing_headers.sh index f3145bfa216..5e70563d01b 100755 --- a/maintainer/add_missing_headers.sh +++ b/maintainer/add_missing_headers.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh # Copyright (C) 2018-2019 The ESPResSo project # # This file is part of ESPResSo. diff --git a/maintainer/benchmarks/runner.sh b/maintainer/benchmarks/runner.sh index bbd9a34cfc8..d27ba956488 100644 --- a/maintainer/benchmarks/runner.sh +++ b/maintainer/benchmarks/runner.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (C) 2018-2019 The ESPResSo project # # This file is part of ESPResSo. diff --git a/maintainer/benchmarks/suite.sh b/maintainer/benchmarks/suite.sh index d17216efeda..569c439d70c 100644 --- a/maintainer/benchmarks/suite.sh +++ b/maintainer/benchmarks/suite.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (C) 2018-2019 The ESPResSo project # # This file is part of ESPResSo. diff --git a/maintainer/files_with_header.sh b/maintainer/files_with_header.sh index 5e56fc95e72..8b82a92cd03 100755 --- a/maintainer/files_with_header.sh +++ b/maintainer/files_with_header.sh @@ -1,3 +1,4 @@ +#!/usr/bin/env sh # Copyright (C) 2012-2019 The ESPResSo project # Copyright (C) 2012 Olaf Lenz # diff --git a/maintainer/find_missing_header.sh b/maintainer/find_missing_header.sh index 8fd55b32347..6147bdc802b 100755 --- a/maintainer/find_missing_header.sh +++ b/maintainer/find_missing_header.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (C) 2012-2019 The ESPResSo project # Copyright (C) 2012 Olaf Lenz # @@ -20,7 +20,7 @@ # check for missing GPL and copyright headers # -files=$(sh maintainer/files_with_header.sh) +files=$(maintainer/files_with_header.sh) num_files=$(echo ${files} | wc -w) current_year=$(date +%Y) diff --git a/maintainer/find_potentially_missing_authors.sh b/maintainer/find_potentially_missing_authors.sh index 6d5e534603a..de20a0c6b7d 100755 --- a/maintainer/find_potentially_missing_authors.sh +++ b/maintainer/find_potentially_missing_authors.sh @@ -1,3 +1,4 @@ +#!/usr/bin/env sh # Copyright (C) 2019 The ESPResSo project # # This file is part of ESPResSo. diff --git a/maintainer/missing_tests.sh b/maintainer/missing_tests.sh index 60c35721142..bcaa9999640 100755 --- a/maintainer/missing_tests.sh +++ b/maintainer/missing_tests.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (C) 2017-2019 The ESPResSo project # # This file is part of ESPResSo. diff --git a/maintainer/update_header.sh b/maintainer/update_header.sh index 6c77c48aba1..8dd07f7e021 100755 --- a/maintainer/update_header.sh +++ b/maintainer/update_header.sh @@ -1,3 +1,4 @@ +#!/usr/bin/env sh # Copyright (C) 2018-2019 The ESPResSo project # Copyright (C) 2012,2013,2014 Olaf Lenz # @@ -27,7 +28,7 @@ # # To review the diff: # $> git diff --word-diff-regex=. -U0 | grep -Po 'Copyright.+' | sort | uniq -files=$(sh maintainer/files_with_header.sh) +files=$(maintainer/files_with_header.sh) num_files=$(echo ${files} | wc -w) current_year=$(date +%Y) From 5b058332ca060bc17f4652276b68915f1c373c20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 18 Nov 2019 17:08:30 +0100 Subject: [PATCH 14/22] Remove superfluous `echo` and `cat` shellcheck rules: SC2002 SC2116 --- maintainer/CI/doc_warnings.sh | 2 +- maintainer/CI/fix_style.sh | 2 +- maintainer/add_missing_headers.sh | 4 ++-- maintainer/gh_create_issue.sh | 2 +- maintainer/gh_post_status.sh | 2 +- testsuite/cmake/BashUnitTests.sh | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/maintainer/CI/doc_warnings.sh b/maintainer/CI/doc_warnings.sh index 5beb8c988a1..05deb855fda 100755 --- a/maintainer/CI/doc_warnings.sh +++ b/maintainer/CI/doc_warnings.sh @@ -88,7 +88,7 @@ if [ "${?}" = "0" ]; then echo "${filepath_html}:\`${reference}\`" | tee -a doc_warnings.log~ done # generate log file - n_warnings=$(cat doc_warnings.log~ | wc -l) + n_warnings=$(wc -l < doc_warnings.log~) echo "The Sphinx documentation contains ${n_warnings} broken links:" > doc_warnings.log cat doc_warnings.log~ >> doc_warnings.log rm doc_warnings.log~ diff --git a/maintainer/CI/fix_style.sh b/maintainer/CI/fix_style.sh index 2bb314b5a70..b1b48bb7d2f 100755 --- a/maintainer/CI/fix_style.sh +++ b/maintainer/CI/fix_style.sh @@ -78,7 +78,7 @@ pylint_command () { fi } pylint_command --score=no --reports=no --output-format=text src doc maintainer testsuite samples | tee pylint.log -errors=$(grep -P '^[a-z]+/.+?.py:[0-9]+:[0-9]+: [CRWEF][0-9]+:' pylint.log | wc -l) +errors=$(grep -Pc '^[a-z]+/.+?.py:[0-9]+:[0-9]+: [CRWEF][0-9]+:' pylint.log) if [ "${CI}" != "" ]; then maintainer/gh_post_pylint.py "${errors}" pylint.log || exit 1 diff --git a/maintainer/add_missing_headers.sh b/maintainer/add_missing_headers.sh index 5e70563d01b..09c889ba560 100755 --- a/maintainer/add_missing_headers.sh +++ b/maintainer/add_missing_headers.sh @@ -27,7 +27,7 @@ cpp_files=$(echo ${files_to_check} | tr " " "\n" | grep -P '\.([c|h]pp|cuh?|dox) tmp=$(mktemp) # process python/cython/bash files -for f in $(echo ${py_files}); do +for f in ${py_files}; do head -n1 "${f}" | grep -q '^#!' if [ "${?}" = 0 ]; then # preserve shebang on first line @@ -40,7 +40,7 @@ for f in $(echo ${py_files}); do cp "${tmp}" "${f}" done # process c++/cuda/doxygen files -for f in $(echo ${cpp_files}); do +for f in ${cpp_files}; do (echo '/*' sed -e 's/^/ * /' maintainer/header_template.txt | sed 's/ $//' echo ' */' diff --git a/maintainer/gh_create_issue.sh b/maintainer/gh_create_issue.sh index 58d20f398da..a0e778ae678 100755 --- a/maintainer/gh_create_issue.sh +++ b/maintainer/gh_create_issue.sh @@ -17,7 +17,7 @@ # along with this program. If not, see . # -URL=$(echo "https://gitlab.icp.uni-stuttgart.de/espressomd/espresso/pipelines/${CI_PIPELINE_ID}") +URL="https://gitlab.icp.uni-stuttgart.de/espressomd/espresso/pipelines/${CI_PIPELINE_ID}" curl -s "https://api.github.com/repos/espressomd/espresso/issues" \ -H "Accept: application/vnd.github.full+json" \ diff --git a/maintainer/gh_post_status.sh b/maintainer/gh_post_status.sh index e09eaf20530..39c36c37e24 100755 --- a/maintainer/gh_post_status.sh +++ b/maintainer/gh_post_status.sh @@ -20,7 +20,7 @@ [ "${#}" -eq 1 ] || exit -1 GIT_COMMIT=$(git rev-parse HEAD) -URL=$(echo "https://gitlab.icp.uni-stuttgart.de/espressomd/espresso/pipelines/${CI_PIPELINE_ID}") +URL="https://gitlab.icp.uni-stuttgart.de/espressomd/espresso/pipelines/${CI_PIPELINE_ID}" STATUS="${1}" curl "https://api.github.com/repos/espressomd/espresso/statuses/${GIT_COMMIT}?access_token=${GITHUB_TOKEN}" \ -H "Content-Type: application/json" \ diff --git a/testsuite/cmake/BashUnitTests.sh b/testsuite/cmake/BashUnitTests.sh index 9b826861b45..cee9b228e50 100755 --- a/testsuite/cmake/BashUnitTests.sh +++ b/testsuite/cmake/BashUnitTests.sh @@ -420,8 +420,8 @@ function assert_return_code() { if [ "${retcode}" -eq "0" ]; then log_success else - local message="non-zero return code (${retcode}) for command \`$*\`" - local logfile=$(cat "${TMPNAME}" | sed 's/^/ /') + local -r message="non-zero return code (${retcode}) for command \`$*\`" + local -r logfile=$(sed 's/^/ /' < "${TMPNAME}") log_failure "${message}"$'\n'"${logfile}" fi } From f23cb30b071d1ebe30b159856d3d8b8ce03210b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 18 Nov 2019 17:11:12 +0100 Subject: [PATCH 15/22] Properly escape globs in `grep` and `find` shellcheck rules: SC2061 SC2063 --- maintainer/CI/build_cmake.sh | 2 +- maintainer/CI/doc_warnings.sh | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/maintainer/CI/build_cmake.sh b/maintainer/CI/build_cmake.sh index c08d54e5a73..3131329282b 100755 --- a/maintainer/CI/build_cmake.sh +++ b/maintainer/CI/build_cmake.sh @@ -242,7 +242,7 @@ end "BUILD" # check for exit function, which should never be called from shared library # can't do this on CUDA though because nvcc creates a host function that just calls exit for each device function if [ "${with_cuda}" = false ] || [ "$(echo ${NVCC} | grep -o clang)" = "clang" ]; then - if nm -o -C $(find . -name *.so) | grep '[^a-z]exit@@GLIBC'; then + if nm -o -C $(find . -name '*.so') | grep '[^a-z]exit@@GLIBC'; then echo "Found calls to exit() function in shared libraries." exit 1 fi diff --git a/maintainer/CI/doc_warnings.sh b/maintainer/CI/doc_warnings.sh index 05deb855fda..7b8bda198bd 100755 --- a/maintainer/CI/doc_warnings.sh +++ b/maintainer/CI/doc_warnings.sh @@ -37,12 +37,12 @@ if [ ! -f doc/sphinx/html/index.html ]; then fi n_warnings=0 -grep -qrP --include \*.html --exclude-dir=_modules "${regex_sphinx_broken_link}" doc/sphinx/html/ +grep -qrP --include='*.html' --exclude-dir=_modules "${regex_sphinx_broken_link}" doc/sphinx/html/ if [ "${?}" = "0" ]; then rm -f doc_warnings.log~ touch doc_warnings.log~ found="false" - grep -rPno --include \*.html --exclude-dir=_modules "${regex_sphinx_broken_link}" doc/sphinx/html/ | sort | uniq | while read -r line; do + grep -rPno --include='*.html' --exclude-dir=_modules "${regex_sphinx_broken_link}" doc/sphinx/html/ | sort | uniq | while read -r line; do # extract link target reference=$(echo "${line}" | sed -r 's|^.+(.+)$|\1|' | sed 's/()$//') # skip if broken link refers to a standard Python type or to a @@ -100,10 +100,10 @@ fi # * incorrect syntax, e.g. "obj:float:" # * incorrect numpydoc syntax, e.g. ":rtype:`float`" # They are difficult to predict, so we leave them to the user's discretion -grep -qrP --include \*.html --exclude-dir=_modules '(:py)?:[a-z]+:' doc/sphinx/html/ +grep -qrP --include='*.html' --exclude-dir=_modules '(:py)?:[a-z]+:' doc/sphinx/html/ if [ "${?}" = "0" ]; then echo "Possibly errors:" - grep -rP --color --include \*.html --exclude-dir=_modules '(:py)?:[a-z]+:' doc/sphinx/html/ + grep -rP --color --include='*.html' --exclude-dir=_modules '(:py)?:[a-z]+:' doc/sphinx/html/ fi if [ "${CI}" != "" ]; then From 176b6bdc5da91ec66d70cdecb8db7e2dbe2cec19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 18 Nov 2019 17:46:14 +0100 Subject: [PATCH 16/22] Run scripts in root directory --- maintainer/add_missing_headers.sh | 2 +- maintainer/find_potentially_missing_authors.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/maintainer/add_missing_headers.sh b/maintainer/add_missing_headers.sh index 09c889ba560..d4ab978599d 100755 --- a/maintainer/add_missing_headers.sh +++ b/maintainer/add_missing_headers.sh @@ -17,7 +17,7 @@ # along with this program. If not, see . # -# This needs to be run from the top-level directory +cd "$(git rev-parse --show-toplevel)" # Get files without headers all_files=$(maintainer/files_with_header.sh) diff --git a/maintainer/find_potentially_missing_authors.sh b/maintainer/find_potentially_missing_authors.sh index de20a0c6b7d..0ee4ca18ac5 100755 --- a/maintainer/find_potentially_missing_authors.sh +++ b/maintainer/find_potentially_missing_authors.sh @@ -21,7 +21,7 @@ # based on git commits. The output has to be checked manually, because # users have committed under different spellings and abbreviations. -# This has to be run from the root directory of the source tree +cd "$(git rev-parse --show-toplevel)" git log | grep -i ^author | From 6a5d4a323f521c8bc2bc3240ef54493e08cfca39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 18 Nov 2019 17:54:53 +0100 Subject: [PATCH 17/22] Document shell scripts --- maintainer/add_missing_headers.sh | 4 +++- maintainer/files_with_header.sh | 4 +++- maintainer/find_missing_header.sh | 6 +++--- maintainer/find_potentially_missing_authors.sh | 2 +- maintainer/gh_close_issue.sh | 1 - maintainer/gh_create_issue.sh | 1 - maintainer/gh_post_pylint.py | 1 - maintainer/gh_post_status.sh | 1 - maintainer/gh_post_style_patch.py | 1 - maintainer/git2changelog.py | 2 +- maintainer/missing_tests.sh | 5 ++++- maintainer/update_header.sh | 4 +++- 12 files changed, 18 insertions(+), 14 deletions(-) diff --git a/maintainer/add_missing_headers.sh b/maintainer/add_missing_headers.sh index d4ab978599d..46deedc892f 100755 --- a/maintainer/add_missing_headers.sh +++ b/maintainer/add_missing_headers.sh @@ -15,7 +15,9 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# + + +# Add copyright header to C++, CUDA, Doxygen, Python and shell files. cd "$(git rev-parse --show-toplevel)" diff --git a/maintainer/files_with_header.sh b/maintainer/files_with_header.sh index 8b82a92cd03..799eaa31cbe 100755 --- a/maintainer/files_with_header.sh +++ b/maintainer/files_with_header.sh @@ -16,7 +16,9 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# + + +# List all files that are eligible for a copyright header. git ls-files --exclude-standard | grep -vE '\.(blk|gz|npz|data|dat|tab|chk|jpg|png|pdf|fig|gif|xcf|css|bib|vtf|vtk|svg|ico|eps|rst|ipynb)$' | diff --git a/maintainer/find_missing_header.sh b/maintainer/find_missing_header.sh index 6147bdc802b..73fe7f60711 100755 --- a/maintainer/find_missing_header.sh +++ b/maintainer/find_missing_header.sh @@ -16,9 +16,9 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# -# check for missing GPL and copyright headers -# + + +# Check for missing GPL and copyright headers files=$(maintainer/files_with_header.sh) num_files=$(echo ${files} | wc -w) diff --git a/maintainer/find_potentially_missing_authors.sh b/maintainer/find_potentially_missing_authors.sh index 0ee4ca18ac5..2475155e8a2 100755 --- a/maintainer/find_potentially_missing_authors.sh +++ b/maintainer/find_potentially_missing_authors.sh @@ -15,7 +15,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# + # This gets a tentative list of authors that are missing from the AUTHORS file # based on git commits. The output has to be checked manually, because diff --git a/maintainer/gh_close_issue.sh b/maintainer/gh_close_issue.sh index 2b44dcf072a..98fb85325c4 100755 --- a/maintainer/gh_close_issue.sh +++ b/maintainer/gh_close_issue.sh @@ -15,7 +15,6 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# ISSUE_NUMBER=$(curl -s -G https://api.github.com/search/issues \ --data-urlencode "q=\"CI failed for merged PR\" org:espressomd repo:espresso is:open is:issue in:title" \ diff --git a/maintainer/gh_create_issue.sh b/maintainer/gh_create_issue.sh index a0e778ae678..38253e23903 100755 --- a/maintainer/gh_create_issue.sh +++ b/maintainer/gh_create_issue.sh @@ -15,7 +15,6 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# URL="https://gitlab.icp.uni-stuttgart.de/espressomd/espresso/pipelines/${CI_PIPELINE_ID}" diff --git a/maintainer/gh_post_pylint.py b/maintainer/gh_post_pylint.py index 9852f23b9b8..32ee34a96c8 100755 --- a/maintainer/gh_post_pylint.py +++ b/maintainer/gh_post_pylint.py @@ -16,7 +16,6 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# import re import os diff --git a/maintainer/gh_post_status.sh b/maintainer/gh_post_status.sh index 39c36c37e24..2580fe68105 100755 --- a/maintainer/gh_post_status.sh +++ b/maintainer/gh_post_status.sh @@ -15,7 +15,6 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# [ "${#}" -eq 1 ] || exit -1 diff --git a/maintainer/gh_post_style_patch.py b/maintainer/gh_post_style_patch.py index 5734d79a216..a32756e9cff 100755 --- a/maintainer/gh_post_style_patch.py +++ b/maintainer/gh_post_style_patch.py @@ -16,7 +16,6 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# import os import requests diff --git a/maintainer/git2changelog.py b/maintainer/git2changelog.py index 6500c6a528a..7b5698f63f8 100755 --- a/maintainer/git2changelog.py +++ b/maintainer/git2changelog.py @@ -15,7 +15,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# + import re import os diff --git a/maintainer/missing_tests.sh b/maintainer/missing_tests.sh index bcaa9999640..4d5c977af5e 100755 --- a/maintainer/missing_tests.sh +++ b/maintainer/missing_tests.sh @@ -15,7 +15,10 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# + + +# Detect python tests that are not included in CMakeLists.txt. Run this script +# in the folders for python, sample, tutorial and benchmark testsuite folders. for T in *.py; do if grep -qF " ${T}" CMakeLists.txt; then diff --git a/maintainer/update_header.sh b/maintainer/update_header.sh index 8dd07f7e021..4bd5936e6df 100755 --- a/maintainer/update_header.sh +++ b/maintainer/update_header.sh @@ -16,7 +16,8 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# + + # Add current year to copyright header # # 1. Find files that do have copyright disclaimers @@ -28,6 +29,7 @@ # # To review the diff: # $> git diff --word-diff-regex=. -U0 | grep -Po 'Copyright.+' | sort | uniq + files=$(maintainer/files_with_header.sh) num_files=$(echo ${files} | wc -w) current_year=$(date +%Y) From c36e2bf9cfb6850f09d40759344fe4aa6d1d54e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 18 Nov 2019 17:57:31 +0100 Subject: [PATCH 18/22] Add copyright headers --- doc/sphinx/samples.py | 17 +++++++++++++++++ src/utils/include/utils/mask.hpp | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/doc/sphinx/samples.py b/doc/sphinx/samples.py index 79e1215411d..3ed7daec374 100644 --- a/doc/sphinx/samples.py +++ b/doc/sphinx/samples.py @@ -1,3 +1,20 @@ +# Copyright (C) 2019 The ESPResSo project +# +# This file is part of ESPResSo. +# +# ESPResSo is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ESPResSo is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + import os import ast import textwrap diff --git a/src/utils/include/utils/mask.hpp b/src/utils/include/utils/mask.hpp index 64bc1c78985..76f374b2b36 100644 --- a/src/utils/include/utils/mask.hpp +++ b/src/utils/include/utils/mask.hpp @@ -1,3 +1,21 @@ +/* + * Copyright (C) 2019 The ESPResSo project + * + * This file is part of ESPResSo. + * + * ESPResSo is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ESPResSo is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #ifndef ESPRESSO_MASK_HPP #define ESPRESSO_MASK_HPP From df1758a50c70ad57c73eb35226212ef41d2ed493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 18 Nov 2019 18:10:18 +0100 Subject: [PATCH 19/22] Run unit tests on all operating systems Separate unit tests from python tests. Run unit tests on Fedora, Debian and OpenSUSE. --- .gitlab-ci.yml | 22 +++++++++++----------- maintainer/CI/build_cmake.sh | 15 ++++++++++----- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 21d00c80e5c..7f8cd5298b0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -132,7 +132,7 @@ debian:10: image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/debian-python3:10 script: - export with_cuda=false - - export myconfig=maxset make_check=false + - export myconfig=maxset make_check_python=false - bash maintainer/CI/build_cmake.sh tags: - docker @@ -143,7 +143,7 @@ opensuse:15.1: stage: build image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/$CI_JOB_NAME script: - - export with_cuda=false myconfig=maxset make_check=false + - export with_cuda=false myconfig=maxset make_check_python=false - bash maintainer/CI/build_cmake.sh tags: - docker @@ -154,7 +154,7 @@ centos:7: stage: build image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/centos-python3:7 script: - - export with_cuda=false myconfig=maxset make_check=true + - export with_cuda=false myconfig=maxset make_check_python=true - bash maintainer/CI/build_cmake.sh tags: - docker @@ -165,7 +165,7 @@ fedora: stage: build image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/centos-python3:next script: - - export with_cuda=false myconfig=maxset make_check=false + - export with_cuda=false myconfig=maxset make_check_python=false - bash maintainer/CI/build_cmake.sh tags: - docker @@ -217,7 +217,7 @@ tutorials-samples-maxset: stage: build image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/ubuntu-python3:cuda-10.1 script: - - export myconfig=maxset with_coverage=false make_check=false + - export myconfig=maxset with_coverage=false make_check_unit_tests=false make_check_python=false - export make_check_tutorials=true make_check_samples=true make_check_benchmarks=true test_timeout=1200 - bash maintainer/CI/build_cmake.sh tags: @@ -230,7 +230,7 @@ tutorials-samples-default: stage: build image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/ubuntu-python3:cuda-10.1 script: - - export myconfig=default with_coverage=false make_check=false + - export myconfig=default with_coverage=false make_check_unit_tests=false make_check_python=false - export make_check_tutorials=true make_check_samples=true make_check_benchmarks=true test_timeout=1200 - bash maintainer/CI/build_cmake.sh tags: @@ -245,7 +245,7 @@ tutorials-samples-empty: stage: build image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/ubuntu-python3:cuda-10.1 script: - - export myconfig=empty with_coverage=false make_check=false + - export myconfig=empty with_coverage=false make_check_unit_tests=false make_check_python=false - export make_check_tutorials=true make_check_samples=true make_check_benchmarks=true test_timeout=1200 with_scafacos=false - bash maintainer/CI/build_cmake.sh tags: @@ -260,7 +260,7 @@ tutorials-samples-no-gpu: stage: build image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/ubuntu-python3:cuda-10.1 script: - - export myconfig=maxset with_coverage=false make_check=false + - export myconfig=maxset with_coverage=false make_check_unit_tests=false make_check_python=false - export make_check_tutorials=true make_check_samples=true make_check_benchmarks=true test_timeout=1200 hide_gpu=true - bash maintainer/CI/build_cmake.sh tags: @@ -274,7 +274,7 @@ installation: stage: build image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/ubuntu-python3:cuda-10.1 script: - - export myconfig=maxset with_coverage=false make_check=false + - export myconfig=maxset with_coverage=false make_check_unit_tests=false make_check_python=false - export srcdir=${CI_PROJECT_DIR} test_timeout=1800 - bash maintainer/CI/build_cmake.sh - cd build @@ -317,7 +317,7 @@ ubuntu:wo-dependencies: stage: build image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/ubuntu-python3:wo-dependencies script: - - export myconfig=maxset make_check=false + - export myconfig=maxset make_check_unit_tests=false make_check_python=false - bash maintainer/CI/build_cmake.sh tags: - docker @@ -388,7 +388,7 @@ osx-cuda: <<: *global_job_definition stage: build script: - - export with_ccache=false myconfig=maxset with_cuda=true make_check=false + - export with_ccache=false myconfig=maxset with_cuda=true make_check_unit_tests=false make_check_python=false - bash maintainer/CI/build_cmake.sh tags: - mac diff --git a/maintainer/CI/build_cmake.sh b/maintainer/CI/build_cmake.sh index 3131329282b..b101f6b02cd 100755 --- a/maintainer/CI/build_cmake.sh +++ b/maintainer/CI/build_cmake.sh @@ -87,10 +87,11 @@ set_default_value with_static_analysis false set_default_value myconfig "default" set_default_value build_procs 2 set_default_value check_procs ${build_procs} -set_default_value make_check true set_default_value check_odd_only false set_default_value check_gpu_only false set_default_value check_skip_long false +set_default_value make_check_unit_tests true +set_default_value make_check_python true set_default_value make_check_tutorials false set_default_value make_check_samples false set_default_value make_check_benchmarks false @@ -101,7 +102,7 @@ set_default_value with_scafacos true set_default_value test_timeout 300 set_default_value hide_gpu false -if [ "${make_check}" = true ] || [ "${make_check_tutorials}" = true ] || [ "${make_check_samples}" = true ] || [ "${make_check_benchmarks}" = true ]; then +if [ "${make_check_unit_tests}" = true ] || [ "${make_check_python}" = true ] || [ "${make_check_tutorials}" = true ] || [ "${make_check_samples}" = true ] || [ "${make_check_benchmarks}" = true ]; then run_checks=true else run_checks=false @@ -153,7 +154,7 @@ elif [ -z "${builddir}" ]; then fi outp insource srcdir builddir \ - make_check make_check_tutorials make_check_samples make_check_benchmarks \ + make_check_unit_tests make_check_python make_check_tutorials make_check_samples make_check_benchmarks \ cmake_params with_fftw \ with_python_interface with_coverage \ with_ubsan with_asan \ @@ -251,9 +252,13 @@ fi if [ "${run_checks}" = true ]; then start "TEST" - # unit tests and integration tests - if [ "${make_check}" = true ]; then + # unit tests + if [ "${make_check_unit_tests}" = true ]; then make -j${build_procs} check_unit_tests ${make_params} || exit 1 + fi + + # integration tests + if [ "${make_check_python}" = true ]; then if [ -z "${run_tests}" ]; then if [ "${check_odd_only}" = true ]; then make -j${build_procs} check_python_parallel_odd ${make_params} || exit 1 From 0f11fccc58883344e3f2349ae3225b616c585fcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Tue, 19 Nov 2019 13:27:27 +0100 Subject: [PATCH 20/22] Use POSIX syntax Reduce bashisms. Downgrade shebangs from Bash to Dash (sh) in POSIX-compliant shell scripts. Use the most portable shebang (`#!/usr/bin/env `) to include the user $PATH in the search path. --- maintainer/CI/build_cmake.sh | 17 +++++++------- maintainer/CI/dox_warnings.sh | 2 +- maintainer/benchmarks/suite.sh | 6 ++--- maintainer/find_missing_header.sh | 2 +- maintainer/gh_close_issue.sh | 2 +- maintainer/gh_create_issue.sh | 2 +- maintainer/gh_post_status.sh | 2 +- maintainer/missing_tests.sh | 8 +++---- src/python/pypresso.cmakein | 2 +- testsuite/cmake/BashUnitTests.sh | 38 +++++++++++++++---------------- 10 files changed, 40 insertions(+), 41 deletions(-) diff --git a/maintainer/CI/build_cmake.sh b/maintainer/CI/build_cmake.sh index b101f6b02cd..3252674cc8f 100755 --- a/maintainer/CI/build_cmake.sh +++ b/maintainer/CI/build_cmake.sh @@ -7,8 +7,7 @@ # notice and this notice are preserved. This file is offered as-is, # without any warranty. -abort() -{ +abort() { echo "An error occurred. Exiting..." >&2 echo "Command that failed: ${BASH_COMMAND}" >&2 exit 1 @@ -20,21 +19,21 @@ set -e # HELPER FUNCTIONS # output value of env variables -function outp { +outp() { for p in ${*}; do echo " ${p}=${!p}" done } # start a block -function start { +start() { echo "==================================================" echo "START ${1}" echo "==================================================" } # end a block -function end { +end() { echo "==================================================" echo "END ${1}" echo "==================================================" @@ -42,7 +41,7 @@ function end { # set a default value to empty environment variables # cast boolean values to true/false -function set_default_value { +set_default_value() { if [ "${#}" != 2 ]; then echo "set_default_value() takes 2 arguments (varname, default), got ${#}" exit 1 @@ -127,7 +126,7 @@ if [ -z "${cxx_flags}" ]; then fi if [ "${with_coverage}" = true ]; then - bash <(curl -s https://codecov.io/env) &> /dev/null + bash <(curl -s https://codecov.io/env) 1>/dev/null 2>&1 fi cmake_params="-DCMAKE_BUILD_TYPE=${build_type} -DWARNINGS_ARE_ERRORS=ON -DTEST_NP:INT=${check_procs} ${cmake_params}" @@ -176,8 +175,8 @@ fi # load MPI module if necessary if [ -f "/etc/os-release" ]; then - grep -q suse /etc/os-release && source /etc/profile.d/modules.sh && module load gnu-openmpi - grep -q 'rhel\|fedora' /etc/os-release && for f in /etc/profile.d/*module*.sh; do source "${f}"; done && module load mpi + grep -q suse /etc/os-release && . /etc/profile.d/modules.sh && module load gnu-openmpi + grep -q 'rhel\|fedora' /etc/os-release && for f in /etc/profile.d/*module*.sh; do . "${f}"; done && module load mpi fi # CONFIGURE diff --git a/maintainer/CI/dox_warnings.sh b/maintainer/CI/dox_warnings.sh index ec0419fab64..aecb9a1d776 100755 --- a/maintainer/CI/dox_warnings.sh +++ b/maintainer/CI/dox_warnings.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh # Copyright (C) 2019 The ESPResSo project # # This file is part of ESPResSo. diff --git a/maintainer/benchmarks/suite.sh b/maintainer/benchmarks/suite.sh index 569c439d70c..ef9da8eff4a 100644 --- a/maintainer/benchmarks/suite.sh +++ b/maintainer/benchmarks/suite.sh @@ -49,7 +49,7 @@ mkdir "${build_dir}" cd "${build_dir}" # check for unstaged changes -if [ "$(git diff-index HEAD -- ${directories})" ]; then +if [ ! -z "$(git status --porcelain -- ${directories})" ]; then echo "fatal: you have unstaged changes, please commit or stash them:" git diff-index --name-only HEAD -- ${directories} exit 1 @@ -57,7 +57,7 @@ fi cleanup() { # restore files in source directory - git checkout HEAD ${directories} + git checkout HEAD -- ${directories} } # prepare output files @@ -69,7 +69,7 @@ EOF # run benchmarks for commit in ${commits}; do echo "### commit ${commit}" >> benchmarks.log - git checkout ${commit} ${directories} + git checkout ${commit} -- ${directories} bash ../maintainer/benchmarks/runner.sh sed -ri "s/^/\"${commit}\",/" benchmarks.csv tail -n +2 benchmarks.csv >> benchmarks_suite.csv diff --git a/maintainer/find_missing_header.sh b/maintainer/find_missing_header.sh index 73fe7f60711..2e96170f874 100755 --- a/maintainer/find_missing_header.sh +++ b/maintainer/find_missing_header.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh # Copyright (C) 2012-2019 The ESPResSo project # Copyright (C) 2012 Olaf Lenz # diff --git a/maintainer/gh_close_issue.sh b/maintainer/gh_close_issue.sh index 98fb85325c4..f703588801c 100755 --- a/maintainer/gh_close_issue.sh +++ b/maintainer/gh_close_issue.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh # Copyright (C) 2019 The ESPResSo project # # This file is part of ESPResSo. diff --git a/maintainer/gh_create_issue.sh b/maintainer/gh_create_issue.sh index 38253e23903..4c3d4472380 100755 --- a/maintainer/gh_create_issue.sh +++ b/maintainer/gh_create_issue.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh # Copyright (C) 2019 The ESPResSo project # # This file is part of ESPResSo. diff --git a/maintainer/gh_post_status.sh b/maintainer/gh_post_status.sh index 2580fe68105..6c7bd2a6cda 100755 --- a/maintainer/gh_post_status.sh +++ b/maintainer/gh_post_status.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh # Copyright (C) 2017,2019 The ESPResSo project # # This file is part of ESPResSo. diff --git a/maintainer/missing_tests.sh b/maintainer/missing_tests.sh index 4d5c977af5e..b751a42f41c 100755 --- a/maintainer/missing_tests.sh +++ b/maintainer/missing_tests.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh # Copyright (C) 2017-2019 The ESPResSo project # # This file is part of ESPResSo. @@ -18,14 +18,14 @@ # Detect python tests that are not included in CMakeLists.txt. Run this script -# in the folders for python, sample, tutorial and benchmark testsuite folders. +# in the testsuite folders for python, sample, tutorial and benchmark tests. for T in *.py; do if grep -qF " ${T}" CMakeLists.txt; then continue else - GIT_STATUS=$(git status --porcelain -- "${T}") - if [[ ${GIT_STATUS} == ??* ]]; then + tracked_status=$(git ls-files -- "${T}") + if [ -z "${tracked_status}" ]; then echo "File '${T}' is not tracked." continue else diff --git a/src/python/pypresso.cmakein b/src/python/pypresso.cmakein index 019af45c477..7ed2e576c85 100755 --- a/src/python/pypresso.cmakein +++ b/src/python/pypresso.cmakein @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env sh # Copyright (C) 2010-2019 The ESPResSo project # # Copying and distribution of this file, with or without modification, diff --git a/testsuite/cmake/BashUnitTests.sh b/testsuite/cmake/BashUnitTests.sh index cee9b228e50..4ecd4ef5d47 100755 --- a/testsuite/cmake/BashUnitTests.sh +++ b/testsuite/cmake/BashUnitTests.sh @@ -107,7 +107,7 @@ ## @brief Print message to stderr ## @param $1 Message to display -function stderr() { +stderr() { local message=$1 echo "${message}" 1>&2 } @@ -116,7 +116,7 @@ function stderr() { ## ## If functions named `test_*` are already declared in the current environment, ## stop unit testing now. We don't want to run them and create side effects. -function check_namespace() { +check_namespace() { if [ ! -z "$(declare -F | sed -r 's/declare +-f +//' | grep -P '^test_')" ]; then stderr 'Functions named test_* already exist:' for test in $(declare -F | sed -r 's/declare +-f +//' | grep -P "^test_"); do @@ -148,7 +148,7 @@ check_namespace ## variables](https://www.open-mpi.org/faq/?category=running#mpi-environmental-variables) ## that can easily be checked for. ## @returns 1 if MPI is used, 0 otherwise -function detect_open_mpi() { +detect_open_mpi() { if [ -z "${OMPI_COMM_WORLD_SIZE}" ] && [ -z "${OMPI_COMM_WORLD_RANK}" ] \ && [ -z "${OMPI_COMM_WORLD_LOCAL_RANK}" ] && [ -z "${OMPI_UNIVERSE_SIZE}" ] \ && [ -z "${OMPI_COMM_WORLD_LOCAL_SIZE}" ] && [ -z "${OMPI_COMM_WORLD_NODE_RANK}" ]; then @@ -164,7 +164,7 @@ function detect_open_mpi() { ## ## @param $@ Command to run, possibly with modifiers ## @returns Error code returned by the command -function try_catch() { +try_catch() { detect_open_mpi || return 1 ( set -e # exit from current subshell on first error @@ -178,7 +178,7 @@ function try_catch() { ## Run a command in a subshell, exiting the subshell on first error. ## @param $@ Command to run, possibly with modifiers ## @returns Error code returned by the command -function try_catch_silent() { +try_catch_silent() { detect_open_mpi || return 1 ( set -e # exit from current subshell on first error @@ -193,7 +193,7 @@ function try_catch_silent() { ## logging stdout/stderr to the temporary file at #TMPNAME. ## @param $@ Command to run, possibly with modifiers ## @returns Error code returned by the command -function try_catch_capture_output() { +try_catch_capture_output() { detect_open_mpi || return 1 rm -f "${TMPNAME}" ( @@ -207,7 +207,7 @@ function try_catch_capture_output() { ## @brief Run the set_up() function if it exists ## @returns Error code returned by setUp() -function run_set_up() { +run_set_up() { if [ "$(type -t set_up)" = "function" ]; then try_catch set_up local -r retcode=${?} @@ -222,7 +222,7 @@ function run_set_up() { ## @brief Run the tear_down() function if it exists ## @returns Error code returned by tear_down() -function run_tear_down() { +run_tear_down() { rm -f "${TMPNAME}" if [ "$(type -t tear_down)" = "function" ]; then try_catch tear_down @@ -236,7 +236,7 @@ function run_tear_down() { } ## @brief Run the tests -function run_tests() { +run_tests() { for test in $(declare -F | sed -r 's/declare +-f +//' | grep -P "^test_"); do start_test_block "${test#test_}" ${test} @@ -273,7 +273,7 @@ function start_test_block() { ## @brief End a test ## ## Print a newline character and print all error messages in @ref error_log -function end_test_block() { +end_test_block() { echo "" for (( i=0; i<${#error_log[@]}; i++ )); do stderr " ${error_log[i]}" @@ -281,14 +281,14 @@ function end_test_block() { } ## @brief Log a successful assertion -function log_success() { +log_success() { echo -n '.' total_tests=$((total_tests + 1)) } ## @brief Log a failed assertion ## @param $* Description of the failure -function log_failure() { +log_failure() { local message="${*}" echo -n 'x' error_log+=("${message}") @@ -307,7 +307,7 @@ function log_failure() { ## @{ ## @brief Run the setup, tests, teardown -function run_test_suite() { +run_test_suite() { run_set_up run_tests run_tear_down @@ -329,7 +329,7 @@ function run_test_suite() { ## @brief Check if a file exists ## @param $1 Filepath ## @param $2 Message on failure (optional) -function assert_file_exists() { +assert_file_exists() { local -r filepath="${1}" local message="${2}" if [ -z "${message}" ]; then @@ -346,7 +346,7 @@ function assert_file_exists() { ## @param $1 Obtained result ## @param $2 Expected result ## @param $3 Message on failure (optional) -function assert_string_equal() { +assert_string_equal() { local -r result="${1}" local -r expected="${2}" local message="${3}" @@ -364,7 +364,7 @@ function assert_string_equal() { ## @param $1 Obtained result ## @param $2 Expected result ## @param $3 Message on failure (optional) -function assert_equal() { +assert_equal() { local -r result="${1}" local -r expected="${2}" local message="${3}" @@ -381,7 +381,7 @@ function assert_equal() { ## @brief Check if a variable is non-zero ## @param $1 Obtained result ## @param $2 Message on failure (optional) -function assert_non_zero() { +assert_non_zero() { local -r result="${1}" local message="${2}" if [ -z "${message}" ]; then @@ -397,7 +397,7 @@ function assert_non_zero() { ## @brief Check if a variable is zero ## @param $1 Obtained result ## @param $2 Message on failure (optional) -function assert_zero() { +assert_zero() { local -r result="${1}" local message="${2}" if [ -z "${message}" ]; then @@ -414,7 +414,7 @@ function assert_zero() { ## ## Cannot be used in a script run by Open MPI (see \ref TryCatch). ## @param $@ Command to run, possibly with modifiers -function assert_return_code() { +assert_return_code() { try_catch_capture_output "${@}" local -r retcode=${?} if [ "${retcode}" -eq "0" ]; then From dac3b47e02f22d66ddabf792ae1b85e33beac261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Tue, 19 Nov 2019 14:25:09 +0100 Subject: [PATCH 21/22] Quote string variables --- src/python/pypresso.cmakein | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/python/pypresso.cmakein b/src/python/pypresso.cmakein index 7ed2e576c85..fd074dc98ba 100755 --- a/src/python/pypresso.cmakein +++ b/src/python/pypresso.cmakein @@ -29,9 +29,9 @@ fi export LD_PRELOAD if [ "@WITH_UBSAN@" = "ON" ]; then if [ "@WARNINGS_ARE_ERRORS@" = "ON" ]; then - export UBSAN_OPTIONS="halt_on_error=1 print_stacktrace=1 suppressions=@CMAKE_SOURCE_DIR@/tools/ubsan-suppressions.txt $UBSAN_OPTIONS" + export UBSAN_OPTIONS="halt_on_error=1 print_stacktrace=1 suppressions=\"@CMAKE_SOURCE_DIR@/tools/ubsan-suppressions.txt\" $UBSAN_OPTIONS" else - export UBSAN_OPTIONS="print_stacktrace=1 suppressions=@CMAKE_SOURCE_DIR@/tools/ubsan-suppressions.txt $UBSAN_OPTIONS" + export UBSAN_OPTIONS="print_stacktrace=1 suppressions=\"@CMAKE_SOURCE_DIR@/tools/ubsan-suppressions.txt\" $UBSAN_OPTIONS" fi fi if [ "@WITH_ASAN@" = "ON" ]; then @@ -51,55 +51,55 @@ if [ "@WITH_MSAN@" = "ON" ] && [ "@WARNINGS_ARE_ERRORS@" = "ON" ]; then export MSAN_OPTIONS="halt_on_error=1 $MSAN_OPTIONS" fi -case $1 in +case "$1" in --gdb) shift [ "@PYTHON_FRONTEND@" = "@IPYTHON_EXECUTABLE@" ] && exec gdb -ex "set print thread-events off" -ex "set exec-wrapper sh -c 'exec \"@IPYTHON_EXECUTABLE@\" \"\$@\"'" --args "@PYTHON_EXECUTABLE@" "$@" - exec gdb --args @PYTHON_FRONTEND@ "$@" + exec gdb --args "@PYTHON_FRONTEND@" "$@" ;; --lldb) shift - exec lldb -- @PYTHON_FRONTEND@ "$@" + exec lldb -- "@PYTHON_FRONTEND@" "$@" ;; --valgrind) shift - exec valgrind --leak-check=full @PYTHON_FRONTEND@ "$@" + exec valgrind --leak-check=full "@PYTHON_FRONTEND@" "$@" ;; --cuda-gdb) shift - exec cuda-gdb --args @PYTHON_FRONTEND@ "$@" + exec cuda-gdb --args "@PYTHON_FRONTEND@" "$@" ;; --cuda-memcheck) shift - exec cuda-memcheck @PYTHON_FRONTEND@ "$@" + exec cuda-memcheck "@PYTHON_FRONTEND@" "$@" ;; --gdb=*) options="${1#*=}" shift [ "@PYTHON_FRONTEND@" = "@IPYTHON_EXECUTABLE@" ] && exec gdb -ex "set print thread-events off" -ex "set exec-wrapper sh -c 'exec \"@IPYTHON_EXECUTABLE@\" \"\$@\"'" ${options} --args "@PYTHON_EXECUTABLE@" "$@" - exec gdb ${options} --args @PYTHON_FRONTEND@ "$@" + exec gdb ${options} --args "@PYTHON_FRONTEND@" "$@" ;; --lldb=*) options="${1#*=}" shift - exec lldb ${options} -- @PYTHON_FRONTEND@ "$@" + exec lldb ${options} -- "@PYTHON_FRONTEND@" "$@" ;; --valgrind=*) options="${1#*=}" shift - exec valgrind ${options} @PYTHON_FRONTEND@ "$@" + exec valgrind ${options} "@PYTHON_FRONTEND@" "$@" ;; --cuda-gdb=*) options="${1#*=}" shift - exec cuda-gdb ${options} --args @PYTHON_FRONTEND@ "$@" + exec cuda-gdb ${options} --args "@PYTHON_FRONTEND@" "$@" ;; --cuda-memcheck=*) options="${1#*=}" shift - exec cuda-memcheck ${options} @PYTHON_FRONTEND@ "$@" + exec cuda-memcheck ${options} "@PYTHON_FRONTEND@" "$@" ;; *) - exec @PYTHON_FRONTEND@ "$@" + exec "@PYTHON_FRONTEND@" "$@" ;; esac From 93ec8c65426968f78977610b9b53c9299a92c052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Thu, 5 Dec 2019 11:25:58 +0100 Subject: [PATCH 22/22] Quote string variables --- doc/doxygen/Doxyfile.in | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/doc/doxygen/Doxyfile.in b/doc/doxygen/Doxyfile.in index 75e06ceb96c..05d551aa6ec 100644 --- a/doc/doxygen/Doxyfile.in +++ b/doc/doxygen/Doxyfile.in @@ -1,6 +1,6 @@ # Doxyfile 1.8.2 -@INCLUDE = @CMAKE_CURRENT_BINARY_DIR@/doxy-features +@INCLUDE = "@CMAKE_CURRENT_BINARY_DIR@/doxy-features" # This file describes the settings to be used by the documentation system # doxygen (www.doxygen.org) for a project. @@ -47,14 +47,14 @@ PROJECT_BRIEF = "Extensible Simulation Package for Research on Soft Mat # exceed 55 pixels and the maximum width should not exceed 200 pixels. # Doxygen will copy the logo to the output directory. -PROJECT_LOGO = @CMAKE_SOURCE_DIR@/doc/logo/logo_48x48.png +PROJECT_LOGO = "@CMAKE_SOURCE_DIR@/doc/logo/logo_48x48.png" # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # base path where the generated documentation will be put. # If a relative path is entered, it will be relative to the location # where doxygen was started. If left blank the current directory will be used. -OUTPUT_DIRECTORY = @CMAKE_CURRENT_BINARY_DIR@ +OUTPUT_DIRECTORY = "@CMAKE_CURRENT_BINARY_DIR@" # If the CREATE_SUBDIRS tag is set to YES, then doxygen will create # 4096 sub-directories (in 2 levels) under the output directory of each output @@ -647,8 +647,8 @@ WARN_LOGFILE = # directories like "/usr/src/myproject". Separate the files or directories # with spaces. -INPUT = @CMAKE_SOURCE_DIR@/src \ - @CMAKE_SOURCE_DIR@/doc/doxygen/main.dox +INPUT = "@CMAKE_SOURCE_DIR@/src" \ + "@CMAKE_SOURCE_DIR@/doc/doxygen/main.dox" # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is @@ -686,7 +686,7 @@ RECURSIVE = YES # Note that relative paths are relative to the directory from which doxygen is # run. -EXCLUDE = @CMAKE_SOURCE_DIR@/src/config/myconfig-default.hpp +EXCLUDE = "@CMAKE_SOURCE_DIR@/src/config/myconfig-default.hpp" # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded @@ -700,8 +700,8 @@ EXCLUDE_SYMLINKS = NO # against the file with absolute path, so to exclude all test directories # for example use the pattern */test/* -EXCLUDE_PATTERNS = @CMAKE_SOURCE_DIR@/*/unit_tests/* \ - @CMAKE_SOURCE_DIR@/*/tests/* +EXCLUDE_PATTERNS = "@CMAKE_SOURCE_DIR@/*/unit_tests/*" \ + "@CMAKE_SOURCE_DIR@/*/tests/*" # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names # (namespaces, classes, functions, etc.) that should be excluded from the @@ -735,7 +735,7 @@ EXAMPLE_RECURSIVE = YES # directories that contain image that are included in the documentation (see # the \image command). -IMAGE_PATH = @CMAKE_SOURCE_DIR@/doc/doxygen/figs +IMAGE_PATH = "@CMAKE_SOURCE_DIR@/doc/doxygen/figs" # The INPUT_FILTER tag can be used to specify a program that doxygen should # invoke to filter for each input file. Doxygen will invoke the filter program