Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 2756f14

Browse files
authored
Remove rewrapper prefix from compiler commands for clang-tidy (#51001)
This PR also enables RBE for builds for clang-tidy.
1 parent 0f727a5 commit 2756f14

4 files changed

Lines changed: 59 additions & 9 deletions

File tree

ci/builders/linux_clang_tidy.json

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@
66
"device_type=none",
77
"os=Linux"
88
],
9+
"gclient_variables": {
10+
"use_rbe": true
11+
},
912
"gn": [
1013
"--android",
1114
"--android-cpu",
1215
"arm64",
1316
"--no-lto",
1417
"--target-dir",
15-
"android_debug_arm64_clang_tidy"
18+
"android_debug_arm64_clang_tidy",
19+
"--rbe",
20+
"--no-goma"
1621
],
1722
"name": "android_debug_arm64_clang_tidy",
1823
"ninja": {
@@ -25,13 +30,18 @@
2530
"device_type=none",
2631
"os=Linux"
2732
],
33+
"gclient_variables": {
34+
"use_rbe": true
35+
},
2836
"gn": [
2937
"--runtime-mode",
3038
"debug",
3139
"--prebuilt-dart-sdk",
3240
"--no-lto",
3341
"--target-dir",
34-
"host_debug_clang_tidy"
42+
"host_debug_clang_tidy",
43+
"--rbe",
44+
"--no-goma"
3545
],
3646
"name": "host_debug_clang_tidy",
3747
"ninja": {
@@ -58,6 +68,7 @@
5868
{
5969
"name": "test: lint host_debug",
6070
"parameters": [
71+
"--verbose",
6172
"--variant",
6273
"host_debug_clang_tidy",
6374
"--lint-all",
@@ -87,6 +98,7 @@
8798
{
8899
"name": "test: lint host_debug",
89100
"parameters": [
101+
"--verbose",
90102
"--variant",
91103
"host_debug_clang_tidy",
92104
"--lint-all",
@@ -116,6 +128,7 @@
116128
{
117129
"name": "test: lint host_debug",
118130
"parameters": [
131+
"--verbose",
119132
"--variant",
120133
"host_debug_clang_tidy",
121134
"--lint-all",
@@ -145,6 +158,7 @@
145158
{
146159
"name": "test: lint host_debug",
147160
"parameters": [
161+
"--verbose",
148162
"--variant",
149163
"host_debug_clang_tidy",
150164
"--lint-all",
@@ -172,6 +186,7 @@
172186
{
173187
"name": "test: lint android_debug_arm64",
174188
"parameters": [
189+
"--verbose",
175190
"--variant",
176191
"android_debug_arm64_clang_tidy",
177192
"--lint-all",

ci/builders/mac_clang_tidy.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"cpu=arm64"
88
],
99
"gclient_variables": {
10-
"download_android_deps": false
10+
"download_android_deps": false,
11+
"use_rbe": true
1112
},
1213
"gn": [
1314
"--runtime-mode",
@@ -16,7 +17,9 @@
1617
"--no-lto",
1718
"--force-mac-arm64",
1819
"--target-dir",
19-
"host_debug_clang_tidy"
20+
"host_debug_clang_tidy",
21+
"--rbe",
22+
"--no-goma"
2023
],
2124
"name": "host_debug_clang_tidy",
2225
"ninja": {
@@ -30,7 +33,8 @@
3033
"cpu=arm64"
3134
],
3235
"gclient_variables": {
33-
"download_android_deps": false
36+
"download_android_deps": false,
37+
"use_rbe": true
3438
},
3539
"gn": [
3640
"--ios",
@@ -40,7 +44,9 @@
4044
"--no-lto",
4145
"--force-mac-arm64",
4246
"--target-dir",
43-
"ios_debug_sim_clang_tidy"
47+
"ios_debug_sim_clang_tidy",
48+
"--rbe",
49+
"--no-goma"
4450
],
4551
"name": "ios_debug_sim_clang_tidy",
4652
"ninja": {

tools/clang_tidy/lib/src/command.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class Command {
5555
/// The file on which the command operates.
5656
late final String filePath;
5757

58-
static final RegExp _pathRegex = RegExp(r'\S*clang/bin/clang');
59-
static final RegExp _argRegex = RegExp(r'-MF \S*');
58+
static final RegExp _pathRegex = RegExp(r'\S*clang/bin/clang(\+\+)?');
59+
static final RegExp _argRegex = RegExp(r'-MF\s+\S+\s+');
6060

6161
// Filter out any extra commands that were appended to the compile command.
6262
static final RegExp _extraCommandRegex = RegExp(r'&&.*$');
@@ -67,6 +67,11 @@ class Command {
6767
String get tidyArgs {
6868
return _tidyArgs ??= (() {
6969
String result = command;
70+
result = result.replaceAll(r'\s+', ' ');
71+
// Remove everything that comes before the compiler command.
72+
result = result.split(' ')
73+
.skipWhile((String s) => !_pathRegex.hasMatch(s))
74+
.join(' ');
7075
result = result.replaceAll(_pathRegex, '');
7176
result = result.replaceAll(_argRegex, '');
7277
result = result.replaceAll(_extraCommandRegex, '');
@@ -81,7 +86,7 @@ class Command {
8186
return _tidyPath ??= _pathRegex.stringMatch(command)?.replaceAll(
8287
'clang/bin/clang',
8388
'clang/bin/clang-tidy',
84-
) ?? '';
89+
).replaceAll('clang-tidy++', 'clang-tidy') ?? '';
8590
}
8691

8792
/// Whether this command operates on any of the files in `queries`.

tools/clang_tidy/test/clang_tidy_test.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,5 +586,29 @@ Future<int> main(List<String> args) async {
586586
expect(command.tidyArgs.trim(), 'filename');
587587
});
588588

589+
test('Command filters out the -MF flag', () {
590+
final Command command = Command.fromMap(<String, String>{
591+
'directory': '/unused',
592+
'command':
593+
'../../buildtools/mac-x64/clang/bin/clang -MF stuff filename ',
594+
'file': 'unused',
595+
});
596+
expect(command.tidyArgs.trim(), 'filename');
597+
});
598+
599+
test('Command filters out rewrapper command before a compile command', () {
600+
final Command command = Command.fromMap(<String, String>{
601+
'directory': '/unused',
602+
'command':
603+
'flutter/engine/src/buildtools/mac-arm64/reclient/rewrapper '
604+
'--cfg=flutter/engine/src/flutter/build/rbe/rewrapper-mac-arm64.cfg '
605+
'--exec_root=flutter/engine/src/ '
606+
'--labels=type=compile,compiler=clang,lang=cpp '
607+
'../../buildtools/mac-x64/clang/bin/clang++ filename ',
608+
'file': 'unused',
609+
});
610+
expect(command.tidyArgs.trim(), 'filename');
611+
});
612+
589613
return 0;
590614
}

0 commit comments

Comments
 (0)