When building clang-tidy commands, filter out the sed command that may be appended to each compile command (flutter/engine#49605)

See https://github.com/flutter/engine/pull/49542
This commit is contained in:
Jason Simmons
2024-01-08 14:41:45 -08:00
committed by GitHub
parent bf24ae2448
commit 923436da87
2 changed files with 15 additions and 0 deletions

View File

@@ -58,6 +58,9 @@ class Command {
static final RegExp _pathRegex = RegExp(r'\S*clang/bin/clang');
static final RegExp _argRegex = RegExp(r'-MF \S*');
// Filter out any extra commands that were appended to the compile command.
static final RegExp _extraCommandRegex = RegExp(r'&&.*$');
String? _tidyArgs;
/// The command line arguments of the command.
@@ -66,6 +69,7 @@ class Command {
String result = command;
result = result.replaceAll(_pathRegex, '');
result = result.replaceAll(_argRegex, '');
result = result.replaceAll(_extraCommandRegex, '');
return result;
})();
}

View File

@@ -575,5 +575,16 @@ Future<int> main(List<String> args) async {
expect(lintAction, equals(LintAction.lint));
});
test('Command filters out sed command after a compile command', () {
final Command command = Command.fromMap(<String, String>{
'directory': '/unused',
'command':
'../../buildtools/mac-x64/clang/bin/clang filename '
"&& sed -i 's@/b/f/w@../..@g' filename",
'file': 'unused',
});
expect(command.tidyArgs.trim(), 'filename');
});
return 0;
}