From 923436da87317aed7eb1b53379f9919275f3cddc Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Mon, 8 Jan 2024 14:41:45 -0800 Subject: [PATCH] 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 --- .../src/flutter/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/engine/src/flutter/tools/clang_tidy/lib/src/command.dart b/engine/src/flutter/tools/clang_tidy/lib/src/command.dart index 38a8c9a455..980841038c 100644 --- a/engine/src/flutter/tools/clang_tidy/lib/src/command.dart +++ b/engine/src/flutter/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/engine/src/flutter/tools/clang_tidy/test/clang_tidy_test.dart b/engine/src/flutter/tools/clang_tidy/test/clang_tidy_test.dart index f50175d5b0..f27fe82c83 100644 --- a/engine/src/flutter/tools/clang_tidy/test/clang_tidy_test.dart +++ b/engine/src/flutter/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; }