diff --git a/.github/workflows/spell_check.yml b/.github/workflows/spell_check.yml index 207182401d..305b1af303 100644 --- a/.github/workflows/spell_check.yml +++ b/.github/workflows/spell_check.yml @@ -38,7 +38,7 @@ jobs: - name: check macros run: | for file in $(git diff --name-only --diff-filter=A); do - ./scripts/check_macros.sh "$file" &>> check_macros.txt + ./scripts/internal/check_macros.sh "$file" &>> check_macros.txt done - name: Archive script output if: failure() diff --git a/.github/workflows/test_valgrind.yml b/.github/workflows/test_valgrind.yml index 91dd1f6be4..4225171d18 100644 --- a/.github/workflows/test_valgrind.yml +++ b/.github/workflows/test_valgrind.yml @@ -122,4 +122,4 @@ jobs: # Execute script that runs a Valgrind check for all test binaries. # We use 4 parallel processes to run the binaries in parallel with MPI. - name: Valgrind check - run: cd scripts && bash ./check_all_test_binaries_valgrind.sh --ntasks=4 + run: cd scripts && bash ./check_all_test_binaries_valgrind.sh ../build/test/ --ntasks=4 diff --git a/.typos.toml b/.typos.toml index 11d8700b70..b956ef5a00 100644 --- a/.typos.toml +++ b/.typos.toml @@ -3,4 +3,4 @@ eles = "eles" packageid = "packageid" [files] -extend-exclude = ["scripts/t8indent.sh", "thirdparty/", "t8code_logo.png", "cmake/FindOpenCASCADE.cmake", "src/t8_misc/t8_with_macro_error.h", "doc/Doxyfile.in"] +extend-exclude = ["scripts/indent.sh", "thirdparty/", "t8code_logo.png", "cmake/FindOpenCASCADE.cmake", "src/t8_misc/t8_with_macro_error.h", "doc/Doxyfile.in"] diff --git a/pull_request_template.md b/pull_request_template.md index 9487fb68b8..9b7346fbe5 100644 --- a/pull_request_template.md +++ b/pull_request_template.md @@ -25,7 +25,7 @@ If the Pull request introduces code that is not covered by the github action (fo - [ ] Should this use case be added to the github action? - [ ] If not, does the specific use case compile and all tests pass (check manually). #### Scripts and Wiki -- [ ] If a new directory with source files is added, it must be covered by the `script/find_all_source_files.scp` to check the indentation of these files. +- [ ] If a new directory with source files is added, it must be covered by the `scripts/find_all_source_files.scp` to check the indentation of these files. - [ ] If this PR introduces a new feature, it must be covered in an example or tutorial and a Wiki article. #### License - [ ] The author added a BSD statement to `doc/` (or already has one). \ No newline at end of file diff --git a/scripts/README.md b/scripts/README.md index c573496467..6fc8c255bd 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -6,26 +6,21 @@ This folder contains several scripts that are useful for t8code users and develo The purpose of the indentation scripts is to help t8code developers to indent their code according to the t8code [indentation guidelines](https://github.com/DLR-AMR/t8code/wiki/Coding-Guideline#indentation). Please read these guidelines before using these scripts. -#### t8indent.sh +#### indent.sh Apply this script to a `.c`, `.cxx`, `.h` or `.hxx` file to indent it according to the guidelines. You can also provide a list of files and all will get indented. This script uses the `clang-format` program with t8code specific settings. -Sometimes `t8indent.sh` does produce undesired results. Therefore, after indenting use `git add -p` or similar to check all changes before committing. You can protect code lines from being changed by the script by enclosing them in `/* clang-format off */` and `/* clang-format on */` comments. +Sometimes `indent.sh` does produce undesired results. Therefore, after indenting use `git add -p` or similar to check all changes before committing. You can protect code lines from being changed by the script by enclosing them in `/* clang-format off */` and `/* clang-format on */` comments. +#### internal/indent_ignore -#### t8indent_ignore.sh - -A list of files that will be ignored by `t8indent.sh`. - -#### pre-commit - -This script should be copied to your `.git/hooks` folder. `git` then automatically checks the indentation of committed files and prevents you from committing wrongly indented files. See [Git indentation workflow](https://github.com/DLR-AMR/t8code/wiki/Coding-Guideline#git-indentation-workflow). +A list of files that will be ignored by `indent.sh`. #### check_if_file_indented.sh -Check for a single source file whether it is indented according to `t8indent.sh`. +Check for a single source file whether it is indented according to `indent.sh`. #### check_if_all_files_indented.sh @@ -35,30 +30,23 @@ Check whether all t8code source files are properly indented. This script indents all t8code source files at once. This script should only be used by the main developers of t8code. Handle with care. -#### find_all_source_files.sh +## Software development + +#### pre-commit -List all source files of t8code in the `src/`, `example/` and `test/` subfolders. +This script should be copied to your `.git/hooks` folder. `git` then automatically checks the indentation of committed files and prevents you from committing wrongly indented files. See [Git indentation workflow](https://github.com/DLR-AMR/t8code/wiki/Coding-Guideline#git-indentation-workflow). #### check_valgrind.sh This script runs Valgrind on a binary path provided as a parameter with specified memory leak detection flags. The Valgrind output is parsed. Using `--supp=[FILE]`, you can provide a path to a suppression file that is used by Valgrind to suppress certain errors (e.g. [valgrind_suppressions_file](valgrind_suppressions_file.supp)). With `--ntasks=[NUMBER]`, you can provide the number of processes to use with mpi (default is 1). -#### find_all_test_binary_paths.sh - -This file lists all paths to test binaries that exist in the build/test directory. -The paths are relative paths assuming an execution from the test/ folder in the build directory. - #### check_all_test_binaries_valgrind.sh -This script performs a valgrind check on each test binary found by [find_all_test_binary_paths.sh](find_all_test_binary_paths.sh). +This script performs a valgrind check on each test binary found by [find_all_test_binary_paths.sh](internal/find_all_test_binary_paths.sh). The valgrind check is done by [check_valgrind.sh](check_valgrind.sh). It is assumed that the build folder ../build/test/ with the correct test binaries exists. With `--ntasks=[NUMBER]`, you can provide the number of processes to use with mpi for parallel tests (default is 1). ## Others -#### su2_mesh_to_gmsh.py - -Used to convert coarse meshes from an su2 format into msh format. - #### create_todo_list.sh Parses through the code and collects comments containing the `TODO` keyword. diff --git a/scripts/check_all_test_binaries_valgrind.sh b/scripts/check_all_test_binaries_valgrind.sh old mode 100644 new mode 100755 index c4f5796b30..0431d30f67 --- a/scripts/check_all_test_binaries_valgrind.sh +++ b/scripts/check_all_test_binaries_valgrind.sh @@ -4,7 +4,7 @@ # t8code is a C library to manage a collection (a forest) of multiple # connected adaptive space-trees of general element classes in parallel. # -# Copyright (C) 2025 the developers +# Copyright (C) 2026 the developers # # t8code is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -23,16 +23,35 @@ # # This script performs a valgrind check on each test binary given by find_all_test_binary_paths.sh. # The valgrind check is done by the check_valgrind.sh script. -# The script returns 1 if an error is found and 0 otherwise. +# The script returns 1 if an error is found and 0 otherwise. # This script must be executed from the scripts/ folder. # It is assumed that the build folder ../build/test/ with the correct test binaries exists. # With "--ntasks=[NUMBER]", you can provide the number of processes to use with MPI for parallel tests (default is 1). # USAGE="\nUSAGE: This script executes valgrind in parallel on each test binary available. Use the syntax \n -$0 --ntasks=[NUM_TASKS]\n +$0 [TEST_BINARY_PATH] --ntasks=[NUM_TASKS]\n Providing the number of parallel processes to use with MPI for parallel tests is optional.\n" +# Check directory exists +if [ -z "$1" ]; then + echo "ERROR: Need to provide a directory as first argument." + echo -e "$USAGE" + exit 1 +fi + +# Check if it is a directory +if [ -d "$1" ]; then + TEST_BINARY_PATH="$1" +else + echo "ERROR: Directory does not exist: $1" + echo -e "$USAGE" + exit 1 +fi + +#convert to abspath +TEST_BINARY_ABSPATH=$(realpath $TEST_BINARY_PATH) + # Check if a number of processes is provided. If not, set to 1. num_procs=1 for arg in "$@"; do @@ -61,20 +80,22 @@ if [ `basename $PWD` != scripts ]; then fi # Find all test binary paths. -test_bin_paths=`bash ./find_all_test_binary_paths.sh` -num_paths=$(echo $test_bin_paths | wc -w) +test_bin_paths=$(bash ./find_all_test_binary_paths.sh "$TEST_BINARY_ABSPATH") +status=$? -# This is necessary because some tests use test files specified by relative paths. -# These tests only work when run from the build/test/ directory. -if [ -d ../build/test ]; then - # The directory stack is automatically reset on script exit. - pushd ../build/test/ > /dev/null -else - echo "ERROR: Couldn't find a the directory ../build/test/." - echo -e "$USAGE" - exit 1 +if [ $status -ne 0 ]; then + echo "$test_bin_paths" + echo "Failed to collect test binaries." + exit $status fi +num_paths=$(echo $test_bin_paths | wc -w) + +# This is necessary because some tests use test files specified by relative paths. +# These tests only work when run from the test directory. +# The directory stack is automatically reset on script exit. +pushd $TEST_BINARY_ABSPATH > /dev/null + status=0 counter=0 valgrind_suppressions_file=../../scripts/valgrind_suppressions_file.supp diff --git a/scripts/check_if_all_files_indented.sh b/scripts/check_if_all_files_indented.sh index dca7f1a81c..4c8208c3bf 100755 --- a/scripts/check_if_all_files_indented.sh +++ b/scripts/check_if_all_files_indented.sh @@ -44,7 +44,7 @@ fi # Find all files with the appropriate suffix. # Excluding the sc/ and p4est/ subfolders. -files=`./find_all_source_files.sh` +files=`./internal/find_all_source_files.sh` notallindented=0 for file in $files diff --git a/scripts/check_if_file_indented.sh b/scripts/check_if_file_indented.sh index be7c55b3c5..ca23327d56 100755 --- a/scripts/check_if_file_indented.sh +++ b/scripts/check_if_file_indented.sh @@ -21,14 +21,14 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # -# This script checks if a given file is correctly indented according to the t8indent.sh script. -# +# This script checks if a given file is correctly indented according to the indent.sh script. +# GIT_REPO_PATH=$(git rev-parse --show-toplevel) -INDENT_SCRIPT=${GIT_REPO_PATH}/scripts/t8indent.sh +INDENT_SCRIPT=${GIT_REPO_PATH}/scripts/indent.sh -usage="USAGE:$0 [FILE_TO_CHECK]\n\nWill check if [FILE_TO_CHECK] is correctly indentend according to the script t8indent.sh." +usage="USAGE:$0 [FILE_TO_CHECK]\n\nWill check if [FILE_TO_CHECK] is correctly indentend according to the script indent.sh." # Check if first argument given if [ ${1-x} = x ] diff --git a/scripts/check_valgrind.sh b/scripts/check_valgrind.sh old mode 100644 new mode 100755 index 635bdfd34b..c33c685413 --- a/scripts/check_valgrind.sh +++ b/scripts/check_valgrind.sh @@ -21,7 +21,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # -# This script runs Valgrind on an input binary paths with specified memory leak detection flags. +# This script runs Valgrind on an input binary paths with specified memory leak detection flags. # The Valgrind output is parsed. If any errors are found, they are printed and the script exits with a status of 1. # If errors are found, the Valgrind output is kept in the file valgrind-output.log for further inspection. # Using "--supp=[FILE]", you can provide a path to a suppression file that is used by Valgrind to suppress certain errors. @@ -32,7 +32,7 @@ $0 [FILE] --supp=[SUPPRESSION_FILE] --ntasks=[NUM_TASKS]\n to run valgrind on FILE. Optionally you can provide a suppression file and the number of parallel processes to use with MPI.\n" # Check that an argument is given and that the argument is a file. -if [ ${1-x} = x ]; then +if [ -z "$1" ]; then echo "ERROR: Need to provide a file as first argument." echo -e "$USAGE" exit 1 diff --git a/scripts/configure_for_rtd.sh b/scripts/configure_for_rtd.sh old mode 100644 new mode 100755 index dc44a436e7..c728d4ee62 --- a/scripts/configure_for_rtd.sh +++ b/scripts/configure_for_rtd.sh @@ -20,6 +20,8 @@ # along with t8code; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +pushd "$(git rev-parse --show-toplevel)" > /dev/null + git submodule init git submodule update diff --git a/scripts/find_disabled_tests.sh b/scripts/find_disabled_tests.sh index efa3460aa3..0fa60081f5 100755 --- a/scripts/find_disabled_tests.sh +++ b/scripts/find_disabled_tests.sh @@ -1,25 +1,24 @@ #!/bin/bash - -#This file is part of t8code. -#t8code is a C library to manage a collection (a forest) of multiple -#connected adaptive space-trees of general element classes in parallel. - -#Copyright (C) 2024 the developers - -#t8code 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 2 of the License, or -#(at your option) any later version. - -#t8code 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 t8code; if not, write to the Free Software Foundation, Inc., -#51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# This file is part of t8code. +# t8code is a C library to manage a collection (a forest) of multiple +# connected adaptive space-trees of general element classes in parallel. +# +# Copyright (C) 2024 the developers +# +# t8code 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 2 of the License, or +# (at your option) any later version. +# +# t8code 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 t8code; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/scripts/t8indent.sh b/scripts/indent.sh similarity index 97% rename from scripts/t8indent.sh rename to scripts/indent.sh index 750ecd6c51..e091533c8b 100755 --- a/scripts/t8indent.sh +++ b/scripts/indent.sh @@ -66,12 +66,12 @@ fi # # Parsing of input files and throwing out files to be ignored # -# Read all lines from the IGNORE_FILE +# Read all lines from the IGNORE_FILE # that are not empty and are not comments (i.e. start with '#'). # Determine base directory of git repo GIT_REPO_PATH=$(git rev-parse --show-toplevel) -IGNORE_FILE=${GIT_REPO_PATH}/scripts/t8indent_ignore.sh +IGNORE_FILE=${GIT_REPO_PATH}/scripts/internal/indent_ignore files_to_ignore=() while read line; do if [[ ${line:0:1} != "#" ]] && [[ $line != "" ]] @@ -112,7 +112,7 @@ do do echo Checking "$arg" against "${GIT_REPO_PATH}/$ignore_file" if [[ "$arg" -ef "${GIT_REPO_PATH}/$ignore_file" ]] - then + then # arg matches and will be ignored echo The file \"$arg\" will be ignored by indentation as specified in \"$IGNORE_FILE\". ignore_arg=1 @@ -136,7 +136,7 @@ then else $FORMAT $FORMAT_OPTIONS ${newargs[@]} status=$? -fi +fi # If the file content was not changed, the return # value determines whether or not the file was diff --git a/scripts/indent_all_files.sh b/scripts/indent_all_files.sh index 8d0559530f..4d7a7b4acf 100755 --- a/scripts/indent_all_files.sh +++ b/scripts/indent_all_files.sh @@ -43,13 +43,13 @@ fi # Find all files with the appropriate suffix. # Excluding the sc/ and p4est/ subfolders. -files=`./find_all_source_files.sh` +files=`./internal/find_all_source_files.sh` notallindented=0 -INDENT=./t8indent.sh +INDENT=./indent.sh -echo This script will change all source files found in +echo This script will change all source files found in echo $PWD/../src/ echo $PWD/../example/ echo $PWD/../test/ @@ -72,14 +72,14 @@ then then $INDENT $file status=$? - if test $status -ne 0 + if test $status -ne 0 then echo "File $file is not indented." notallindented=1 fi fi done - + if test $notallindented -eq 0 then echo All files are indented. diff --git a/scripts/check_macros.sh b/scripts/internal/check_macros.sh similarity index 96% rename from scripts/check_macros.sh rename to scripts/internal/check_macros.sh index cd6cc8e5cf..7597ea9c11 100755 --- a/scripts/check_macros.sh +++ b/scripts/internal/check_macros.sh @@ -35,19 +35,19 @@ then exit 0 fi -# -# This script searches for lines containing a macro definition in the style of '#ifdef T8_ENABLE_' +# +# This script searches for lines containing a macro definition in the style of '#ifdef T8_ENABLE_' # in the specified file and processes each matching line. -# It uses 'grep' to find all occurrences of '#ifdef T8_ENABLE_' in the file located -# at the path stored in the variable 'file_path'. The '-n' option with 'grep' +# It uses 'grep' to find all occurrences of '#ifdef T8_ENABLE_' in the file located +# at the path stored in the variable 'file_path'. The '-n' option with 'grep' # ensures that the line numbers of the matching lines are included in the output. -# The output of 'grep' is then piped into a 'while' loop, which reads each line +# The output of 'grep' is then piped into a 'while' loop, which reads each line # and splits it into the line number and the line content using ':' as the delimiter. # Variables: # - file_path: The path to the file to be searched. # - line_number: The line number where the macro definition is found. # - line: The content of the line where the macro definition is found. -# +# found_macros=FALSE diff --git a/scripts/find_all_source_files.sh b/scripts/internal/find_all_source_files.sh similarity index 100% rename from scripts/find_all_source_files.sh rename to scripts/internal/find_all_source_files.sh diff --git a/scripts/find_all_test_binary_paths.sh b/scripts/internal/find_all_test_binary_paths.sh old mode 100644 new mode 100755 similarity index 74% rename from scripts/find_all_test_binary_paths.sh rename to scripts/internal/find_all_test_binary_paths.sh index 6abc889624..6984067bba --- a/scripts/find_all_test_binary_paths.sh +++ b/scripts/internal/find_all_test_binary_paths.sh @@ -4,7 +4,7 @@ # t8code is a C library to manage a collection (a forest) of multiple # connected adaptive space-trees of general element classes in parallel. # -# Copyright (C) 2025 the developers +# Copyright (C) 2026 the developers # # t8code is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -26,16 +26,16 @@ # The paths are relative paths assuming an execution from the test/ folder in the build directory. # -build_test_directory="../build/test/" +TEST_BINARY_PATH="$1" # Check that path to test folder in build directory is correct. -if [ ! -d "$build_test_directory" ]; then - echo "Directory build/test/ not found!" +if [ ! -d "$TEST_BINARY_PATH" ]; then + echo "Directory $TEST_BINARY_PATH not found!" exit 1 fi -# Find all executables in the build/test/ directory (that do not have a .so file ending) -# and store the relative paths to the build_test_directory with leading "./". -test_bin_paths=$(find "$build_test_directory" -type f -executable -not -name "*.so" -exec realpath --relative-to="$build_test_directory" {} \; | sed 's|^|./|') +# Find all executables in the build/test/ directory (that do not have a .so file ending) +# and store the relative paths to the TEST_BINARY_PATH with leading "./". +test_bin_paths=$(find "$TEST_BINARY_PATH" -type f -executable -not -name "*.so" -exec realpath --relative-to="$TEST_BINARY_PATH" {} \; | sed 's|^|./|') -echo $test_bin_paths +echo "$test_bin_paths" diff --git a/scripts/t8indent_ignore.sh b/scripts/internal/indent_ignore old mode 100755 new mode 100644 similarity index 90% rename from scripts/t8indent_ignore.sh rename to scripts/internal/indent_ignore index 6a0c982c23..2c33ee86fb --- a/scripts/t8indent_ignore.sh +++ b/scripts/internal/indent_ignore @@ -19,11 +19,11 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # This is t8code's indentation ignore file. -# All files listed here are ignored by out t8indent.sh script and thus not +# All files listed here are ignored by out indent.sh script and thus not # indented according to our indentation guidelines. -# Since we rely on clang-format version 17 and clang-format.ignored files +# Since we rely on clang-format version 17 and clang-format.ignored files # have only been introduced in version 18, we need to manually parse -# this list and throw out the matching files. This happens in t8indent.sh +# this list and throw out the matching files. This happens in indent.sh # Each file that is listed here must have a comment describing why # it is necessary to ignore indentation for this file. diff --git a/scripts/pre-commit b/scripts/pre-commit index 19b160f9d9..cf062bdace 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -38,7 +38,7 @@ GIT_REPO_PATH=$(git rev-parse --show-toplevel) # Set paths to check scripts CHECK_INDENT=$GIT_REPO_PATH/scripts/check_if_file_indented.sh -CHECK_MACROS=$GIT_REPO_PATH/scripts/check_macros.sh +CHECK_MACROS=$GIT_REPO_PATH/scripts/internal/check_macros.sh TYPOS=`which typos 2> /dev/null` TYPOS_CONFIG_FILE=./.typos.toml @@ -92,7 +92,7 @@ do if ! [ -z "$status" ]; then echo "File $file contains typos." nocontinue=1 - fi + fi # We only indent .c, .cxx, .h and .hxx files #-a ${file: -2} != ".h" ] @@ -102,7 +102,7 @@ do echo "Checking file $file" $CHECK_INDENT $file > /dev/null 2>&1 status=$? - if test $status -ne 0 + if test $status -ne 0 then echo "File $file is not indented." nocontinue=1 @@ -116,7 +116,7 @@ do # - nocontinue: Flag set to 1 if the incorrect macro usage is found. $CHECK_MACROS $file status=$? - if test $status -ne 0 + if test $status -ne 0 then nocontinue=1 fi diff --git a/scripts/t8spell_check_and_indent.sh b/scripts/spell_check_and_indent.sh similarity index 97% rename from scripts/t8spell_check_and_indent.sh rename to scripts/spell_check_and_indent.sh index 600b7bfb9e..f1ab9687a5 100755 --- a/scripts/t8spell_check_and_indent.sh +++ b/scripts/spell_check_and_indent.sh @@ -70,7 +70,7 @@ then if [[ $REPLY =~ ^[Yy]$ ]] then echo Indenting all files... - (cd $repo_main_dir && ./scripts/t8indent.sh $changed_files) + (cd $repo_main_dir && ./scripts/indent.sh $changed_files) echo done. else echo Aborted.