This repository was archived by the owner on Feb 25, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +61
-1
lines changed Expand file tree Collapse file tree 5 files changed +61
-1
lines changed Original file line number Diff line number Diff line change @@ -221,7 +221,8 @@ et query targets //flutter/fml/... # List all targets under `//flutter/fml`
221
221
}
222
222
223
223
if (allTargets.isEmpty) {
224
- environment.logger.fatal ('Query unexpectedly returned an empty list' );
224
+ environment.logger.error ('No targets found, nothing to query.' );
225
+ return 1 ;
225
226
}
226
227
227
228
for (final BuildTarget target in allTargets) {
Original file line number Diff line number Diff line change @@ -86,6 +86,11 @@ et test //flutter/fml:fml_benchmarks # Run a single test target in `//flutter/f
86
86
buildTargets.addAll (found);
87
87
}
88
88
89
+ if (buildTargets.isEmpty) {
90
+ environment.logger.error ('No targets found, nothing to test.' );
91
+ return 1 ;
92
+ }
93
+
89
94
// Make sure there is at least one test target.
90
95
final List <ExecutableBuildTarget > testTargets = buildTargets
91
96
.whereType <ExecutableBuildTarget >()
Original file line number Diff line number Diff line change @@ -55,6 +55,26 @@ interface class Gn {
55
55
failOk: true ,
56
56
);
57
57
if (process.exitCode != 0 ) {
58
+ // If the error was in the format:
59
+ // "The input testing/scenario_app:scenario_app matches no targets, configs or files."
60
+ //
61
+ // Then report a nicer error, versus a fatal error.
62
+ final stdout = process.stdout;
63
+ if (stdout.contains ('matches no targets, configs or files' )) {
64
+ final gnPattern = pattern.toGnPattern ();
65
+ if (! gnPattern.startsWith ('//flutter' )) {
66
+ _environment.logger.warning (
67
+ 'No targets matched the pattern `$gnPattern `.'
68
+ 'Did you mean `//flutter/$gnPattern `?' ,
69
+ );
70
+ } else {
71
+ _environment.logger.warning (
72
+ 'No targets matched the pattern `${pattern .toGnPattern ()}`' ,
73
+ );
74
+ }
75
+ return < BuildTarget > [];
76
+ }
77
+
58
78
_environment.logger.fatal (
59
79
'Failed to run `${command .join (' ' )}` (exit code ${process .exitCode })'
60
80
'\n\n '
Original file line number Diff line number Diff line change @@ -424,6 +424,36 @@ void main() {
424
424
}
425
425
});
426
426
427
+ test ('build command gracefully handles no matched targets' , () async {
428
+ final List <CannedProcess > cannedProcesses = < CannedProcess > [
429
+ CannedProcess ((List <String > command) =>
430
+ command.contains ('desc' ),
431
+ stdout: fixtures.gnDescOutputEmpty (gnPattern: 'testing/scenario_app:sceario_app' ),
432
+ exitCode: 1 ),
433
+ ];
434
+ final TestEnvironment testEnv = TestEnvironment .withTestEngine (
435
+ cannedProcesses: cannedProcesses,
436
+ );
437
+ try {
438
+ final ToolCommandRunner runner = ToolCommandRunner (
439
+ environment: testEnv.environment,
440
+ configs: configs,
441
+ );
442
+ final int result = await runner.run (< String > [
443
+ 'build' ,
444
+ '--config' ,
445
+ 'host_debug' ,
446
+ // Intentionally omit the prefix '//flutter/' to trigger the warning.
447
+ '//testing/scenario_app' ,
448
+ ]);
449
+ expect (result, equals (0 ));
450
+ expect (testEnv.testLogs.map ((LogRecord r) => r.message).join (),
451
+ contains ('No targets matched the pattern `testing/scenario_app' ));
452
+ } finally {
453
+ testEnv.cleanup ();
454
+ }
455
+ });
456
+
427
457
test ('et help build line length is not too big' , () async {
428
458
final List <String > prints = < String > [];
429
459
await runZoned (
Original file line number Diff line number Diff line change @@ -319,3 +319,7 @@ String gnDescOutput() => '''
319
319
}
320
320
}
321
321
''' ;
322
+
323
+ String gnDescOutputEmpty ({required String gnPattern}) => '''
324
+ The input $gnPattern matches no targets, configs or files.
325
+ ''' ;
You can’t perform that action at this time.
0 commit comments