Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Clang Tidy | |
|
Devlin
2016/07/11 23:38:28
Not all markdown viewers are created equal - do yo
| |
| 2 | |
| 3 [TOC] | |
| 4 | |
| 5 ## Introduction | |
| 6 | |
| 7 [clang-tidy](http://clang.llvm.org/extra/clang-tidy/) is a clang-based C++ | |
| 8 “linter” tool. Its purpose is to provide an extensible framework for diagnosing | |
| 9 and fixing typical programming errors, like style violations, interface misuse, | |
| 10 or bugs that can be deduced via static analysis. **clang-tidy** is modular and | |
| 11 provides a convenient interface for writing new checks. | |
| 12 | |
| 13 ## Setting Up | |
| 14 | |
| 15 In addition to a full Chromium checkout, you need the clang-tidy binary. We | |
| 16 recommend checking llvm's clang source and building the clang-tidy binary | |
| 17 directly. Instructions for getting started with clang are available from | |
| 18 [llvm](http://clang.llvm.org/get_started.html). You'll need to get llvm, | |
| 19 clang, and the extra clang tools (you won't need Compiler-RT or libcxx). | |
| 20 If you don't have it, you'll also need to install cmake as a part of this | |
| 21 process. | |
| 22 | |
| 23 Instead of building with `"Unix Makefiles"`, generate build files for Ninja with | |
| 24 ``` | |
| 25 cmake -GNinja ../llvm | |
| 26 ``` | |
| 27 | |
| 28 Then, instead of using `make`, use ninja to build the clang-tidy binary with | |
| 29 ``` | |
| 30 ninja clang-tidy | |
| 31 ``` | |
| 32 | |
| 33 This binary will be at (build)/bin/clang-tidy. | |
| 34 | |
| 35 If you intend to use the `fix` feature of clang-tidy, you'll also need to build | |
| 36 the `clang-apply-replacements` binary. | |
| 37 ``` | |
| 38 ninja clang-apply-replacements | |
| 39 ``` | |
| 40 | |
| 41 ## Running clang-tidy | |
| 42 | |
| 43 Running clang-tidy is (hopefully) simple. | |
| 44 1. Build chrome normally.\* | |
| 45 ``` | |
| 46 ninja -C out/release chrome | |
| 47 ``` | |
| 48 2. Generate the compilation database | |
| 49 ``` | |
| 50 ninja -C out/release -t compdb objxx cxx > compile_commands.json | |
| 51 ``` | |
| 52 3. Enter the build directory. | |
| 53 ``` | |
| 54 cd out/release | |
| 55 ``` | |
| 56 4. Run clang-tidy. | |
| 57 ``` | |
| 58 <PATH_TO_LLVM_SRC>/tools/clang/tools/extra/clang-tidy/tools/run-clang-tidy.py \ | |
| 59 -p ../.. \# Set the root project directory, where compile_commands.json is. | |
| 60 # Set the clang-tidy binary path, if it's not in your $PATH. | |
| 61 -clang-tidy-binary <PATH_TO_LLVM_BUILD>/bin/clang-tidy \ | |
| 62 # Set the clang-apply-replacements binary path, if it's not in your $PATH | |
| 63 # and you are using the `fix` behavior of clang-tidy. | |
| 64 -clang-apply-replacements-binary \ | |
| 65 <PATH_TO_LLVM_BUILD>/bin/clang-apply-replacements \ | |
| 66 # The checks to employ in the build. Use `-*` to omit default checks. | |
| 67 -checks=<CHECKS> \ | |
| 68 -header-filter=<FILTER> \# Optional, limit results to only certain files. | |
| 69 -fix \# Optional, used if you want to have clang-tidy auto-fix errors. | |
| 70 chrome/browser # The path to the files you want to check. | |
| 71 ``` | |
| 72 | |
| 73 \*It's not clear which, if any, `gn` flags may cause issues for `clang-tidy`. | |
| 74 I've had no problems building a component release build, both with and without | |
| 75 goma. if you run into issues, let us know! | |
| 76 | |
| 77 ## Troubleshooting | |
| 78 | |
| 79 If you see errors like | |
| 80 ``` | |
| 81 src/build/linux/debian_wheezy_amd64-sysroot/usr/include/wchar.h:40:11: error: 's tdarg.h' file not found [clang-diagnostic-error] | |
| 82 ``` | |
| 83 | |
| 84 then you should also build the `clang-headers` target in your llvm checkout. | |
| 85 (This should be fixed by http://reviews.llvm.org/D22046). | |
| 86 | |
| 87 ## Questions | |
| 88 | |
| 89 Questions? Reach out to rdevlin.cronin@chromium.org or thakis@chromium.org. | |
|
Devlin
2016/07/11 23:38:28
I'm volunteering you here. Let me know if you want
| |
| 90 Discoveries? Update the doc! | |
| OLD | NEW |