Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Clang Tidy | 1 # Clang Tidy |
| 2 | 2 |
| 3 [TOC] | 3 [TOC] |
| 4 | 4 |
| 5 ## Danger, Will Robinson! | 5 ## Danger, Will Robinson! |
| 6 | 6 |
| 7 Support for `clang-tidy` in Chromium is very experimental, and is somewhat | 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 | 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, | 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. | 10 forge ahead. Otherwise, feel free to turn back now. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 2. Generate the compilation database | 54 2. Generate the compilation database |
| 55 ``` | 55 ``` |
| 56 ninja -C out/Release -t compdb objcxx cxx > compile_commands.json | 56 ninja -C out/Release -t compdb objcxx cxx > compile_commands.json |
| 57 ``` | 57 ``` |
| 58 3. Enter the build directory. | 58 3. Enter the build directory. |
| 59 ``` | 59 ``` |
| 60 cd out/Release | 60 cd out/Release |
| 61 ``` | 61 ``` |
| 62 4. Run clang-tidy. | 62 4. Run clang-tidy. |
| 63 ``` | 63 ``` |
| 64 <PATH_TO_LLVM_SRC>/tools/clang/tools/extra/clang-tidy/tools/run-clang-tidy.py \ | 64 <PATH_TO_LLVM_SRC>/tools/clang/tools/extra/clang-tidy/tool/run-clang-tidy.py \ |
|
Devlin
2016/09/26 17:21:52
Ah, of course, there's only two nested tools/ dire
| |
| 65 -p ../.. \# Set the root project directory, where compile_commands.json is. | 65 -p ../.. \# Set the root project directory, where compile_commands.json is. |
| 66 # Set the clang-tidy binary path, if it's not in your $PATH. | 66 # Set the clang-tidy binary path, if it's not in your $PATH. |
| 67 -clang-tidy-binary <PATH_TO_LLVM_BUILD>/bin/clang-tidy \ | 67 -clang-tidy-binary <PATH_TO_LLVM_BUILD>/bin/clang-tidy \ |
| 68 # Set the clang-apply-replacements binary path, if it's not in your $PATH | 68 # Set the clang-apply-replacements binary path, if it's not in your $PATH |
| 69 # and you are using the `fix` behavior of clang-tidy. | 69 # and you are using the `fix` behavior of clang-tidy. |
| 70 -clang-apply-replacements-binary \ | 70 -clang-apply-replacements-binary \ |
| 71 <PATH_TO_LLVM_BUILD>/bin/clang-apply-replacements \ | 71 <PATH_TO_LLVM_BUILD>/bin/clang-apply-replacements \ |
| 72 # The checks to employ in the build. Use `-*` to omit default checks. | 72 # The checks to employ in the build. Use `-*` to omit default checks. |
| 73 -checks=<CHECKS> \ | 73 -checks=<CHECKS> \ |
| 74 -header-filter=<FILTER> \# Optional, limit results to only certain files. | 74 -header-filter=<FILTER> \# Optional, limit results to only certain files. |
| 75 -fix \# Optional, used if you want to have clang-tidy auto-fix errors. | 75 -fix \# Optional, used if you want to have clang-tidy auto-fix errors. |
| 76 chrome/browser # The path to the files you want to check. | 76 chrome/browser # The path to the files you want to check. |
| 77 | 77 |
| 78 Copy-Paste Friendly (though you'll still need to stub in the variables): | 78 Copy-Paste Friendly (though you'll still need to stub in the variables): |
| 79 <PATH_TO_LLVM_SRC>/tools/clang/tools/extra/clang-tidy/tools/run-clang-tidy.py \ | 79 <PATH_TO_LLVM_SRC>/tools/clang/tools/extra/clang-tidy/tool/run-clang-tidy.py \ |
| 80 -p ../.. \ | 80 -p ../.. \ |
| 81 -clang-tidy-binary <PATH_TO_LLVM_BUILD>/bin/clang-tidy \ | 81 -clang-tidy-binary <PATH_TO_LLVM_BUILD>/bin/clang-tidy \ |
| 82 -clang-apply-replacements-binary \ | 82 -clang-apply-replacements-binary \ |
| 83 <PATH_TO_LLVM_BUILD>/bin/clang-apply-replacements \ | 83 <PATH_TO_LLVM_BUILD>/bin/clang-apply-replacements \ |
| 84 -checks=<CHECKS> \ | 84 -checks=<CHECKS> \ |
| 85 -header-filter=<FILTER> \ | 85 -header-filter=<FILTER> \ |
| 86 -fix \ | 86 -fix \ |
| 87 chrome/browser | 87 chrome/browser |
| 88 ``` | 88 ``` |
| 89 | 89 |
| 90 \*It's not clear which, if any, `gn` flags may cause issues for `clang-tidy`. | 90 \*It's not clear which, if any, `gn` flags may cause issues for `clang-tidy`. |
| 91 I've had no problems building a component release build, both with and without | 91 I've had no problems building a component release build, both with and without |
| 92 goma. if you run into issues, let us know! | 92 goma. if you run into issues, let us know! |
| 93 | 93 |
| 94 ## Troubleshooting | 94 ## Troubleshooting |
| 95 | 95 |
| 96 If you see errors like | 96 If you see errors like |
| 97 ``` | 97 ``` |
| 98 src/build/linux/debian_wheezy_amd64-sysroot/usr/include/wchar.h:40:11: error: 's tdarg.h' file not found [clang-diagnostic-error] | 98 src/build/linux/debian_wheezy_amd64-sysroot/usr/include/wchar.h:40:11: error: 's tdarg.h' file not found [clang-diagnostic-error] |
| 99 ``` | 99 ``` |
| 100 | 100 |
| 101 then you should also build the `clang-headers` target in your llvm checkout. | 101 then you should also build the `clang-headers` target in your llvm checkout. |
| 102 This is fixed by http://reviews.llvm.org/D22046, so if your llvm checkout is | 102 This is fixed by http://reviews.llvm.org/D22046, so if your llvm checkout is |
| 103 up-to-date, this shouldn't be needed. | 103 up-to-date, this shouldn't be needed. |
| 104 | 104 |
| 105 ## Questions | 105 ## Questions |
| 106 | 106 |
| 107 Questions? Reach out to rdevlin.cronin@chromium.org or thakis@chromium.org. | 107 Questions? Reach out to rdevlin.cronin@chromium.org or thakis@chromium.org. |
| 108 Discoveries? Update the doc! | 108 Discoveries? Update the doc! |
| OLD | NEW |