Clang-tidy: cleaned up the output. (flutter/engine#37059)

This commit is contained in:
gaaclarke
2022-11-01 18:15:15 -07:00
committed by GitHub
parent 6c93b7e903
commit 8fb750c029
2 changed files with 61 additions and 5 deletions

View File

@@ -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<String> _trimGenerator(String output) sync* {
const LineSplitter splitter = LineSplitter();
final List<String> 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<int> _runJobs(List<WorkerJob> 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;
}

View File

@@ -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<int> main(List<String> args) async {
if (args.isEmpty) {
io.stderr.writeln(
@@ -37,6 +65,10 @@ Future<int> main(List<String> 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();