Skip files in the clang-tidy driver if clang-tidy crashes when processing the file (flutter/engine#52379)

Recent versions of clang-tidy have been segfaulting when processing a few of the engine source files.  This patch skips over those errors so that the engine can roll Clang.

See https://github.com/flutter/flutter/issues/143178
This commit is contained in:
Jason Simmons
2024-05-06 07:48:53 -07:00
committed by GitHub
parent 7c751d83b2
commit 6964119253
3 changed files with 65 additions and 5 deletions

View File

@@ -3,7 +3,7 @@
// found in the LICENSE file.
import 'dart:convert' show LineSplitter, jsonDecode;
import 'dart:io' as io show File, stderr, stdout;
import 'dart:io' as io show File, ProcessSignal, stderr, stdout;
import 'package:engine_repo_tools/engine_repo_tools.dart';
import 'package:git_repo_tools/git_repo_tools.dart';
@@ -399,11 +399,12 @@ class ClangTidy {
Future<int> _runJobs(List<WorkerJob> jobs) async {
int result = 0;
int ignoredFailures = 0;
final Set<String> pendingJobs = <String>{for (final WorkerJob job in jobs) job.name};
void reporter(int totalJobs, int completed, int inProgress, int pending, int failed) {
return _logWithTimestamp(ProcessPool.defaultReportToString(
totalJobs, completed, inProgress, pending, failed));
totalJobs, completed, inProgress, pending, failed - ignoredFailures));
}
final ProcessPool pool = ProcessPool(
@@ -425,6 +426,15 @@ class ClangTidy {
}
continue;
}
// Recent versions of clang-tidy are segfaulting when processing some
// engine source files.
// (see https://github.com/flutter/flutter/issues/143178)
// TODO(jsimmons): remove this when the issue is fixed in Clang.
if (job.result.exitCode == -io.ProcessSignal.sigsegv.signalNumber) {
_errSink.writeln('❗ Crash when running clang-tidy for ${job.name}. Skipping this file.');
ignoredFailures++;
continue;
}
_errSink.writeln('❌ Failures for ${job.name}:');
if (!job.printOutput) {
final Exception? exception = job.exception;

View File

@@ -2,7 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:io' as io show Directory, File, Platform, stderr;
import 'dart:convert' show jsonEncode;
import 'dart:io' as io show Directory, File, Platform, ProcessSignal, stderr;
import 'package:clang_tidy/clang_tidy.dart';
import 'package:clang_tidy/src/command.dart';
@@ -611,5 +612,51 @@ Future<int> main(List<String> args) async {
expect(command.tidyArgs.trim(), 'filename');
});
test('Files that cause clang-tidy to segfault are skipped', () async {
final Fixture fileListFixture = Fixture.fromOptions(
Options(
buildCommandsPath: io.File(buildCommands),
lintTarget: const LintAll(),
),
);
final String firstFilePath = (await fileListFixture.tool.computeFilesOfInterest()).first.path;
final FakeProcessManager fakeProcessManager = FakeProcessManager(
onStart: (List<String> command) {
if (command.first.endsWith('clang-tidy')) {
return FakeProcess(exitCode: -io.ProcessSignal.sigsegv.signalNumber);
}
return FakeProcessManager.unhandledStart(command);
},
);
final List<dynamic> commandsData = <Map<String, dynamic>>[
<String, dynamic>{
'file': firstFilePath,
'directory': '/unused',
'command': 'clang/bin/clang $firstFilePath',
},
];
final io.File commands = io.File(path.join(
io.Directory.systemTemp.path, 'test_compile_commands.json'));
int result;
try {
commands.writeAsStringSync(jsonEncode(commandsData));
final Fixture fixture = Fixture.fromOptions(
Options(
buildCommandsPath: commands,
lintTarget: const LintAll(),
),
processManager: fakeProcessManager,
);
result = await fixture.tool.run();
} finally {
commands.deleteSync();
}
expect(result, 0);
});
return 0;
}

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'dart:io' as io;
@@ -101,11 +102,13 @@ final class FakeProcess implements io.Process {
String stderr = '',
}) : _exitCode = exitCode,
_stdout = stdout,
_stderr = stderr;
_stderr = stderr,
_stdin = io.IOSink(StreamController<List<int>>.broadcast().sink);
final int _exitCode;
final String _stdout;
final String _stderr;
final io.IOSink _stdin;
@override
Future<int> get exitCode async => _exitCode;
@@ -122,7 +125,7 @@ final class FakeProcess implements io.Process {
}
@override
io.IOSink get stdin => throw UnimplementedError();
io.IOSink get stdin => _stdin;
@override
Stream<List<int>> get stdout {