blob: cd5d1cc93b259a8d4fd52bd323c602f4c13093ac [file] [log] [blame] [view]
rdevlin.croninbe2898eb2016-07-13 01:20:361# Clang Tidy
2
3[TOC]
4
5## Danger, Will Robinson!
6
7Support for `clang-tidy` in Chromium is very experimental, and is somewhat
8painful to use. We are exploring making it easier and integrating with existing
9tools, but aren't there yet. If you don't want to wait and enjoy tinkering,
10forge 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++
15linter tool. Its purpose is to provide an extensible framework for diagnosing
16and fixing typical programming errors, like style violations, interface misuse,
17or bugs that can be deduced via static analysis.
18
19## Setting Up
20
21In addition to a full Chromium checkout, you need the clang-tidy binary. We
22recommend checking llvm's clang source and building the clang-tidy binary
23directly. Instructions for getting started with clang are available from
24[llvm](http://clang.llvm.org/get_started.html). You'll need to get llvm,
25clang, and the extra clang tools (you won't need Compiler-RT or libcxx).
26If you don't have it, you'll also need to install cmake as a part of this
27process.
28
29Instead of building with `"Unix Makefiles"`, generate build files for Ninja with
30```
Chris Watkinse4ffe1e22017-11-24 00:48:4831cmake -GNinja -DCMAKE_BUILD_TYPE=Release ../llvm
rdevlin.croninbe2898eb2016-07-13 01:20:3632```
33
34Then, instead of using `make`, use ninja to build the clang-tidy binary with
35```
36ninja clang-tidy
37```
38
39This binary will be at (build)/bin/clang-tidy.
40
41If you intend to use the `fix` feature of clang-tidy, you'll also need to build
42the `clang-apply-replacements` binary.
43```
44ninja clang-apply-replacements
45```
46
47## Running clang-tidy
48
49Running clang-tidy is (hopefully) simple.
501. Build chrome normally.\*
51```
52ninja -C out/Release chrome
53```
542. Generate the compilation database
55```
Daniel Cheng51c55302017-05-04 00:39:1656tools/clang/scripts/generate_compdb.py -p out/Release > compile_commands.json
rdevlin.croninbe2898eb2016-07-13 01:20:3657```
583. Enter the build directory.
59```
60cd out/Release
61```
624. Run clang-tidy.
63```
treib52d7e482016-09-26 21:46:35