build_macos.dart 1.61 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 8 9
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

import '../base/common.dart';
import '../build_info.dart';
import '../cache.dart';
10
import '../features.dart';
11
import '../globals.dart' as globals;
12
import '../macos/build_macos.dart';
13 14 15 16
import '../project.dart';
import '../runner/flutter_command.dart' show FlutterCommandResult;
import 'build.dart';

17
/// A command to build a macOS desktop target through a build shell script.
18
class BuildMacosCommand extends BuildSubCommand {
19
  BuildMacosCommand() {
20
    usesTargetOption();
21
    addBuildModeFlags();
22 23 24 25 26 27
  }

  @override
  final String name = 'macos';

  @override
28
  bool get hidden => !featureFlags.isMacOSEnabled || !globals.platform.isMacOS;
29 30 31 32 33 34 35

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

  @override
36
  String get description => 'build the macOS desktop target.';
37 38 39 40 41

  @override
  Future<FlutterCommandResult> runCommand() async {
    Cache.releaseLockEarly();
    final BuildInfo buildInfo = getBuildInfo();
42
    final FlutterProject flutterProject = FlutterProject.current();
43 44 45
    if (!featureFlags.isMacOSEnabled) {
      throwToolExit('"build macos" is not currently supported.');
    }
46
    if (!globals.platform.isMacOS) {
47 48
      throwToolExit('"build macos" only supported on macOS hosts.');
    }
49 50 51 52 53
    await buildMacOS(
      flutterProject: flutterProject,
      buildInfo: buildInfo,
      targetOverride: targetFile,
    );
54
    return FlutterCommandResult.success();
55 56
  }
}