diff --git a/.clang-tidy b/.clang-tidy index fffab0ce372641ebabd3468a5c106d2c9b0ce039..8728493b9c79947e08e56a12592baabf5589407b 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -34,21 +34,14 @@ modernize-*, -modernize-loop-convert, -modernize-pass-by-value, -modernize-raw-string-literal, --modernize-use-using, -modernize-avoid-bind, --modernize-return-braced-init-list, -modernize-min-max-use-initializer-list, -modernize-use-transparent-functors, --modernize-redundant-void-arg, -modernize-use-trailing-return-type, --modernize-use-default-member-init, +-modernize-use-nodiscard, -modernize-use-equals-delete, -modernize-macro-to-enum, --modernize-avoid-c-arrays, -modernize-concat-nested-namespaces, --modernize-use-nodiscard, --modernize-type-traits, --modernize-make-shared, mpi-*, -mpi-type-mismatch, diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000000000000000000000000000000000000..e1b021bd37b0272e303315e0c72455e57e9760a7 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,32 @@ +{ + "version": 6, + "cmakeMinimumRequired": { + "major": 3, + "minor": 23, + "patch": 0 + }, + "configurePresets": [ + { + "name": "clang-tidy", + "generator": "Unix Makefiles", + "binaryDir": "${sourceDir}/build/clang-tidy", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": true, + "WALBERLA_BUFFER_DEBUG": true, + "WALBERLA_BUILD_TESTS": true, + "WALBERLA_BUILD_BENCHMARKS": true, + "WALBERLA_BUILD_TUTORIALS": true, + "WALBERLA_BUILD_TOOLS": true, + "WALBERLA_BUILD_WITH_MPI": true, + "WALBERLA_BUILD_WITH_OPENMP": true, + "CMAKE_BUILD_TYPE": "Debug", + "WALBERLA_BUILD_WITH_METIS": true, + "WALBERLA_BUILD_WITH_PARMETIS": true, + "WALBERLA_BUILD_WITH_OPENMESH": true, + "WALBERLA_DOUBLE_ACCURACY": true, + "WALBERLA_LOGLEVEL": "DETAIL" + } + } + ] + } + \ No newline at end of file diff --git a/utilities/clang-tidy/README.md b/utilities/clang-tidy/README.md index d58bcb008c07b5f4fe4b2e8bc8577cfbcbe91e82..5c132d521ee534931d26b6f934b8b7b29836682e 100644 --- a/utilities/clang-tidy/README.md +++ b/utilities/clang-tidy/README.md @@ -4,6 +4,35 @@ See also the [Clang-Tidy Documentation](https://clang.llvm.org/extra/clang-tidy/ This document briefly explains how to run a clang-tidy analysis and (auto-)fixing pass on the waLBerla code base. +## tl;dr + + 1. Set up build system: `cmake --preset clang-tidy` + 2. Navigate to `build/clang-tidy` + 3. Filter the compile command database: + +```bash +python utilities/clang-tidy/filterCompileCommands.py -f compile_commands.json --exclude * --include folder1 folder2 .... +``` + + 4. Run clang-tidy: + +```bash +run-clang-tidy -quiet -header-filter=".*/(module1|module2|...)/.*" > tidy.txt +``` + + 5. Inspect the output: + +```bash +python utilities/clang-tidy/clangTidySummary.py tidy.txt +less tidy.txt +``` + + 6. Fix the errors, if applicable use autofix: + +```bash +run-clang-tidy -header-filter=".*/(module1|module2|...)/.*" -checks=-*,<diagnostic-to-fix> -fix +``` + ## Set up CMake To run clang-tidy, CMake needs to be configured to emit a compile command data base which clang-tidy @@ -55,7 +84,9 @@ The above configuration: in `core` and `blockforest`, you can set `WALBERLA_BUILD_WITH_METIS` and `WALBERLA_BUILD_WITH_PARMETIS` to `false`. - prepares the build system also for tests, benchmarks and tutorials - if you do not wish to analyze those, you can exlude them. -Copy the preset JSON code to the `CMakeUserPresets.json` file in your waLBerla root directory and run `cmake --preset clang-tidy` to set up the build system. +This preset is contained in the `CMakePresets.json` file. To generate the build system defined by it, run `cmake --preset clang-tidy`. + +## Filter Translation Units to be Analyzed Next, navigate to the `build/clang-tidy` subdirectory. There, you will find the compile command data base `compile_commands.json`. diff --git a/utilities/clang-tidy/clangTidySummary.py b/utilities/clang-tidy/clangTidySummary.py index d9a850c9a83dc21d0ef86d3bc8de39e4433d58a5..21f228b2e842ea6b676085037246233be1564425 100644 --- a/utilities/clang-tidy/clangTidySummary.py +++ b/utilities/clang-tidy/clangTidySummary.py @@ -4,8 +4,9 @@ import pathlib import re import pprint -WARNING_PATTERN = re.compile(r"\[([^[]+)(?:,-warnings-as-errors)?\]\n") -TRAILING = len(",-warnings-as-errors") +# WARNING_PATTERN = re.compile(r"\[([^[]+)(?:,-warnings-as-errors)?\]\n") +WARNING_PATTERN = re.compile(r"\[[a-z-]+,-warnings-as-errors\]\n") +TRAILING = len(",-warnings-as-errors]\n") if __name__ == "__main__": parser = ArgumentParser() @@ -15,7 +16,7 @@ if __name__ == "__main__": output_fp = pathlib.Path(args.clang_tidy_output) clang_tidy_log = output_fp.read_text() matches = WARNING_PATTERN.findall(clang_tidy_log) - matches = [m[:-TRAILING] for m in matches] + matches = [m[1:-TRAILING] for m in matches] counter = Counter(matches) pprint.pp(counter)