diff --git a/engine/src/flutter/tools/githooks/lib/githooks.dart b/engine/src/flutter/tools/githooks/lib/githooks.dart index aedcac4db14..14c3d4349ff 100644 --- a/engine/src/flutter/tools/githooks/lib/githooks.dart +++ b/engine/src/flutter/tools/githooks/lib/githooks.dart @@ -19,6 +19,10 @@ Future run(List args) async { // Add top-level arguments. runner.argParser + ..addFlag( + 'enable-clang-tidy', + help: 'Enable running clang-tidy on changed files.', + ) ..addOption( 'flutter', abbr: 'f', diff --git a/engine/src/flutter/tools/githooks/lib/src/pre_push_command.dart b/engine/src/flutter/tools/githooks/lib/src/pre_push_command.dart index 80b653cbabe..6b456cbe53e 100644 --- a/engine/src/flutter/tools/githooks/lib/src/pre_push_command.dart +++ b/engine/src/flutter/tools/githooks/lib/src/pre_push_command.dart @@ -20,10 +20,18 @@ class PrePushCommand extends Command { Future run() async { final Stopwatch sw = Stopwatch()..start(); final bool verbose = globalResults!['verbose']! as bool; + final bool enableClangTidy = globalResults!['enable-clang-tidy']! as bool; final String flutterRoot = globalResults!['flutter']! as String; + + if (!enableClangTidy) { + print('The clang-tidy check is disabled. To enable set the environment ' + 'variable PRE_PUSH_CLANG_TIDY to any value.'); + } + final List checkResults = [ await _runFormatter(flutterRoot, verbose), - await _runClangTidy(flutterRoot, verbose), + if (enableClangTidy) + await _runClangTidy(flutterRoot, verbose), ]; sw.stop(); io.stdout.writeln('pre-push checks finished in ${sw.elapsed}'); @@ -51,7 +59,8 @@ class PrePushCommand extends Command { 'compile_commands.json', )); if (!compileCommands.existsSync()) { - io.stderr.writeln('clang-tidy requires a fully built host_debug or host_debug_unopt build directory'); + io.stderr.writeln('clang-tidy requires a fully built host_debug or ' + 'host_debug_unopt build directory'); return false; } } diff --git a/engine/src/flutter/tools/githooks/pre-push b/engine/src/flutter/tools/githooks/pre-push index 2d0651e40dd..4e10ce870ad 100755 --- a/engine/src/flutter/tools/githooks/pre-push +++ b/engine/src/flutter/tools/githooks/pre-push @@ -15,15 +15,24 @@ import sys SRC_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) FLUTTER_DIR = os.path.join(SRC_ROOT, 'flutter') DART_BIN = os.path.join(SRC_ROOT, 'third_party', 'dart', 'tools', 'sdks', 'dart-sdk', 'bin') - +ENABLE_CLANG_TIDY = os.environ.get('PRE_PUSH_CLANG_TIDY') def Main(argv): + githook_args = [ + '--flutter', + FLUTTER_DIR, + ] + + if ENABLE_CLANG_TIDY is not None: + githook_args += [ + '--enable-clang-tidy', + ] + result = subprocess.run([ os.path.join(DART_BIN, 'dart'), '--disable-dart-dev', os.path.join(FLUTTER_DIR, 'tools', 'githooks', 'bin', 'main.dart'), - '--flutter', - FLUTTER_DIR, + ] + githook_args + [ 'pre-push', ], cwd=SRC_ROOT) return result.returncode