22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5- // @dart = 2.9
6-
75import 'dart:async' ;
86import 'dart:io' show Directory;
97
@@ -13,6 +11,7 @@ import 'package:build_daemon/client.dart';
1311import 'package:build_daemon/data/build_status.dart' ;
1412import 'package:build_daemon/data/build_target.dart' ;
1513import 'package:build_daemon/data/server_log.dart' ;
14+ import 'package:collection/collection.dart' show IterableExtension;
1615import 'package:logging/logging.dart' as logging;
1716
1817import '../daemon_client.dart' ;
@@ -37,22 +36,21 @@ class BuildCommand extends Command<int> {
3736
3837 @override
3938 Future <int > run () async {
40- var unsupported =
41- argResults.rest .where ((arg) => ! arg.startsWith ('-' )).toList ();
39+ var extraArgs = argResults ? .rest ?? [];
40+ var unsupported = extraArgs .where ((arg) => ! arg.startsWith ('-' )).toList ();
4241 if (unsupported.isNotEmpty) {
4342 throw UsageException (
4443 'Arguments were provided that are not supported: '
4544 '"${unsupported .join (' ' )}".' ,
4645 argParser.usage);
4746 }
48- var extraArgs =
49- argResults.rest.where ((arg) => arg.startsWith ('-' )).toList ();
47+ var validExtraArgs = extraArgs.where ((arg) => arg.startsWith ('-' )).toList ();
5048
5149 var configuration = Configuration .fromArgs (argResults);
5250 configureLogWriter (configuration.verbose);
5351 var pubspecLock = await readPubspecLock (configuration);
5452 final arguments = buildRunnerArgs (pubspecLock, configuration)
55- ..addAll (extraArgs );
53+ ..addAll (validExtraArgs );
5654
5755 try {
5856 logWriter (logging.Level .INFO , 'Connecting to the build daemon...' );
@@ -66,12 +64,13 @@ class BuildCommand extends Command<int> {
6664 stackTrace: serverLog.stackTrace);
6765 },
6866 );
69- OutputLocation outputLocation;
67+ OutputLocation ? outputLocation;
68+ var outputInput = configuration.outputInput;
7069 if (configuration.outputPath != null ) {
7170 outputLocation = OutputLocation ((b) => b
7271 ..output = configuration.outputPath
7372 ..useSymlinks = false
74- ..hoist = configuration. outputInput.isNotEmpty);
73+ ..hoist = outputInput != null && outputInput.isNotEmpty);
7574 }
7675 client.registerBuildTarget (DefaultBuildTarget ((b) => b
7776 ..target = configuration.outputInput
@@ -80,9 +79,8 @@ class BuildCommand extends Command<int> {
8079 var exitCode = 0 ;
8180 var gotBuildStart = false ;
8281 await for (final result in client.buildResults) {
83- var targetResult = result.results.firstWhere (
84- (buildResult) => buildResult.target == configuration.outputInput,
85- orElse: () => null );
82+ var targetResult = result.results.firstWhereOrNull (
83+ (buildResult) => buildResult.target == configuration.outputInput);
8684 if (targetResult == null ) continue ;
8785 // We ignore any builds that happen before we get a `started` event,
8886 // because those could be stale (from some other client).
@@ -97,8 +95,9 @@ class BuildCommand extends Command<int> {
9795 exitCode = 1 ;
9896 }
9997
100- if (targetResult.error? .isNotEmpty == true ) {
101- logWriter (logging.Level .SEVERE , targetResult.error);
98+ var error = targetResult.error ?? '' ;
99+ if (error.isNotEmpty) {
100+ logWriter (logging.Level .SEVERE , error);
102101 }
103102 break ;
104103 }
0 commit comments