diff --git a/engine/src/flutter/tools/clangd_check/bin/main.dart b/engine/src/flutter/tools/clangd_check/bin/main.dart index e024ac2cd6..fe3570531b 100644 --- a/engine/src/flutter/tools/clangd_check/bin/main.dart +++ b/engine/src/flutter/tools/clangd_check/bin/main.dart @@ -51,9 +51,30 @@ void main(List args) { } String? clangd = results['clangd'] as String?; - final Map entry = compileCommands.first! as Map; + // To improve determinism, check the first clangd item that matches the asset fixture file. + Map? selectedEntry; + for (final Object? entry in compileCommands) { + if (entry is Map) { + final String? file = entry['file'] as String?; + if (file != null && file.endsWith('_fl__fl_assets_fixtures.cc')) { + selectedEntry = entry; + break; + } + } else { + io.stderr.writeln('Unexpected: compile_commands.json has an unexpected format'); + io.stderr.writeln('First entry: ${const JsonEncoder.withIndent(' ').convert(entry)}'); + io.exitCode = 1; + return; + } + } + if (selectedEntry == null) { + io.stderr.writeln('No compile_commands.json entry found for _fl__fl_assets_fixtures.cc'); + io.exitCode = 1; + return; + } + final String checkFile; - if (entry case { + if (selectedEntry case { 'command': final String command, 'directory': final String directory, 'file': final String file, @@ -94,7 +115,7 @@ void main(List args) { } } else { io.stderr.writeln('Unexpected: compile_commands.json has an unexpected format'); - io.stderr.writeln('First entry: ${const JsonEncoder.withIndent(' ').convert(entry)}'); + io.stderr.writeln('First entry: ${const JsonEncoder.withIndent(' ').convert(selectedEntry)}'); io.exitCode = 1; return; } @@ -134,7 +155,7 @@ void main(List args) { } } on io.ProcessException catch (e) { io.stderr.writeln('Failed to run clangd: $e'); - io.stderr.writeln(const JsonEncoder.withIndent(' ').convert(entry)); + io.stderr.writeln(const JsonEncoder.withIndent(' ').convert(selectedEntry)); io.exitCode = 1; } finally { // Remove the copied .clangd file from the engine root directory.