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

5
import '../base/analyze_size.dart';
6 7 8
import '../base/common.dart';
import '../build_info.dart';
import '../cache.dart';
9
import '../features.dart';
10
import '../globals.dart' as globals;
11
import '../macos/build_macos.dart';
12 13 14 15
import '../project.dart';
import '../runner/flutter_command.dart' show FlutterCommandResult;
import 'build.dart';

16
/// A command to build a macOS desktop target through a build shell script.
17
class BuildMacosCommand extends BuildSubCommand {
18
  BuildMacosCommand({
19
    required super.logger,
20
    required bool verboseHelp,
21
  }) : super(verboseHelp: verboseHelp) {
22
    addCommonDesktopBuildOptions(verboseHelp: verboseHelp);
23 24 25 26 27 28 29
    usesFlavorOption();
    argParser
      .addFlag('config-only',
        help: 'Update the project configuration without performing a build. '
          'This can be used in CI/CD process that create an archive to avoid '
          'performing duplicate work.'
    );
30 31 32 33 34 35
  }

  @override
  final String name = 'macos';

  @override
36
  bool get hidden => !featureFlags.isMacOSEnabled || !globals.platform.isMacOS;
37 38 39 40 41 42 43

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

  @override
44
  String get description => 'Build a macOS desktop application.';
45

46 47 48
  @override
  bool get supported => globals.platform.isMacOS;

49
  bool get configOnly => boolArg('config-only');
50

51 52
  @override
  Future<FlutterCommandResult> runCommand() async {
53
    final BuildInfo buildInfo = await getBuildInfo();
54
    final FlutterProject flutterProject = FlutterProject.current();
55
    if (!featureFlags.isMacOSEnabled) {
56
      throwToolExit('"build macos" is not currently supported. To enable, run "flutter config --enable-macos-desktop".');
57
    }
58
    if (!supported) {
59 60
      throwToolExit('"build macos" only supported on macOS hosts.');
    }
61
    displayNullSafetyMode(buildInfo);
62 63 64 65
    await buildMacOS(
      flutterProject: flutterProject,
      buildInfo: buildInfo,
      targetOverride: targetFile,
66
      verboseLogging: globals.logger.isVerbose,
67
      configOnly: configOnly,
68 69 70 71
      sizeAnalyzer: SizeAnalyzer(
        fileSystem: globals.fs,
        logger: globals.logger,
        appFilenamePattern: 'App',
72
        flutterUsage: globals.flutterUsage,
73
        analytics: analytics,
74
      ),
75
    );
76
    return FlutterCommandResult.success();
77 78
  }
}