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

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

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tools/clang_tidy/lib/src/command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -66,6 +69,7 @@ class Command {
String result = command;
result = result.replaceAll(_pathRegex, '');
result = result.replaceAll(_argRegex, '');
result = result.replaceAll(_extraCommandRegex, '');
return result;
})();
}
Expand Down
11 changes: 11 additions & 0 deletions tools/clang_tidy/test/clang_tidy_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}