| 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 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 the [Chrome style | 105 the [Chrome style |
| 106 plugin](https://chromium.googlesource.com/chromium/src/+/master/tools/clang/plug
ins/), | 106 plugin](https://chromium.googlesource.com/chromium/src/+/master/tools/clang/plug
ins/), |
| 107 and the [Blink to Chrome style rewriter](https://chromium.googlesource.com/chrom
ium/src/+/master/tools/clang/rewrite_to_chrome_style/). Additional arguments to
`--tools` should be the name of | 107 and the [Blink to Chrome style rewriter](https://chromium.googlesource.com/chrom
ium/src/+/master/tools/clang/rewrite_to_chrome_style/). Additional arguments to
`--tools` should be the name of |
| 108 subdirectories in | 108 subdirectories in |
| 109 [//tools/clang](https://chromium.googlesource.com/chromium/src/+/master/tools/cl
ang). | 109 [//tools/clang](https://chromium.googlesource.com/chromium/src/+/master/tools/cl
ang). |
| 110 Generally, `--tools` should always include `blink_gc_plugin` and `plugins`: othe
rwise, Chromium won't build. | 110 Generally, `--tools` should always include `blink_gc_plugin` and `plugins`: othe
rwise, Chromium won't build. |
| 111 | 111 |
| 112 It is important to use --bootstrap as there appear to be [bugs](https://crbug.co
m/580745) | 112 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. | 113 in the clang library this script produces if you build it with gcc, which is the
default. |
| 114 | 114 |
| 115 After bootstrapping is done, rebuilding can be done with something like: |
| 116 |
| 117 ```shell |
| 118 ninja -C third_party/llvm-build/Release+Asserts <tool name> |
| 119 ``` |
| 120 |
| 115 ## Running | 121 ## Running |
| 116 First, build all chromium targets to avoid failures due to missing dependecies | 122 First, build all chromium targets to avoid failures due to missing dependecies |
| 117 that are generated as part of the build: | 123 that are generated as part of the build: |
| 118 | 124 |
| 119 ```shell | 125 ```shell |
| 120 ninja -C out/Debug | 126 ninja -C out/Debug |
| 121 ``` | 127 ``` |
| 122 | 128 |
| 123 Then run the actual tool: | 129 Then run the actual tool: |
| 124 | 130 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 stmt->dumpColor(); | 171 stmt->dumpColor(); |
| 166 ``` | 172 ``` |
| 167 | 173 |
| 168 By default, the script hides the output of the tool. The easiest way to change | 174 By default, the script hides the output of the tool. The easiest way to change |
| 169 that is to `return 1` from the `main()` function of the clang tool. | 175 that is to `return 1` from the `main()` function of the clang tool. |
| 170 | 176 |
| 171 ## Testing | 177 ## Testing |
| 172 Synposis: | 178 Synposis: |
| 173 | 179 |
| 174 ```shell | 180 ```shell |
| 175 test_tool.py <tool name> | 181 tools/clang/scripts/test_tool.py <tool name> |
| 176 ``` | 182 ``` |
| 177 | 183 |
| 178 The name of the tool binary and the subdirectory for the tool in | 184 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 | 185 `//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 | 186 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 | 187 those files, and compared it to the `*-expected.cc` version. If there is a |
| 182 mismatch, the result is saved in `*-actual.cc`. | 188 mismatch, the result is saved in `*-actual.cc`. |
| OLD | NEW |