| OLD | NEW |
| 1 # Clang Tool Refactoring | 1 # Clang Tool Refactoring |
| 2 | 2 |
| 3 [TOC] | 3 [TOC] |
| 4 | 4 |
| 5 ## Introduction | 5 ## Introduction |
| 6 | 6 |
| 7 Clang tools can help with global refactorings of Chromium code. Clang tools can | 7 Clang tools can help with global refactorings of Chromium code. Clang tools can |
| 8 take advantage of clang's AST to perform refactorings that would be impossible | 8 take advantage of clang's AST to perform refactorings that would be impossible |
| 9 with a traditional find-and-replace regexp: | 9 with a traditional find-and-replace regexp: |
| 10 | 10 |
| 11 * Constructing `scoped_ptr<T>` from `NULL`: <https://crbug.com/173286> | 11 * Constructing `scoped_ptr<T>` from `NULL`: <https://crbug.com/173286> |
| 12 * Implicit conversions of `scoped_refptr<T>` to `T*`: <https://crbug.com/11061
0> | 12 * Implicit conversions of `scoped_refptr<T>` to `T*`: <https://crbug.com/11061
0> |
| 13 * Rename everything in Blink to follow Chromium style: <https://crbug.com/5637
93> | 13 * Rename everything in Blink to follow Chromium style: <https://crbug.com/5637
93> |
| 14 | 14 |
| 15 ## Caveats | 15 ## Caveats |
| 16 | 16 |
| 17 An invocation of the clang tool runs on one build config. Code that only | 17 An invocation of the clang tool runs on one build config. Code that only |
| 18 compiles on one platform or code that is guarded by a set of compile-time flags | 18 compiles on one platform or code that is guarded by a set of compile-time flags |
| 19 can be problematic. Performing a global refactoring typically requires running | 19 can be problematic. Performing a global refactoring typically requires running |
| 20 the tool once in each build config with code that needs to be updated. | 20 the tool once in each build config with code that needs to be updated. |
| 21 | 21 |
| 22 Other minor issues: | 22 Other minor issues: |
| 23 | 23 |
| 24 * Requires a git checkout. | 24 * Requires a git checkout. |
| 25 * Requires [some hacks to run on Windows](https://codereview.chromium.org/7188
73004). | |
| 26 | 25 |
| 27 ## Prerequisites | 26 ## Prerequisites |
| 28 | 27 |
| 29 A Chromium checkout created with `fetch` should have everything needed. | 28 A Chromium checkout created with `fetch` should have everything needed. |
| 30 | 29 |
| 31 For convenience, add `third_party/llvm-build/Release+Asserts/bin` to `$PATH`. | 30 For convenience, add `third_party/llvm-build/Release+Asserts/bin` to `$PATH`. |
| 32 | 31 |
| 33 ## Writing the tool | 32 ## Writing the tool |
| 34 | 33 |
| 35 LLVM uses C++11 and CMake. Source code for Chromium clang tools lives in | 34 LLVM uses C++11 and CMake. Source code for Chromium clang tools lives in |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 Generally, `--tools` should always include `blink_gc_plugin` and `plugins`: othe
rwise, Chromium won't build. | 109 Generally, `--tools` should always include `blink_gc_plugin` and `plugins`: othe
rwise, Chromium won't build. |
| 111 | 110 |
| 112 It is important to use --bootstrap as there appear to be [bugs](https://crbug.co
m/580745) | 111 It is important to use --bootstrap as there appear to be [bugs](https://crbug.co
m/580745) |
| 113 in the clang library this script produces if you build it with gcc, which is the
default. | 112 in the clang library this script produces if you build it with gcc, which is the
default. |
| 114 | 113 |
| 115 ## Running | 114 ## Running |
| 116 First, build all Chromium targets to avoid failures due to missing dependencies | 115 First, build all Chromium targets to avoid failures due to missing dependencies |
| 117 that are generated as part of the build: | 116 that are generated as part of the build: |
| 118 | 117 |
| 119 ```shell | 118 ```shell |
| 120 ninja -C out/Debug | 119 ninja -C out/Debug # For non-Windows |
| 120 ninja -d keeprsp -C out/Debug # For Windows |
| 121 ``` |
| 122 |
| 123 On Windows, generate the compile DB first, and after making any source changes. |
| 124 Then omit the `--generate-compdb` in later steps. |
| 125 |
| 126 ```shell |
| 127 tools/clang/scripts/generate_win_compdb.py out/Debug |
| 121 ``` | 128 ``` |
| 122 | 129 |
| 123 Then run the actual tool: | 130 Then run the actual tool: |
| 124 | 131 |
| 125 ```shell | 132 ```shell |
| 126 tools/clang/scripts/run_tool.py <toolname> \ | 133 tools/clang/scripts/run_tool.py <toolname> \ |
| 127 --generate-compdb | 134 --generate-compdb |
| 128 out/Debug <path 1> <path 2> ... | 135 out/Debug <path 1> <path 2> ... |
| 129 ``` | 136 ``` |
| 130 | 137 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 180 |
| 174 ```shell | 181 ```shell |
| 175 tools/clang/scripts/test_tool.py <tool name> | 182 tools/clang/scripts/test_tool.py <tool name> |
| 176 ``` | 183 ``` |
| 177 | 184 |
| 178 The name of the tool binary and the subdirectory for the tool in | 185 The name of the tool binary and the subdirectory for the tool in |
| 179 `//tools/clang` must match. The test runner finds all files that match the | 186 `//tools/clang` must match. The test runner finds all files that match the |
| 180 pattern `//tools/clang/<tool name>/tests/*-original.cc`, runs the tool across | 187 pattern `//tools/clang/<tool name>/tests/*-original.cc`, runs the tool across |
| 181 those files, and compared it to the `*-expected.cc` version. If there is a | 188 those files, and compared it to the `*-expected.cc` version. If there is a |
| 182 mismatch, the result is saved in `*-actual.cc`. | 189 mismatch, the result is saved in `*-actual.cc`. |
| OLD | NEW |