build_fuchsia.dart 2.91 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import '../base/common.dart';
import '../build_info.dart';
import '../cache.dart';
8
import '../features.dart';
9
import '../fuchsia/fuchsia_build.dart';
10
import '../fuchsia/fuchsia_pm.dart';
11
import '../globals.dart' as globals;
12 13 14 15 16 17
import '../project.dart';
import '../runner/flutter_command.dart' show FlutterCommandResult;
import 'build.dart';

/// A command to build a Fuchsia target.
class BuildFuchsiaCommand extends BuildSubCommand {
18
  BuildFuchsiaCommand({
19
    required bool verboseHelp,
20
  }) : super(verboseHelp: verboseHelp) {
21
    addTreeShakeIconsFlag();
22
    usesTargetOption();
23
    usesDartDefineOption();
24
    addBuildModeFlags(verboseHelp: verboseHelp);
25 26
    addNullSafetyModeOptions(hide: !verboseHelp);
    addEnableExperimentation(hide: !verboseHelp);
27 28 29 30 31 32 33 34 35 36 37
    argParser.addOption(
      'runner-source',
      help: 'The package source to use for the flutter_runner. '
            '"${FuchsiaPackageServer.deviceHost}" implies using a runner already on the device. '
            '"${FuchsiaPackageServer.toolHost}" implies using a runner distributed with Flutter.',
      allowed: <String>[
        FuchsiaPackageServer.deviceHost,
        FuchsiaPackageServer.toolHost,
      ],
      defaultsTo: FuchsiaPackageServer.toolHost,
    );
38 39 40 41 42
    argParser.addOption('target-platform',
      defaultsTo: 'fuchsia-x64',
      allowed: <String>['fuchsia-arm64', 'fuchsia-x64'],
      help: 'The target platform for which the app is compiled.',
    );
43 44 45 46 47 48 49 50 51 52 53 54 55 56
  }

  @override
  final String name = 'fuchsia';

  @override
  bool hidden = true;

  @override
  Future<Set<DevelopmentArtifact>> get requiredArtifacts async => <DevelopmentArtifact>{
    DevelopmentArtifact.fuchsia,
  };

  @override
57
  String get description => 'Build the Fuchsia target (Experimental).';
58

59 60 61
  @override
  bool get supported => globals.platform.isLinux || globals.platform.isMacOS;

62 63
  @override
  Future<FlutterCommandResult> runCommand() async {
64 65 66 67 68 69
    if (!featureFlags.isFuchsiaEnabled) {
      throwToolExit(
        '"build fuchsia" is currently disabled. See "flutter config" for more '
        'information.'
      );
    }
70
    final BuildInfo buildInfo = await getBuildInfo();
71
    final FlutterProject flutterProject = FlutterProject.current();
72
    if (!supported) {
73
      throwToolExit('"build fuchsia" is only supported on Linux and MacOS hosts.');
74 75
    }
    if (!flutterProject.fuchsia.existsSync()) {
76
      throwToolExit('No Fuchsia project is configured.');
77
    }
78
    displayNullSafetyMode(buildInfo);
79
    await buildFuchsia(
80 81
      fuchsiaProject: flutterProject.fuchsia,
      target: targetFile,
82
      targetPlatform: getTargetPlatformForName(stringArgDeprecated('target-platform')!),
83
      buildInfo: buildInfo,
84
      runnerPackageSource: stringArgDeprecated('runner-source')!,
85
    );
86
    return FlutterCommandResult.success();
87 88
  }
}