diff --git a/ci/clang_tidy.sh b/ci/clang_tidy.sh index 80cb7030fbd55..653256140cfa6 100755 --- a/ci/clang_tidy.sh +++ b/ci/clang_tidy.sh @@ -46,6 +46,11 @@ else fix_flag="--fix --lint-all" fi +# Determine wether to use x64 or arm64. +if command -v arch &> /dev/null && [[ $(arch) == "arm64" ]]; then + CLANG_TIDY_PATH="buildtools/mac-arm64/clang/bin/clang-tidy" +fi + COMPILE_COMMANDS="$SRC_DIR/out/host_debug/compile_commands.json" if [ ! -f "$COMPILE_COMMANDS" ]; then (cd "$SRC_DIR"; ./flutter/tools/gn) @@ -58,6 +63,7 @@ cd "$SCRIPT_DIR" --disable-dart-dev \ "$SRC_DIR/flutter/tools/clang_tidy/bin/main.dart" \ --src-dir="$SRC_DIR" \ + ${CLANG_TIDY_PATH:+--clang-tidy="$SRC_DIR/$CLANG_TIDY_PATH"} \ $fix_flag \ "$@" && true # errors ignored clang_tidy_return=$? diff --git a/shell/common/shell.cc b/shell/common/shell.cc index 88948eb9d7d62..c89e129cc7f68 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -177,6 +177,7 @@ std::unique_ptr Shell::Create( auto resource_cache_limit_calculator = std::make_shared( settings.resource_cache_max_bytes_threshold); + return CreateWithSnapshot(platform_data, // task_runners, // /*parent_thread_merger=*/nullptr, // diff --git a/tools/clang_tidy/lib/src/command.dart b/tools/clang_tidy/lib/src/command.dart index 41dbea5914592..38a8c9a455a7c 100644 --- a/tools/clang_tidy/lib/src/command.dart +++ b/tools/clang_tidy/lib/src/command.dart @@ -146,8 +146,9 @@ class Command { '--', ]; args.addAll(tidyArgs.split(' ')); + final String clangTidyPath = options.clangTidyPath?.path ?? tidyPath; return WorkerJob( - [tidyPath, ...args], + [clangTidyPath, ...args], workingDirectory: directory, name: 'clang-tidy on $filePath', printOutput: options.verbose, diff --git a/tools/clang_tidy/lib/src/options.dart b/tools/clang_tidy/lib/src/options.dart index f9d5320fb18a4..160210f1ef5cc 100644 --- a/tools/clang_tidy/lib/src/options.dart +++ b/tools/clang_tidy/lib/src/options.dart @@ -38,6 +38,7 @@ class Options { this.shardCommandsPaths = const [], this.enableCheckProfile = false, StringSink? errSink, + this.clangTidyPath, }) : checks = checksArg.isNotEmpty ? '--checks=$checksArg' : null, _errSink = errSink ?? io.stderr; @@ -69,6 +70,7 @@ class Options { StringSink? errSink, required List shardCommandsPaths, int? shardId, + io.File? clangTidyPath, }) { final LintTarget lintTarget; if (options.wasParsed('lint-all') || io.Platform.environment['FLUTTER_LINT_ALL'] != null) { @@ -92,6 +94,7 @@ class Options { shardCommandsPaths: shardCommandsPaths, shardId: shardId, enableCheckProfile: options['enable-check-profile'] as bool, + clangTidyPath: clangTidyPath, ); } @@ -138,12 +141,16 @@ class Options { if (shardId != null && (shardId > shardCommands.length || shardId < 0)) { return Options._error('Invalid shard-id value: $shardId.', errSink: errSink); } + final io.File? clangTidyPath = ((String? path) => path == null + ? null + : io.File(path))(argResults['clang-tidy'] as String?); return Options._fromArgResults( argResults, buildCommandsPath: buildCommands, errSink: errSink, shardCommandsPaths: shardCommands, shardId: shardId, + clangTidyPath: clangTidyPath, ); } @@ -227,6 +234,10 @@ class Options { 'string, indicating all checks should be performed.', defaultsTo: '', ) + ..addOption('clang-tidy', + help: + 'Path to the clang-tidy executable. Defaults to deriving the path\n' + 'from compile_commands.json.') ..addFlag( 'enable-check-profile', help: 'Enable per-check timing profiles and print a report to stderr.', @@ -276,6 +287,10 @@ class Options { final StringSink _errSink; + /// Override for which clang-tidy to use. If it is null it will be derived + /// instead. + final io.File? clangTidyPath; + /// Print command usage with an additional message. void printUsage({String? message, required Engine? engine}) { if (message != null) { diff --git a/tools/clang_tidy/test/clang_tidy_test.dart b/tools/clang_tidy/test/clang_tidy_test.dart index da3bbf921d171..370c989bfa8a7 100644 --- a/tools/clang_tidy/test/clang_tidy_test.dart +++ b/tools/clang_tidy/test/clang_tidy_test.dart @@ -214,6 +214,23 @@ Future main(List args) async { }); }); + test('clang-tidy specified', () async { + _withTempFile('shard-id-valid', (String path) { + final Options options = Options.fromCommandLine( [ + '--clang-tidy=foo/bar', + ],); + expect(options.clangTidyPath, isNotNull); + expect(options.clangTidyPath!.path, equals('foo/bar')); + }); + }); + + test('clang-tidy unspecified', () async { + _withTempFile('shard-id-valid', (String path) { + final Options options = Options.fromCommandLine( [],); + expect(options.clangTidyPath, isNull); + }); + }); + test('shard-id invalid', () async { _withTempFile('shard-id-valid', (String path) { final StringBuffer errBuffer = StringBuffer();