[clang-tidy] Add ability to checkout clang-tidy.

This CL adds the DEPS entry to checkout `clang-tidy` if requested
in the `.gclient` config file. A doc is added which gives some
guidance on how to run `clang-tidy`.

Change-Id: I92eeaff33137158ffd17315649fb333c366fc91d
Bug: dawn:1414
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/89801
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
dan sinclair 2022-05-16 12:58:24 +00:00 committed by Dawn LUCI CQ
parent 9ff8abf347
commit 93cf346d67
4 changed files with 232 additions and 0 deletions

179
.clang-tidy Normal file
View File

@ -0,0 +1,179 @@
FormatStyle: file
Checks: "+*,\
-bugprone-argument-comment,\
-bugprone-branch-clone,\
-bugprone-copy-constructor-init,\
-bugprone-easily-swappable-parameters,\
-bugprone-exception-escape,\
-bugprone-fold-init-type,\
-bugprone-forward-declaration-namespace,\
-bugprone-forwarding-reference-overload,\
-bugprone-implicit-widening-of-multiplication-result,\
-bugprone-incorrect-roundings,\
-bugprone-infinite-loop,\
-bugprone-integer-division,\
-bugprone-lambda-function-name,\
-bugprone-macro-parentheses,\
-bugprone-misplaced-widening-cast,\
-bugprone-move-forwarding-reference,\
-bugprone-multiple-statement-macro,\
-bugprone-narrowing-conversions,\
-bugprone-not-null-terminated-result,\
-bugprone-parent-virtual-call,\
-bugprone-redundant-branch-condition,\
-bugprone-reserved-identifier,\
-bugprone-signed-char-misuse,\
-bugprone-sizeof-expression,\
-bugprone-string-constructor,\
-bugprone-suspicious-enum-usage,\
-bugprone-suspicious-include,\
-bugprone-suspicious-memory-comparison,\
-bugprone-suspicious-string-compare,\
-bugprone-terminating-continue,\
-bugprone-throw-keyword-missing,\
-bugprone-too-small-loop-variable,\
-bugprone-undefined-memory-manipulation,\
-bugprone-unhandled-self-assignment,\
-bugprone-unused-raii,\
-bugprone-unused-return-value,\
-bugprone-use-after-move,\
-bugprone-virtual-near-miss,\
-cert-dcl03-c,\
-cert-dcl16-c,\
-cert-dcl21-cpp,\
-cert-dcl50-cpp,\
-cert-dcl54-cpp,\
-cert-dcl58-cpp,\
-cert-dcl59-cpp,\
-cert-err09-cpp,\
-cert-err33-c,\
-cert-err34-c,\
-cert-err52-cpp,\
-cert-err58-cpp,\
-cert-msc30-c,\
-cert-msc32-c,\
-cert-oop11-cpp,\
-cert-oop54-cpp,\
-cert-oop57-cpp,\
-clang-analyzer-core.CallAndMessage,\
-clang-analyzer-core.DivideZero,\
-clang-analyzer-core.NonNullParamChecker,\
-clang-analyzer-core.NullDereference,\
-clang-analyzer-core.UndefinedBinaryOperatorResult,\
-clang-analyzer-core.uninitialized.Assign,\
-clang-analyzer-core.uninitialized.Branch,\
-clang-analyzer-core.uninitialized.UndefReturn,\
-clang-analyzer-cplusplus.Move,\
-clang-analyzer-cplusplus.NewDelete,\
-clang-analyzer-cplusplus.NewDeleteLeaks,\
-clang-analyzer-cplusplus.PlacementNew,\
-clang-analyzer-deadcode.DeadStores,\
-clang-analyzer-optin.cplusplus.UninitializedObject,\
-clang-analyzer-optin.cplusplus.VirtualCall,\
-clang-analyzer-optin.performance.Padding,\
-clang-analyzer-optin.portability.UnixAPI,\
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,\
-clang-analyzer-security.insecureAPI.strcpy,\
-clang-analyzer-unix.Malloc,\
-clang-analyzer-valist.Unterminated,\
-concurrency-mt-unsafe,\
-google-build-using-namespace,\
-google-default-arguments,\
-google-explicit-constructor,\
-google-global-names-in-headers,\
-google-readability-avoid-underscore-in-googletest-name,\
-google-readability-braces-around-statements,\
-google-readability-casting,\
-google-readability-function-size,\
-google-readability-namespace-comments,\
-google-readability-todo,\
-google-runtime-int,\
-google-runtime-operator,\
-google-upgrade-googletest-case,\
-misc-definitions-in-headers,\
-misc-misplaced-const,\
-misc-non-private-member-variables-in-classes,\
-misc-no-recursion,\
-misc-redundant-expression,\
-misc-unconventional-assign-operator,\
-misc-uniqueptr-reset-release,\
-misc-unused-parameters,\
-misc-unused-using-decls,\
-modernize-avoid-bind,\
-modernize-avoid-c-arrays,\
-modernize-concat-nested-namespaces,\
-modernize-deprecated-headers,\
-modernize-loop-convert,\
-modernize-macro-to-enum,\
-modernize-make-shared,\
-modernize-make-unique,\
-modernize-pass-by-value,\
-modernize-raw-string-literal,\
-modernize-redundant-void-arg,\
-modernize-replace-disallow-copy-and-assign-macro,\
-modernize-return-braced-init-list,\
-modernize-unary-static-assert,\
-modernize-use-auto,\
-modernize-use-bool-literals,\
-modernize-use-default-member-init,\
-modernize-use-emplace,\
-modernize-use-equals-default,\
-modernize-use-equals-delete,\
-modernize-use-nodiscard,\
-modernize-use-noexcept,\
-modernize-use-nullptr,\
-modernize-use-override,\
-modernize-use-trailing-return-type,\
-modernize-use-transparent-functors,\
-modernize-use-using,\
-performance-faster-string-find,\
-performance-for-range-copy,\
-performance-inefficient-algorithm,\
-performance-inefficient-string-concatenation,\
-performance-inefficient-vector-operation,\
-performance-move-const-arg,\
-performance-no-automatic-move,\
-performance-noexcept-move-constructor,\
-performance-no-int-to-ptr,\
-performance-trivially-destructible,\
-performance-unnecessary-copy-initialization,\
-performance-unnecessary-value-param,\
-portability-std-allocator-const,\
-readability-avoid-const-params-in-decls,\
-readability-braces-around-statements,\
-readability-const-return-type,\
-readability-container-data-pointer,\
-readability-container-size-empty,\
-readability-convert-member-functions-to-static,\
-readability-delete-null-pointer,\
-readability-duplicate-include,\
-readability-else-after-return,\
-readability-function-cognitive-complexity,\
-readability-identifier-length,\
-readability-identifier-naming,\
-readability-implicit-bool-conversion,\
-readability-inconsistent-declaration-parameter-name,\
-readability-isolate-declaration,\
-readability-magic-numbers,\
-readability-make-member-function-const,\
-readability-misleading-indentation,\
-readability-named-parameter,\
-readability-non-const-parameter,\
-readability-qualified-auto,\
-readability-redundant-access-specifiers,\
-readability-redundant-control-flow,\
-readability-redundant-declaration,\
-readability-redundant-member-init,\
-readability-redundant-preprocessor,\
-readability-redundant-smartptr-get,\
-readability-redundant-string-cstr,\
-readability-redundant-string-init,\
-readability-simplify-boolean-expr,\
-readability-simplify-subscript-expr,\
-readability-static-accessed-through-instance,\
-readability-static-definition-in-anonymous-namespace,\
-readability-string-compare,\
-readability-suspicious-call-argument,\
-readability-uppercase-literal-suffix,\
-readability-use-anyofallof,\
"

4
.gitignore vendored
View File

@ -122,3 +122,7 @@ default.profraw
lcov.info lcov.info
/cmake-build-*/ /cmake-build-*/
/testing /testing
### Clang-Tidy files
all_findings.json

12
DEPS
View File

@ -26,6 +26,9 @@ vars = {
# GN variable required by //testing that will be output in the gclient_args.gni # GN variable required by //testing that will be output in the gclient_args.gni
'generate_location_tags': False, 'generate_location_tags': False,
# Fetch clang-tidy into the same bin/ directory as our clang binary.
'checkout_clang_tidy': False,
} }
deps = { deps = {
@ -242,6 +245,15 @@ hooks = [
'action': ['python3', 'tools/clang/scripts/update.py'], 'action': ['python3', 'tools/clang/scripts/update.py'],
'condition': 'dawn_standalone', 'condition': 'dawn_standalone',
}, },
{
# This is also supposed to support the same set of platforms as 'clang'
# above. LLVM ToT support isn't provided at the moment.
'name': 'clang_tidy',
'pattern': '.',
'condition': 'checkout_clang_tidy',
'action': ['python3', 'tools/clang/scripts/update.py',
'--package=clang-tidy'],
},
{ {
# Pull rc binaries using checked-in hashes. # Pull rc binaries using checked-in hashes.
'name': 'rc_win', 'name': 'rc_win',

37
docs/clang-tidy.md Normal file
View File

@ -0,0 +1,37 @@
# Running clang-tidy
* Add `"checkout_clang_tidy": True` to `.gclient` file in the `custom_vars`.
```
{
"custom_vars": {
"checkout_clang_tidy": True,
}
}
```
* `gclient sync`
There should now be `third_party/llvm-build/Release+Asserts/bin/clang-tidy`
* `cd out`
* `git clone https://chromium.googlesource.com/chromium/tools/build`
The Chromium build folder contains the `tricium` files used to run `clang-tidy`
Running clang-tidy over all the source can be done with:
```
cd ..
out/build/recipes/recipe_modules/tricium_clang_tidy/resources/tricium_clang_tidy_script.py \
--base_path $PWD \
--out_dir out/Debug \
--findings_file all_findings.json \
--clang_tidy_binary $PWD/third_party/llvm-build/Release+Asserts/bin/clang-tidy \
--all
```
`--all` can be replaced by specific files if desired to run on individual source
files.
## References
* https://chromium.googlesource.com/chromium/src.git/+/HEAD/docs/clang_tidy.md