diff --git a/engine/src/flutter/tools/clang_tidy/lib/clang_tidy.dart b/engine/src/flutter/tools/clang_tidy/lib/clang_tidy.dart index e722c89e03..6625c35278 100644 --- a/engine/src/flutter/tools/clang_tidy/lib/clang_tidy.dart +++ b/engine/src/flutter/tools/clang_tidy/lib/clang_tidy.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:convert' show jsonDecode; +import 'dart:convert' show LineSplitter, jsonDecode; import 'dart:io' as io show File, stderr, stdout; import 'package:meta/meta.dart'; @@ -228,6 +228,27 @@ class ClangTidy { return _ComputeJobsResult(jobs, sawMalformed); } + static Iterable _trimGenerator(String output) sync* { + const LineSplitter splitter = LineSplitter(); + final List lines = splitter.convert(output); + bool isPrintingError = false; + for (final String line in lines) { + if (line.contains(': error:') || line.contains(': warning:')) { + isPrintingError = true; + yield line; + } else if (line == ':') { + isPrintingError = false; + } else if (isPrintingError) { + yield line; + } + } + } + + /// Visible for testing. + /// Function for trimming raw clang-tidy output. + @visibleForTesting + static String trimOutput(String output) => _trimGenerator(output).join('\n'); + Future _runJobs(List jobs) async { int result = 0; final ProcessPool pool = ProcessPool(); @@ -236,10 +257,13 @@ class ClangTidy { continue; } _errSink.writeln('❌ Failures for ${job.name}:'); - _errSink.writeln(job.result.stdout); - final Exception? exception = job.exception; - if (exception != null) { - _errSink.writeln(exception); + if (!job.printOutput) { + final Exception? exception = job.exception; + if (exception != null) { + _errSink.writeln(trimOutput(exception.toString())); + } else { + _errSink.writeln(trimOutput(job.result.stdout)); + } } result = 1; } 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 70ff2cb06d..06301f398e 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 @@ -10,6 +10,34 @@ import 'package:clang_tidy/src/options.dart'; import 'package:litetest/litetest.dart'; import 'package:process_runner/process_runner.dart'; +// Recorded locally from clang-tidy. +const String _tidyOutput = ''' +/runtime.dart_isolate.o" in /Users/aaclarke/dev/engine/src/out/host_debug exited with code 1 +3467 warnings generated. +/Users/aaclarke/dev/engine/src/flutter/runtime/dart_isolate.cc:167:32: error: std::move of the const variable 'dart_entrypoint_args' has no effect; remove std::move() or make the variable non-const [performance-move-const-arg,-warnings-as-errors] + std::move(dart_entrypoint_args))) { + ^~~~~~~~~~ ~ +Suppressed 3474 warnings (3466 in non-user code, 8 NOLINT). +Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well. +1 warning treated as error +: +3467 warnings generated. +Suppressed 3474 warnings (3466 in non-user code, 8 NOLINT). +Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well. +1 warning treated as error + + + +'''; + +const String _tidyTrimmedOutput = ''' +/Users/aaclarke/dev/engine/src/flutter/runtime/dart_isolate.cc:167:32: error: std::move of the const variable 'dart_entrypoint_args' has no effect; remove std::move() or make the variable non-const [performance-move-const-arg,-warnings-as-errors] + std::move(dart_entrypoint_args))) { + ^~~~~~~~~~ ~ +Suppressed 3474 warnings (3466 in non-user code, 8 NOLINT). +Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well. +1 warning treated as error'''; + Future main(List args) async { if (args.isEmpty) { io.stderr.writeln( @@ -37,6 +65,10 @@ Future main(List args) async { expect(errBuffer.toString(), contains('Usage: ')); }); + test('trimmed clang-tidy output', () { + expect(_tidyTrimmedOutput, equals(ClangTidy.trimOutput(_tidyOutput))); + }); + test('Error when --compile-commands and --target-variant are used together', () async { final StringBuffer outBuffer = StringBuffer(); final StringBuffer errBuffer = StringBuffer();