Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tools/engine_tool/lib/src/commands/query_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ et query targets //flutter/fml/... # List all targets under `//flutter/fml`
}

if (allTargets.isEmpty) {
environment.logger.fatal('Query unexpectedly returned an empty list');
environment.logger.error('No targets found, nothing to query.');
return 1;
}

for (final BuildTarget target in allTargets) {
Expand Down
5 changes: 5 additions & 0 deletions tools/engine_tool/lib/src/commands/test_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ et test //flutter/fml:fml_benchmarks # Run a single test target in `//flutter/f
buildTargets.addAll(found);
}

if (buildTargets.isEmpty) {
environment.logger.error('No targets found, nothing to test.');
return 1;
}

// Make sure there is at least one test target.
final List<ExecutableBuildTarget> testTargets = buildTargets
.whereType<ExecutableBuildTarget>()
Expand Down
20 changes: 20 additions & 0 deletions tools/engine_tool/lib/src/gn.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@ interface class Gn {
failOk: true,
);
if (process.exitCode != 0) {
// If the error was in the format:
// "The input testing/scenario_app:scenario_app matches no targets, configs or files."
//
// Then report a nicer error, versus a fatal error.
final stdout = process.stdout;
if (stdout.contains('matches no targets, configs or files')) {
final gnPattern = pattern.toGnPattern();
if (!gnPattern.startsWith('//flutter')) {
_environment.logger.warning(
'No targets matched the pattern `$gnPattern`.'
'Did you mean `//flutter/$gnPattern`?',
);
} else {
_environment.logger.warning(
'No targets matched the pattern `${pattern.toGnPattern()}`',
);
}
return <BuildTarget>[];
}

_environment.logger.fatal(
'Failed to run `${command.join(' ')}` (exit code ${process.exitCode})'
'\n\n'
Expand Down
30 changes: 30 additions & 0 deletions tools/engine_tool/test/build_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,36 @@ void main() {
}
});

test('build command gracefully handles no matched targets', () async {
final List<CannedProcess> cannedProcesses = <CannedProcess>[
CannedProcess((List<String> command) =>
command.contains('desc'),
stdout: fixtures.gnDescOutputEmpty(gnPattern: 'testing/scenario_app:sceario_app'),
exitCode: 1),
];
final TestEnvironment testEnv = TestEnvironment.withTestEngine(
cannedProcesses: cannedProcesses,
);
try {
final ToolCommandRunner runner = ToolCommandRunner(
environment: testEnv.environment,
configs: configs,
);
final int result = await runner.run(<String>[
'build',
'--config',
'host_debug',
// Intentionally omit the prefix '//flutter/' to trigger the warning.
'//testing/scenario_app',
]);
expect(result, equals(0));
expect(testEnv.testLogs.map((LogRecord r) => r.message).join(),
contains('No targets matched the pattern `testing/scenario_app'));
} finally {
testEnv.cleanup();
}
});

test('et help build line length is not too big', () async {
final List<String> prints = <String>[];
await runZoned(
Expand Down
4 changes: 4 additions & 0 deletions tools/engine_tool/test/fixtures.dart
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,7 @@ String gnDescOutput() => '''
}
}
''';

String gnDescOutputEmpty({required String gnPattern}) => '''
The input $gnPattern matches no targets, configs or files.
''';