flutter_command.dart 23.7 KB
Newer Older
1 2 3 4 5 6
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

7
import 'package:args/args.dart';
8
import 'package:args/command_runner.dart';
9
import 'package:meta/meta.dart';
10
import 'package:quiver/strings.dart';
11 12

import '../application_package.dart';
13
import '../base/common.dart';
14
import '../base/context.dart';
15
import '../base/file_system.dart';
16
import '../base/io.dart' as io;
17
import '../base/terminal.dart';
18
import '../base/time.dart';
19
import '../base/user_messages.dart';
20
import '../base/utils.dart';
21
import '../build_info.dart';
22
import '../bundle.dart' as bundle;
23
import '../cache.dart';
24
import '../dart/package_map.dart';
25
import '../dart/pub.dart';
26
import '../device.dart';
27
import '../doctor.dart';
28
import '../features.dart';
29
import '../globals.dart';
30
import '../project.dart';
31
import '../reporting/reporting.dart';
32 33
import 'flutter_command_runner.dart';

34 35
export '../cache.dart' show DevelopmentArtifact;

36 37 38 39 40 41 42
enum ExitStatus {
  success,
  warning,
  fail,
}

/// [FlutterCommand]s' subclasses' [FlutterCommand.runCommand] can optionally
43
/// provide a [FlutterCommandResult] to furnish additional information for
44 45
/// analytics.
class FlutterCommandResult {
46
  const FlutterCommandResult(
47
    this.exitStatus, {
48
    this.timingLabelParts,
49
    this.endTimeOverride,
50
  });
51 52 53

  final ExitStatus exitStatus;

54
  /// Optional data that can be appended to the timing event.
55 56
  /// https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#timingLabel
  /// Do not add PII.
57
  final List<String> timingLabelParts;
58

59
  /// Optional epoch time when the command's non-interactive wait time is
60
  /// complete during the command's execution. Use to measure user perceivable
61 62
  /// latency without measuring user interaction time.
  ///
63
  /// [FlutterCommand] will automatically measure and report the command's
64
  /// complete time if not overridden.
65
  final DateTime endTimeOverride;
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80

  @override
  String toString() {
    switch (exitStatus) {
      case ExitStatus.success:
        return 'success';
      case ExitStatus.warning:
        return 'warning';
      case ExitStatus.fail:
        return 'fail';
      default:
        assert(false);
        return null;
    }
  }
81 82
}

83 84 85 86
/// Common flutter command line options.
class FlutterOptions {
  static const String kExtraFrontEndOptions = 'extra-front-end-options';
  static const String kExtraGenSnapshotOptions = 'extra-gen-snapshot-options';
87
  static const String kEnableExperiment = 'enable-experiment';
88 89
  static const String kFileSystemRoot = 'filesystem-root';
  static const String kFileSystemScheme = 'filesystem-scheme';
90 91
}

92
abstract class FlutterCommand extends Command<void> {
93 94 95
  /// The currently executing command (or sub-command).
  ///
  /// Will be `null` until the top-most command has begun execution.
96
  static FlutterCommand get current => context.get<FlutterCommand>();
97

98 99 100 101 102 103
  /// The option name for a custom observatory port.
  static const String observatoryPortOption = 'observatory-port';

  /// The flag name for whether or not to use ipv6.
  static const String ipv6Flag = 'ipv6';

104 105
  @override
  ArgParser get argParser => _argParser;
106 107 108 109
  final ArgParser _argParser = ArgParser(
    allowTrailingOptions: false,
    usageLineLength: outputPreferences.wrapText ? outputPreferences.wrapColumn : null,
  );
110

111
  @override
112 113
  FlutterCommandRunner get runner => super.runner;

114 115
  bool _requiresPubspecYaml = false;

116 117 118 119
  /// Whether this command uses the 'target' option.
  bool _usesTargetOption = false;

  bool _usesPubOption = false;
120

121 122 123 124
  bool _usesPortOption = false;

  bool _usesIpv6Flag = false;

125 126
  bool get shouldRunPub => _usesPubOption && argResults['pub'];

127 128
  bool get shouldUpdateCache => true;

129 130
  BuildMode _defaultBuildMode;

131 132 133 134
  void requiresPubspecYaml() {
    _requiresPubspecYaml = true;
  }

135 136 137
  void usesTargetOption() {
    argParser.addOption('target',
      abbr: 't',
138
      defaultsTo: bundle.defaultMainPath,
139
      help: 'The main entry-point file of the application, as run on the device.\n'
140
            'If the --target option is omitted, but a file name is provided on '
141 142
            'the command line, then that is used instead.',
      valueHelp: 'path');
143 144 145
    _usesTargetOption = true;
  }

146 147 148 149 150 151
  String get targetFile {
    if (argResults.wasParsed('target'))
      return argResults['target'];
    else if (argResults.rest.isNotEmpty)
      return argResults.rest.first;
    else
152
      return bundle.defaultMainPath;
153 154
  }

155 156 157
  void usesPubOption() {
    argParser.addFlag('pub',
      defaultsTo: true,
158
      help: 'Whether to run "flutter pub get" before executing this command.');
159 160 161
    _usesPubOption = true;
  }

162 163 164 165
  /// Adds flags for using a specific filesystem root and scheme.
  ///
  /// [hide] indicates whether or not to hide these options when the user asks
  /// for help.
166
  void usesFilesystemOptions({ @required bool hide }) {
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
    argParser
      ..addOption('output-dill',
        hide: hide,
        help: 'Specify the path to frontend server output kernel file.',
      )
      ..addMultiOption(FlutterOptions.kFileSystemRoot,
        hide: hide,
        help: 'Specify the path, that is used as root in a virtual file system\n'
            'for compilation. Input file name should be specified as Uri in\n'
            'filesystem-scheme scheme. Use only in Dart 2 mode.\n'
            'Requires --output-dill option to be explicitly specified.\n',
      )
      ..addOption(FlutterOptions.kFileSystemScheme,
        defaultsTo: 'org-dartlang-root',
        hide: hide,
        help: 'Specify the scheme that is used for virtual file system used in\n'
            'compilation. See more details on filesystem-root option.\n',
      );
  }

187 188 189 190
  /// Adds options for connecting to the Dart VM observatory port.
  void usesPortOptions() {
    argParser.addOption(observatoryPortOption,
        help: 'Listen to the given port for an observatory debugger connection.\n'
191
              'Specifying port 0 (the default) will find a random free port.',
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
    );
    _usesPortOption = true;
  }

  /// Gets the observatory port provided to in the 'observatory-port' option.
  ///
  /// If no port is set, returns null.
  int get observatoryPort {
    if (!_usesPortOption || argResults['observatory-port'] == null) {
      return null;
    }
    try {
      return int.parse(argResults['observatory-port']);
    } catch (error) {
      throwToolExit('Invalid port for `--observatory-port`: $error');
    }
    return null;
  }

  void usesIpv6Flag() {
    argParser.addFlag(ipv6Flag,
      hide: true,
      negatable: false,
      help: 'Binds to IPv6 localhost instead of IPv4 when the flutter tool '
            'forwards the host port to a device port. Not used when the '
            '--debug-port flag is not set.',
    );
    _usesIpv6Flag = true;
  }

  bool get ipv6 => _usesIpv6Flag ? argResults['ipv6'] : null;

224 225
  void usesBuildNumberOption() {
    argParser.addOption('build-number',
226 227
        help: 'An identifier used as an internal version number.\n'
              'Each build must have a unique identifier to differentiate it from previous builds.\n'
228 229 230
              'It is used to determine whether one build is more recent than another, with higher numbers indicating more recent build.\n'
              'On Android it is used as \'versionCode\'.\n'
              'On Xcode builds it is used as \'CFBundleVersion\'',
231
    );
232 233 234 235 236 237 238 239 240 241 242
  }

  void usesBuildNameOption() {
    argParser.addOption('build-name',
        help: 'A "x.y.z" string used as the version number shown to users.\n'
              'For each new version of your app, you will provide a version number to differentiate it from previous versions.\n'
              'On Android it is used as \'versionName\'.\n'
              'On Xcode builds it is used as \'CFBundleShortVersionString\'',
        valueHelp: 'x.y.z');
  }

243
  void usesIsolateFilterOption({ @required bool hide }) {
244 245 246 247 248 249 250
    argParser.addOption('isolate-filter',
      defaultsTo: null,
      hide: hide,
      help: 'Restricts commands to a subset of the available isolates (running instances of Flutter).\n'
            'Normally there\'s only one, but when adding Flutter to a pre-existing app it\'s possible to create multiple.');
  }

251
  void addBuildModeFlags({ bool defaultToRelease = true, bool verboseHelp = false }) {
252
    defaultBuildMode = defaultToRelease ? BuildMode.release : BuildMode.debug;
253

254 255
    argParser.addFlag('debug',
      negatable: false,
256
      help: 'Build a debug version of your app${defaultToRelease ? '' : ' (default mode)'}.');
257 258
    argParser.addFlag('profile',
      negatable: false,
259
      help: 'Build a version of your app specialized for performance profiling.');
260
    argParser.addFlag('release',
261
      negatable: false,
262
      help: 'Build a release version of your app${defaultToRelease ? ' (default mode)' : ''}.');
263 264
  }

265
  void usesFuchsiaOptions({ bool hide = false }) {
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
    argParser.addOption(
      'target-model',
      help: 'Target model that determines what core libraries are available',
      defaultsTo: 'flutter',
      hide: hide,
      allowed: const <String>['flutter', 'flutter_runner'],
    );
    argParser.addOption(
      'module',
      abbr: 'm',
      hide: hide,
      help: 'The name of the module (required if attaching to a fuchsia device)',
      valueHelp: 'module-name',
    );
  }

282 283
  set defaultBuildMode(BuildMode value) {
    _defaultBuildMode = value;
284 285
  }

286
  BuildMode getBuildMode() {
287 288
    final List<bool> modeFlags = <bool>[argResults['debug'], argResults['profile'], argResults['release']];
    if (modeFlags.where((bool flag) => flag).length > 1)
289
      throw UsageException('Only one of --debug, --profile, or --release can be specified.', null);
290
    if (argResults['debug']) {
291
      return BuildMode.debug;
292
    }
293 294 295 296 297 298
    if (argResults['profile']) {
      return BuildMode.profile;
    }
    if (argResults['release']) {
      return BuildMode.release;
    }
299
    return _defaultBuildMode;
300 301
  }

302 303 304 305
  void usesFlavorOption() {
    argParser.addOption(
      'flavor',
      help: 'Build a custom app flavor as defined by platform-specific build setup.\n'
306 307 308 309 310 311 312 313 314 315 316 317
            'Supports the use of product flavors in Android Gradle scripts, and '
            'the use of custom Xcode schemes.',
    );
  }

  void usesTrackWidgetCreation({ bool hasEffect = true, @required bool verboseHelp }) {
    argParser.addFlag(
      'track-widget-creation',
      hide: !hasEffect && !verboseHelp,
      defaultsTo: false, // this will soon be changed to true
      help: 'Track widget creation locations. This enables features such as the widget inspector. '
            'This parameter is only functional in debug mode (i.e. when compiling JIT, not AOT).',
318 319 320 321
    );
  }

  BuildInfo getBuildInfo() {
322 323 324 325
    final bool trackWidgetCreation = argParser.options.containsKey('track-widget-creation')
        ? argResults['track-widget-creation']
        : false;

326 327 328
    final String buildNumber = argParser.options.containsKey('build-number') && argResults['build-number'] != null
        ? argResults['build-number']
        : null;
329

330
    String extraFrontEndOptions =
331 332 333 334 335 336 337 338
        argParser.options.containsKey(FlutterOptions.kExtraFrontEndOptions)
            ? argResults[FlutterOptions.kExtraFrontEndOptions]
            : null;
    if (argParser.options.containsKey(FlutterOptions.kEnableExperiment) &&
        argResults[FlutterOptions.kEnableExperiment] != null) {
      for (String expFlag in argResults[FlutterOptions.kEnableExperiment]) {
        final String flag = '--enable-experiment=' + expFlag;
        if (extraFrontEndOptions != null) {
339
          extraFrontEndOptions += ',' + flag;
340
        } else {
341
          extraFrontEndOptions = flag;
342 343 344 345
        }
      }
    }

346
    return BuildInfo(getBuildMode(),
347 348 349
      argParser.options.containsKey('flavor')
        ? argResults['flavor']
        : null,
350
      trackWidgetCreation: trackWidgetCreation,
351
      extraFrontEndOptions: extraFrontEndOptions,
352
      extraGenSnapshotOptions: argParser.options.containsKey(FlutterOptions.kExtraGenSnapshotOptions)
353
          ? argResults[FlutterOptions.kExtraGenSnapshotOptions]
354
          : null,
355 356 357 358
      fileSystemRoots: argParser.options.containsKey(FlutterOptions.kFileSystemRoot)
          ? argResults[FlutterOptions.kFileSystemRoot] : null,
      fileSystemScheme: argParser.options.containsKey(FlutterOptions.kFileSystemScheme)
          ? argResults[FlutterOptions.kFileSystemScheme] : null,
359 360 361 362
      buildNumber: buildNumber,
      buildName: argParser.options.containsKey('build-name')
          ? argResults['build-name']
          : null,
363
    );
364 365
  }

366
  void setupApplicationPackages() {
367
    applicationPackages ??= ApplicationPackageStore();
368 369
  }

370
  /// The path to send to Google Analytics. Return null here to disable
371
  /// tracking of the command.
372 373 374 375 376 377 378 379 380 381
  Future<String> get usagePath async {
    if (parent is FlutterCommand) {
      final FlutterCommand commandParent = parent;
      final String path = await commandParent.usagePath;
      // Don't report for parents that return null for usagePath.
      return path == null ? null : '$path/$name';
    } else {
      return name;
    }
  }
382

383
  /// Additional usage values to be sent with the usage ping.
384 385
  Future<Map<CustomDimensions, String>> get usageValues async =>
      const <CustomDimensions, String>{};
386

387 388 389 390 391 392
  /// Runs this command.
  ///
  /// Rather than overriding this method, subclasses should override
  /// [verifyThenRunCommand] to perform any verification
  /// and [runCommand] to execute the command
  /// so that this method can record and report the overall time to analytics.
393
  @override
394
  Future<void> run() {
395
    final DateTime startTime = systemClock.now();
Devon Carew's avatar
Devon Carew committed
396

397
    return context.run<void>(
398 399 400
      name: 'command',
      overrides: <Type, Generator>{FlutterCommand: () => this},
      body: () async {
401
        if (flutterUsage.isFirstRun) {
402
          flutterUsage.printWelcome();
403
        }
404
        final String commandPath = await usagePath;
405 406
        FlutterCommandResult commandResult;
        try {
407
          commandResult = await verifyThenRunCommand(commandPath);
408 409 410 411
        } on ToolExit {
          commandResult = const FlutterCommandResult(ExitStatus.fail);
          rethrow;
        } finally {
412
          final DateTime endTime = systemClock.now();
413
          printTrace(userMessages.flutterElapsedTime(name, getElapsedAsMilliseconds(endTime.difference(startTime))));
414
          _sendPostUsage(commandPath, commandResult, startTime, endTime);
415 416 417
        }
      },
    );
Devon Carew's avatar
Devon Carew committed
418 419
  }

420 421 422 423
  /// Logs data about this command.
  ///
  /// For example, the command path (e.g. `build/apk`) and the result,
  /// as well as the time spent running it.
424 425
  void _sendPostUsage(String commandPath, FlutterCommandResult commandResult,
                      DateTime startTime, DateTime endTime) {
426 427 428 429
    if (commandPath == null) {
      return;
    }

430
    // Send command result.
431
    CommandResultEvent(commandPath, commandResult).send();
432 433

    // Send timing.
434 435 436 437 438 439
    final List<String> labels = <String>[
      if (commandResult?.exitStatus != null)
        getEnumName(commandResult.exitStatus),
      if (commandResult?.timingLabelParts?.isNotEmpty ?? false)
        ...commandResult.timingLabelParts,
    ];
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455

    final String label = labels
        .where((String label) => !isBlank(label))
        .join('-');
    flutterUsage.sendTiming(
      'flutter',
      name,
      // If the command provides its own end time, use it. Otherwise report
      // the duration of the entire execution.
      (commandResult?.endTimeOverride ?? endTime).difference(startTime),
      // Report in the form of `success-[parameter1-parameter2]`, all of which
      // can be null if the command doesn't provide a FlutterCommandResult.
      label: label == '' ? null : label,
    );
  }

456 457 458 459 460 461 462 463
  /// Perform validation then call [runCommand] to execute the command.
  /// Return a [Future] that completes with an exit code
  /// indicating whether execution was successful.
  ///
  /// Subclasses should override this method to perform verification
  /// then call this method to execute the command
  /// rather than calling [runCommand] directly.
  @mustCallSuper
464
  Future<FlutterCommandResult> verifyThenRunCommand(String commandPath) async {
465
    await validateCommand();
466

467 468
    // Populate the cache. We call this before pub get below so that the sky_engine
    // package is available in the flutter cache for pub to find.
469
    if (shouldUpdateCache) {
470
      await cache.updateAll(await requiredArtifacts);
471
    }
472

473
    if (shouldRunPub) {
474
      await pubGet(context: PubContext.getVerifyContext(name));
475
      final FlutterProject project = FlutterProject.current();
476
      await project.ensureReadyForPlatformSpecificTooling(checkProjects: true);
477
    }
478

479
    setupApplicationPackages();
Devon Carew's avatar
Devon Carew committed
480

481
    if (commandPath != null) {
482 483 484 485 486 487
      final Map<CustomDimensions, String> additionalUsageValues =
        <CustomDimensions, String>{
          ...?await usageValues,
          CustomDimensions.commandHasTerminal: io.stdout.hasTerminal ? 'true' : 'false',
        };
      Usage.command(commandPath, parameters: additionalUsageValues);
488 489
    }

490
    return await runCommand();
491 492
  }

493 494
  /// The set of development artifacts required for this command.
  ///
495
  /// Defaults to [DevelopmentArtifact.universal].
496
  Future<Set<DevelopmentArtifact>> get requiredArtifacts async => const <DevelopmentArtifact>{
497 498 499
    DevelopmentArtifact.universal,
  };

500
  /// Subclasses must implement this to execute the command.
501
  /// Optionally provide a [FlutterCommandResult] to send more details about the
502 503
  /// execution for analytics.
  Future<FlutterCommandResult> runCommand();
504

505
  /// Find and return all target [Device]s based upon currently connected
506
  /// devices and criteria entered by the user on the command line.
507
  /// If no device can be found that meets specified criteria,
508
  /// then print an error message and return null.
509
  Future<List<Device>> findAllTargetDevices() async {
510
    if (!doctor.canLaunchAnything) {
511
      printError(userMessages.flutterNoDevelopmentDevice);
512 513 514
      return null;
    }

515
    List<Device> devices = await deviceManager.findTargetDevices(FlutterProject.current());
516 517

    if (devices.isEmpty && deviceManager.hasSpecifiedDeviceId) {
518
      printStatus(userMessages.flutterNoMatchingDevice(deviceManager.specifiedDeviceId));
519
      return null;
520
    } else if (devices.isEmpty && deviceManager.hasSpecifiedAllDevices) {
521
      printStatus(userMessages.flutterNoDevicesFound);
522
      return null;
523
    } else if (devices.isEmpty) {
524
      printStatus(userMessages.flutterNoSupportedDevices);
525
      return null;
526
    } else if (devices.length > 1 && !deviceManager.hasSpecifiedAllDevices) {
527
      if (deviceManager.hasSpecifiedDeviceId) {
528
        printStatus(userMessages.flutterFoundSpecifiedDevices(devices.length, deviceManager.specifiedDeviceId));
529
      } else {
530
        printStatus(userMessages.flutterSpecifyDeviceWithAllOption);
531
        devices = await deviceManager.getAllConnectedDevices().toList();
532 533
      }
      printStatus('');
534
      await Device.printDevices(devices);
535 536
      return null;
    }
537 538 539 540 541 542
    return devices;
  }

  /// Find and return the target [Device] based upon currently connected
  /// devices and criteria entered by the user on the command line.
  /// If a device cannot be found that meets specified criteria,
543
  /// then print an error message and return null.
544 545 546 547 548
  Future<Device> findTargetDevice() async {
    List<Device> deviceList = await findAllTargetDevices();
    if (deviceList == null)
      return null;
    if (deviceList.length > 1) {
549
      printStatus(userMessages.flutterSpecifyDevice);
550 551 552 553 554 555
      deviceList = await deviceManager.getAllConnectedDevices().toList();
      printStatus('');
      await Device.printDevices(deviceList);
      return null;
    }
    return deviceList.single;
556 557
  }

558 559
  @protected
  @mustCallSuper
560
  Future<void> validateCommand() async {
561
    if (_requiresPubspecYaml && !PackageMap.isUsingCustomPackagesPath) {
562
      // Don't expect a pubspec.yaml file if the user passed in an explicit .packages file path.
563
      if (!fs.isFileSync('pubspec.yaml')) {
564
        throw ToolExit(userMessages.flutterNoPubspec);
565
      }
566

567
      if (fs.isFileSync('flutter.yaml')) {
568
        throw ToolExit(userMessages.flutterMergeYamlFiles);
569
      }
570 571

      // Validate the current package map only if we will not be running "pub get" later.
572
      if (parent?.name != 'pub' && !(_usesPubOption && argResults['pub'])) {
573
        final String error = PackageMap(PackageMap.globalPackagesPath).checkValid();
574
        if (error != null)
575
          throw ToolExit(error);
576
      }
577
    }
578 579

    if (_usesTargetOption) {
580
      final String targetPath = targetFile;
581
      if (!fs.isFileSync(targetPath))
582
        throw ToolExit(userMessages.flutterTargetFileMissing(targetPath));
583 584
    }
  }
585

586 587
  ApplicationPackageStore applicationPackages;
}
588

589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
/// A mixin which applies an implementation of [requiredArtifacts] that only
/// downloads artifacts corresponding to an attached device.
mixin DeviceBasedDevelopmentArtifacts on FlutterCommand {
  @override
  Future<Set<DevelopmentArtifact>> get requiredArtifacts async {
    // If there are no attached devices, use the default configuration.
    // Otherwise, only add development artifacts which correspond to a
    // connected device.
    final List<Device> devices = await deviceManager.getDevices().toList();
    if (devices.isEmpty) {
      return super.requiredArtifacts;
    }
    final Set<DevelopmentArtifact> artifacts = <DevelopmentArtifact>{
      DevelopmentArtifact.universal,
    };
    for (Device device in devices) {
      final TargetPlatform targetPlatform = await device.targetPlatform;
606 607 608
      final DevelopmentArtifact developmentArtifact = _artifactFromTargetPlatform(targetPlatform);
      if (developmentArtifact != null) {
        artifacts.add(developmentArtifact);
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
      }
    }
    return artifacts;
  }
}

/// A mixin which applies an implementation of [requiredArtifacts] that only
/// downloads artifacts corresponding to a target device.
mixin TargetPlatformBasedDevelopmentArtifacts on FlutterCommand {
  @override
  Future<Set<DevelopmentArtifact>> get requiredArtifacts async {
    // If there is no specified target device, fallback to the default
    // confiugration.
    final String rawTargetPlatform = argResults['target-platform'];
    final TargetPlatform targetPlatform = getTargetPlatformForName(rawTargetPlatform);
    if (targetPlatform == null) {
      return super.requiredArtifacts;
    }

    final Set<DevelopmentArtifact> artifacts = <DevelopmentArtifact>{
      DevelopmentArtifact.universal,
    };
631 632 633
    final DevelopmentArtifact developmentArtifact = _artifactFromTargetPlatform(targetPlatform);
    if (developmentArtifact != null) {
      artifacts.add(developmentArtifact);
634 635 636 637 638
    }
    return artifacts;
  }
}

639 640 641 642 643 644 645 646 647
// Returns the development artifact for the target platform, or null
// if none is supported
DevelopmentArtifact _artifactFromTargetPlatform(TargetPlatform targetPlatform) {
  switch (targetPlatform) {
    case TargetPlatform.android_arm:
    case TargetPlatform.android_arm64:
    case TargetPlatform.android_x64:
    case TargetPlatform.android_x86:
      return DevelopmentArtifact.android;
648
    case TargetPlatform.web_javascript:
649 650 651 652
      return DevelopmentArtifact.web;
    case TargetPlatform.ios:
      return DevelopmentArtifact.iOS;
    case TargetPlatform.darwin_x64:
653
      if (featureFlags.isMacOSEnabled) {
654 655 656 657
        return DevelopmentArtifact.macOS;
      }
      return null;
    case TargetPlatform.windows_x64:
658
      if (featureFlags.isWindowsEnabled) {
659 660 661 662
        return DevelopmentArtifact.windows;
      }
      return null;
    case TargetPlatform.linux_x64:
663
      if (featureFlags.isLinuxEnabled) {
664 665 666 667 668 669 670 671 672 673 674
        return DevelopmentArtifact.linux;
      }
      return null;
    case TargetPlatform.fuchsia:
    case TargetPlatform.tester:
      // No artifacts currently supported.
      return null;
  }
  return null;
}

675 676 677 678 679 680 681 682 683 684 685
/// A command which runs less analytics and checks to speed up startup time.
abstract class FastFlutterCommand extends FlutterCommand {
  @override
  Future<void> run() {
    return context.run<void>(
      name: 'command',
      overrides: <Type, Generator>{FlutterCommand: () => this},
      body: runCommand,
    );
  }
}