diff --git a/tools/clang_tidy/lib/clang_tidy.dart b/tools/clang_tidy/lib/clang_tidy.dart index 66c4259512fc4..d5bc169471305 100644 --- a/tools/clang_tidy/lib/clang_tidy.dart +++ b/tools/clang_tidy/lib/clang_tidy.dart @@ -107,8 +107,11 @@ class ClangTidy { } } + final List buildCommandsData = jsonDecode( + options.buildCommandsPath.readAsStringSync(), + ) as List; final List changedFileBuildCommands = getLintCommandsForChangedFiles( - options.buildCommandsPath, + buildCommandsData, changedFiles, ); @@ -163,14 +166,11 @@ class ClangTidy { /// compute the lint commands to run. @visibleForTesting List getLintCommandsForChangedFiles( - io.File buildCommandsPath, + List buildCommandsData, List changedFiles, ) { - final List buildCommandMaps = jsonDecode( - buildCommandsPath.readAsStringSync(), - ) as List; final List buildCommands = [ - for (final dynamic c in buildCommandMaps) + for (final dynamic c in buildCommandsData) Command.fromMap(c as Map), ]; diff --git a/tools/clang_tidy/test/clang_tidy_test.dart b/tools/clang_tidy/test/clang_tidy_test.dart index 769a82415c76b..6dc15762bde93 100644 --- a/tools/clang_tidy/test/clang_tidy_test.dart +++ b/tools/clang_tidy/test/clang_tidy_test.dart @@ -159,8 +159,16 @@ Future main(List args) async { outSink: outBuffer, errSink: errBuffer, ); + const String filePath = '/path/to/a/source_file.cc'; + final List buildCommandsData = >[ + { + 'directory': '/unused', + 'command': '../../buildtools/mac-x64/clang/bin/clang $filePath', + 'file': filePath, + }, + ]; final List commands = clangTidy.getLintCommandsForChangedFiles( - clangTidy.options.buildCommandsPath, + buildCommandsData, [], ); @@ -177,13 +185,17 @@ Future main(List args) async { outSink: outBuffer, errSink: errBuffer, ); - final List fileList = await clangTidy.computeChangedFiles(); - final io.File file = fileList.firstWhere((io.File f) { - return f.path.endsWith('.cc'); - }); + const String filePath = '/path/to/a/source_file.cc'; + final List buildCommandsData = >[ + { + 'directory': '/unused', + 'command': '../../buildtools/mac-x64/clang/bin/clang $filePath', + 'file': filePath, + }, + ]; final List commands = clangTidy.getLintCommandsForChangedFiles( - clangTidy.options.buildCommandsPath, - [file], + buildCommandsData, + [io.File(filePath)], ); expect(commands, isNotEmpty);