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`
221221 }
222222
223223 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 ;
225226 }
226227
227228 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
8686 buildTargets.addAll (found);
8787 }
8888
89+ if (buildTargets.isEmpty) {
90+ environment.logger.error ('No targets found, nothing to test.' );
91+ return 1 ;
92+ }
93+
8994 // Make sure there is at least one test target.
9095 final List <ExecutableBuildTarget > testTargets = buildTargets
9196 .whereType <ExecutableBuildTarget >()
Original file line number Diff line number Diff line change @@ -55,6 +55,26 @@ interface class Gn {
5555 failOk: true ,
5656 );
5757 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+
5878 _environment.logger.fatal (
5979 'Failed to run `${command .join (' ' )}` (exit code ${process .exitCode })'
6080 '\n\n '
Original file line number Diff line number Diff line change @@ -424,6 +424,36 @@ void main() {
424424 }
425425 });
426426
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+
427457 test ('et help build line length is not too big' , () async {
428458 final List <String > prints = < String > [];
429459 await runZoned (
Original file line number Diff line number Diff line change @@ -319,3 +319,7 @@ String gnDescOutput() => '''
319319 }
320320}
321321''' ;
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