Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Clang Tidy | |
| 2 | |
| 3 [TOC] | |
| 4 | |
| 5 ## Danger, Will Robinson! | |
| 6 | |
| 7 Support for `clang-tidy` in Chromium is very experimental, and is somewhat | |
| 8 painful to use. We are exploring making it easier and integrating with existing | |
| 9 tools, but aren't there yet. If you don't want to wait and enjoy tinkering, | |
| 10 forge ahead. Otherwise, feel free to turn back now. | |
| 11 | |
| 12 ## Introduction | |
| 13 | |
| 14 [clang-tidy](http://clang.llvm.org/extra/clang-tidy/) is a clang-based C++ | |
| 15 “linter” tool. Its purpose is to provide an extensible framework for diagnosing | |
| 16 and fixing typical programming errors, like style violations, interface misuse, | |
| 17 or bugs that can be deduced via static analysis. **clang-tidy** is modular and | |
| 18 provides a convenient interface for writing new checks. | |
|
Nico
2016/07/12 18:44:09
i'd omit the last sentence
Devlin
2016/07/12 19:05:02
Done.
| |
| 19 | |
| 20 ## Setting Up | |
| 21 | |
| 22 In addition to a full Chromium checkout, you need the clang-tidy binary. We | |
| 23 recommend checking llvm's clang source and building the clang-tidy binary | |
| 24 directly. Instructions for getting started with clang are available from | |
| 25 [llvm](http://clang.llvm.org/get_started.html). You'll need to get llvm, | |
| 26 clang, and the extra clang tools (you won't need Compiler-RT or libcxx). | |
| 27 If you don't have it, you'll also need to install cmake as a part of this | |
| 28 process. | |
| 29 | |
| 30 Instead of building with `"Unix Makefiles"`, generate build files for Ninja with | |
| 31 ``` | |
| 32 cmake -GNinja ../llvm | |
| 33 ``` | |
| 34 | |
| 35 Then, instead of using `make`, use ninja to build the clang-tidy binary with | |
| 36 ``` | |
| 37 ninja clang-tidy | |
| 38 ``` | |
| 39 | |
| 40 This binary will be at (build)/bin/clang-tidy. | |
| 41 | |
| 42 If you intend to use the `fix` feature of clang-tidy, you'll also need to build | |
| 43 the `clang-apply-replacements` binary. | |
| 44 ``` | |
| 45 ninja clang-apply-replacements | |
| 46 ``` | |
| 47 | |
| 48 ## Running clang-tidy | |
| 49 | |
| 50 Running clang-tidy is (hopefully) simple. | |
| 51 1. Build chrome normally.\* | |
| 52 ``` | |
| 53 ninja -C out/release chrome | |
|
Nico
2016/07/12 18:44:09
upper-case R, then it works with gyp too
Devlin
2016/07/12 19:05:02
It was my subtle hint to get people off gyp ;) Bu
| |
| 54 ``` | |
| 55 2. Generate the compilation database | |
| 56 ``` | |
| 57 ninja -C out/release -t compdb objxx cxx > compile_commands.json | |
|
Nico
2016/07/12 18:44:09
ditto. (also, isn't it "objcxx" for mm files? not
Devlin
2016/07/12 19:05:02
Done, and yes! Typo. Thanks for catching it.
| |
| 58 ``` | |
| 59 3. Enter the build directory. | |
| 60 ``` | |
| 61 cd out/release | |
| 62 ``` | |
| 63 4. Run clang-tidy. | |
| 64 ``` | |
| 65 <PATH_TO_LLVM_SRC>/tools/clang/tools/extra/clang-tidy/tools/run-clang-tidy.py \ | |
| 66 -p ../.. \# Set the root project directory, where compile_commands.json is. | |
| 67 # Set the clang-tidy binary path, if it's not in your $PATH. | |
|
Nico
2016/07/12 18:44:09
hm, do inline comments work with continuations? is
Devlin
2016/07/12 19:05:02
Nope, but I figured it was the easiest way of docu
| |
| 68 -clang-tidy-binary <PATH_TO_LLVM_BUILD>/bin/clang-tidy \ | |
| 69 # Set the clang-apply-replacements binary path, if it's not in your $PATH | |
| 70 # and you are using the `fix` behavior of clang-tidy. | |
| 71 -clang-apply-replacements-binary \ | |
| 72 <PATH_TO_LLVM_BUILD>/bin/clang-apply-replacements \ | |
| 73 # The checks to employ in the build. Use `-*` to omit default checks. | |
| 74 -checks=<CHECKS> \ | |
| 75 -header-filter=<FILTER> \# Optional, limit results to only certain files. | |
| 76 -fix \# Optional, used if you want to have clang-tidy auto-fix errors. | |
| 77 chrome/browser # The path to the files you want to check. | |
| 78 ``` | |
| 79 | |
| 80 \*It's not clear which, if any, `gn` flags may cause issues for `clang-tidy`. | |
| 81 I've had no problems building a component release build, both with and without | |
| 82 goma. if you run into issues, let us know! | |
| 83 | |
| 84 ## Troubleshooting | |
| 85 | |
| 86 If you see errors like | |
| 87 ``` | |
| 88 src/build/linux/debian_wheezy_amd64-sysroot/usr/include/wchar.h:40:11: error: 's tdarg.h' file not found [clang-diagnostic-error] | |
| 89 ``` | |
| 90 | |
| 91 then you should also build the `clang-headers` target in your llvm checkout. | |
| 92 (This should be fixed by http://reviews.llvm.org/D22046). | |
|
Nico
2016/07/12 18:44:09
"(This is fixed in llvm r274751, so if your llvm c
Devlin
2016/07/12 19:05:02
Updated the phrasing. I'd like to keep it in for
| |
| 93 | |
| 94 ## Questions | |
| 95 | |
| 96 Questions? Reach out to rdevlin.cronin@chromium.org or thakis@chromium.org. | |
| 97 Discoveries? Update the doc! | |
| OLD | NEW |