Use package:clang_tidy in git pre-push hook (flutter/engine#26986)
This commit is contained in:
@@ -4,8 +4,10 @@
|
||||
|
||||
// @dart = 2.12
|
||||
|
||||
import 'dart:io' as io;
|
||||
|
||||
import 'package:githooks/githooks.dart';
|
||||
|
||||
Future<int> main(List<String> args) async {
|
||||
return run(args);
|
||||
Future<void> main(List<String> args) async {
|
||||
io.exitCode = await run(args);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
import 'dart:io' as io;
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:clang_tidy/clang_tidy.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
/// The command that implements the pre-push githook
|
||||
@@ -23,7 +24,7 @@ class PrePushCommand extends Command<bool> {
|
||||
final bool verbose = globalResults!['verbose']! as bool;
|
||||
final String flutterRoot = globalResults!['flutter']! as String;
|
||||
final List<bool> checkResults = await Future.wait<bool>(<Future<bool>>[
|
||||
_runLinter(flutterRoot, verbose),
|
||||
_runClangTidy(flutterRoot, verbose),
|
||||
_runFormatter(flutterRoot, verbose),
|
||||
]);
|
||||
sw.stop();
|
||||
@@ -31,17 +32,42 @@ class PrePushCommand extends Command<bool> {
|
||||
return !checkResults.contains(false);
|
||||
}
|
||||
|
||||
Future<bool> _runLinter(String flutterRoot, bool verbose) async {
|
||||
if (io.Platform.isWindows) {
|
||||
return true;
|
||||
}
|
||||
return _runCheck(
|
||||
Future<bool> _runClangTidy(String flutterRoot, bool verbose) async {
|
||||
// First ensure that out/host_debug/compile_commands.json exists by running
|
||||
// //flutter/tools/gn.
|
||||
final io.File compileCommands = io.File(path.join(
|
||||
flutterRoot,
|
||||
path.join(flutterRoot, 'ci', 'lint.sh'),
|
||||
<String>[],
|
||||
'Linting check',
|
||||
verbose: verbose,
|
||||
'..',
|
||||
'out',
|
||||
'host_debug',
|
||||
'compile_commands.json',
|
||||
));
|
||||
if (!compileCommands.existsSync()) {
|
||||
final bool gnResult = await _runCheck(
|
||||
flutterRoot,
|
||||
path.join(flutterRoot, 'tools', 'gn'),
|
||||
<String>[],
|
||||
'GN for host_debug',
|
||||
verbose: verbose,
|
||||
);
|
||||
if (!gnResult) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
final StringBuffer outBuffer = StringBuffer();
|
||||
final StringBuffer errBuffer = StringBuffer();
|
||||
final ClangTidy clangTidy = ClangTidy(
|
||||
buildCommandsPath: compileCommands,
|
||||
repoPath: io.Directory(flutterRoot),
|
||||
outSink: outBuffer,
|
||||
errSink: errBuffer,
|
||||
);
|
||||
final int clangTidyResult = await clangTidy.run();
|
||||
if (clangTidyResult != 0) {
|
||||
io.stderr.write(errBuffer);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<bool> _runFormatter(String flutterRoot, bool verbose) {
|
||||
|
||||
@@ -29,13 +29,27 @@ dev_dependencies:
|
||||
dependency_overrides:
|
||||
args:
|
||||
path: ../../../third_party/dart/third_party/pkg/args
|
||||
async:
|
||||
path: ../../../third_party/dart/third_party/pkg/async
|
||||
async_helper:
|
||||
path: ../../../third_party/dart/pkg/async_helper
|
||||
clang_tidy:
|
||||
path: ../clang_tidy
|
||||
collection:
|
||||
path: ../../../third_party/dart/third_party/pkg/collection
|
||||
expect:
|
||||
path: ../../../third_party/dart/pkg/expect
|
||||
file:
|
||||
path: ../../../third_party/pkg/file/packages/file
|
||||
litetest:
|
||||
path: ../../testing/litetest
|
||||
meta:
|
||||
path: ../../../third_party/dart/pkg/meta
|
||||
path:
|
||||
path: ../../../third_party/dart/third_party/pkg/path
|
||||
platform:
|
||||
path: ../../../third_party/pkg/platform
|
||||
process:
|
||||
path: ../../../third_party/pkg/process
|
||||
process_runner:
|
||||
path: ../../../third_party/pkg/process_runner
|
||||
|
||||
Reference in New Issue
Block a user