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 f2132b2666..41dbea5914 100644 --- a/engine/src/flutter/tools/clang_tidy/lib/src/command.dart +++ b/engine/src/flutter/tools/clang_tidy/lib/src/command.dart @@ -141,6 +141,8 @@ class Command { '--fix', '--format-style=file', ], + if (options.enableCheckProfile) + '--enable-check-profile', '--', ]; args.addAll(tidyArgs.split(' ')); diff --git a/engine/src/flutter/tools/clang_tidy/lib/src/options.dart b/engine/src/flutter/tools/clang_tidy/lib/src/options.dart index 7e17e1f72e..401d34b8e8 100644 --- a/engine/src/flutter/tools/clang_tidy/lib/src/options.dart +++ b/engine/src/flutter/tools/clang_tidy/lib/src/options.dart @@ -36,6 +36,7 @@ class Options { this.warningsAsErrors, this.shardId, this.shardCommandsPaths = const [], + this.enableCheckProfile = false, StringSink? errSink, }) : checks = checksArg.isNotEmpty ? '--checks=$checksArg' : null, _errSink = errSink ?? io.stderr; @@ -82,6 +83,7 @@ class Options { warningsAsErrors: _platformSpecificWarningsAsErrors(options), shardCommandsPaths: shardCommandsPaths, shardId: shardId, + enableCheckProfile: options['enable-check-profile'] as bool, ); } @@ -194,6 +196,11 @@ class Options { help: 'Perform the given checks on the code. Defaults to the empty ' 'string, indicating all checks should be performed.', defaultsTo: '', + ) + ..addFlag( + 'enable-check-profile', + help: 'Enable per-check timing profiles and print a report to stderr.', + negatable: false, ); /// Whether to print a help message and exit. @@ -232,6 +239,9 @@ class Options { /// Whether checks should apply available fix-ups to the working copy. final bool fix; + /// Whether to enable per-check timing profiles and print a report to stderr. + final bool enableCheckProfile; + /// If there was a problem with the command line arguments, this string /// contains the error message. final String? errorMessage; 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 13b2e08188..9b2d6d0e16 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 @@ -128,6 +128,26 @@ Future main(List args) async { )); }); + test('Accepts --enable-check-profile', () async { + final StringBuffer outBuffer = StringBuffer(); + final StringBuffer errBuffer = StringBuffer(); + final ClangTidy clangTidy = ClangTidy.fromCommandLine( + [ + '--compile-commands', + buildCommands, + '--enable-check-profile', + ], + outSink: outBuffer, + errSink: errBuffer, + ); + + final int result = await clangTidy.run(); + + expect(result, equals(0)); + expect(clangTidy.options.enableCheckProfile, isTrue); + print(outBuffer); + }); + test('shard-id valid', () async { _withTempFile('shard-id-valid', (String path) { final Options options = Options.fromCommandLine( [