From 1db054bc8eaee1faf70b8238d51ab2277d5dcc36 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Mon, 8 Jan 2024 21:05:10 +0000 Subject: [PATCH] When building clang-tidy commands, filter out the sed command that may be appended to each compile command See https://github.com/flutter/engine/pull/49542 --- tools/clang_tidy/lib/src/command.dart | 4 ++++ tools/clang_tidy/test/clang_tidy_test.dart | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/tools/clang_tidy/lib/src/command.dart b/tools/clang_tidy/lib/src/command.dart index 38a8c9a455a7c..980841038c1eb 100644 --- a/tools/clang_tidy/lib/src/command.dart +++ b/tools/clang_tidy/lib/src/command.dart @@ -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; })(); } diff --git a/tools/clang_tidy/test/clang_tidy_test.dart b/tools/clang_tidy/test/clang_tidy_test.dart index f50175d5b0bf5..f27fe82c8377e 100644 --- a/tools/clang_tidy/test/clang_tidy_test.dart +++ b/tools/clang_tidy/test/clang_tidy_test.dart @@ -575,5 +575,16 @@ Future main(List args) async { expect(lintAction, equals(LintAction.lint)); }); + test('Command filters out sed command after a compile command', () { + final Command command = Command.fromMap({ + '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; }