Skip to content

Commit fe620e0

Browse files
authored
Merge pull request #349 from vkucera/tools
Tools: Extend instructions for Clang-Tidy. Add more links.
2 parents 8e40ac6 + e843394 commit fe620e0

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

docs/tools/README.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,34 +59,43 @@ To use Clang-Tidy, you need to have O2Physics compiled and a valid symbolic link
5959

6060
The [`readability-identifier-naming`](https://clang.llvm.org/extra/clang-tidy/checks/readability/identifier-naming.html) check can fix deviations from the [naming conventions](https://rawgit.com/AliceO2Group/CodingGuidelines/master/naming_formatting.html).
6161

62-
### Cleaning `#include`s
62+
### Cleaning `#include` statements and `using` statements
6363

64-
The [`misc-include-cleaner`](https://clang.llvm.org/extra/clang-tidy/checks/misc/include-cleaner.html) check can fix missing and unused `#include`s.
65-
This helps to apply the [Include What You Use](https://github.com/AliceO2Group/O2Physics/issues/8357) principle which allows to maintain header dependencies clean.
64+
```danger
65+
Incorrect usage of `#include` statements and `using` statements causes [unnecessary recompilations](https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/WhyIWYU.md#fewer-recompiles) and can [break compilation](https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/WhyIWYU.md#allow-refactoring) of other parts of the project! (See also [Management of header dependencies](https://indico.cern.ch/event/1513750/#29-management-of-header-depend).)
66+
```
67+
68+
The [`misc-include-cleaner`](https://clang.llvm.org/extra/clang-tidy/checks/misc/include-cleaner.html) check can fix missing and unused `#include` statements.
69+
This helps to apply the [Include What You Use](https://github.com/AliceO2Group/O2Physics/issues/8357) (IWYU) principle which allows to maintain header dependencies clean.
70+
The behaviour of the check can be tuned manually using [IWYU pragmas](https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/IWYUPragmas.md).
71+
72+
The [`google-global-names-in-headers`](https://clang.llvm.org/extra/clang-tidy/checks/google/global-names-in-headers.html) check finds `using` declarations and directives in headers, which cause [global namespace pollution](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#rs-using-directive) that can be difficult to fix.
73+
74+
The [`misc-unused-using-decls`](https://clang.llvm.org/extra/clang-tidy/checks/misc/unused-using-decls.html) check finds unused `using` declarations in source files, which create fake dependencies that hamper IWYU.
6675

6776
### Testing (and fixing) many files at once
6877

69-
Here is an example of how to run the `misc-include-cleaner` check in parallel on all `.h`, `.cxx`, `.C` files in the current directory.
78+
Here is an example of how to run selected checks in parallel on all `.h`, `.cxx`, `.C` files in the current directory (`.`).
7079

7180
```bash
72-
find . -name "*.h" -o -name "*.cxx" -o -name "*.C" | parallel "clang-tidy --fix -checks=-*,misc-include-cleaner {}; echo \"{} \$?\"" > "clang-tidy.log"
81+
find . -name "*.h" -o -name "*.cxx" -o -name "*.C" | parallel "clang-tidy -fix -checks=-*,misc-include-cleaner,google-global-names-in-headers,misc-unused-using-decls {}; echo \"{} \$?\"" > "clang-tidy.log"
7382
```
7483

7584
The [`parallel`](https://www.gnu.org/software/parallel/) command is used to parallelise the execution of the `clang-tidy` command for all files.
7685

77-
For each file, Clang-Tidy will first try to compile it and then run the enabled check(s) and fix found problems (the `--fix` option).
86+
For each file, Clang-Tidy will first try to compile it and then run the enabled check(s) and fix found problems (the `-fix` option).
7887
The messages are redirected into `clang-tidy.log`.
7988
The file name and the exit code are printed below the output of Clang-Tidy so that you can get the list of files for which Clang-Tidy failed with `grep " 1$" "clang-tidy.log"`.
8089

8190
## Fixing include format
8291

8392
Headers from the same project should be included using quotation marks (`#include "path/header.h"`), all other headers should be included using angle brackets (`#include <path/header.h>`).
84-
Failing to do so can result in picking a wrong header.
85-
See more details in the [C++ Core Guidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#sf12-prefer-the-quoted-form-of-include-for-files-relative-to-the-including-file-and-the-angle-bracket-form-everywhere-else).
93+
Failing to do so points the preprocessor to a [wrong location](https://gcc.gnu.org/onlinedocs/cpp/Include-Syntax.html) and can result in picking a wrong header.
94+
See also the [C++ Core Guidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#sf12-prefer-the-quoted-form-of-include-for-files-relative-to-the-including-file-and-the-angle-bracket-form-everywhere-else).
8695

8796
The [`format_includes.awk`](https://github.com/AliceO2Group/O2Physics/blob/master/Scripts/format_includes.awk) script allows to fix the include format in a provided O2Physics file.
8897

89-
To fix the include format in all `.h`, `.cxx` files in the current directory, execute:
98+
To fix the include format in all `.h`, `.cxx` files in the current directory (`.`), execute:
9099

91100
```bash
92101
find . -name "*.h" -o -name "*.cxx" | parallel "awk -f Scripts/format_includes.awk \"{}\" > \"{}.tmp\" && mv \"{}.tmp\" \"{}\""
@@ -111,7 +120,7 @@ cppcheck --language=c++ --std=c++20 --enable=style --check-level=exhaustive --su
111120

112121
The report will be stored in the `err.log` file.
113122

114-
To run a parallelised analysis of all `.h`, `.cxx`, `.C` files in the current directory, execute:
123+
To run a parallelised analysis of all `.h`, `.cxx`, `.C` files in the current directory (`.`), execute:
115124

116125
```bash
117126
find . -name "*.h" -o -name "*.cxx" -o -name "*.C" | parallel "cppcheck --language=c++ --std=c++20 --enable=style --check-level=exhaustive --suppressions-list=cppcheck_config {}" 2> "err.log"

0 commit comments

Comments
 (0)