build.dart 3.04 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 6 7
import 'package:meta/meta.dart';

import '../build_info.dart';
8 9 10
import '../commands/build_linux.dart';
import '../commands/build_macos.dart';
import '../commands/build_windows.dart';
11
import '../globals.dart' as globals;
12
import '../runner/flutter_command.dart';
13
import 'build_aar.dart';
14
import 'build_apk.dart';
15
import 'build_appbundle.dart';
16
import 'build_bundle.dart';
17
import 'build_fuchsia.dart';
18
import 'build_ios.dart';
xster's avatar
xster committed
19
import 'build_ios_framework.dart';
20
import 'build_web.dart';
21
import 'build_winuwp.dart';
22

23
class BuildCommand extends FlutterCommand {
24
  BuildCommand({ bool verboseHelp = false }) {
25 26 27 28 29
    _addSubcommand(BuildAarCommand(verboseHelp: verboseHelp));
    _addSubcommand(BuildApkCommand(verboseHelp: verboseHelp));
    _addSubcommand(BuildAppBundleCommand(verboseHelp: verboseHelp));
    _addSubcommand(BuildIOSCommand(verboseHelp: verboseHelp));
    _addSubcommand(BuildIOSFrameworkCommand(
30
      buildSystem: globals.buildSystem,
31
      verboseHelp: verboseHelp,
32
    ));
33 34 35 36 37
    _addSubcommand(BuildIOSArchiveCommand(verboseHelp: verboseHelp));
    _addSubcommand(BuildBundleCommand(verboseHelp: verboseHelp));
    _addSubcommand(BuildWebCommand(verboseHelp: verboseHelp));
    _addSubcommand(BuildMacosCommand(verboseHelp: verboseHelp));
    _addSubcommand(BuildLinuxCommand(
38 39 40
      operatingSystemUtils: globals.os,
      verboseHelp: verboseHelp
    ));
41 42 43 44 45 46 47 48 49
    _addSubcommand(BuildWindowsCommand(verboseHelp: verboseHelp));
    _addSubcommand(BuildWindowsUwpCommand(verboseHelp: verboseHelp));
    _addSubcommand(BuildFuchsiaCommand(verboseHelp: verboseHelp));
  }

  void _addSubcommand(BuildSubCommand command) {
    if (command.supported) {
      addSubcommand(command);
    }
50 51
  }

52
  @override
53
  final String name = 'build';
54 55

  @override
56
  final String description = 'Build an executable app or install bundle.';
57

58 59 60
  @override
  String get category => FlutterCommandCategory.project;

61
  @override
62
  Future<FlutterCommandResult> runCommand() async => FlutterCommandResult.fail();
63
}
64

65
abstract class BuildSubCommand extends FlutterCommand {
66
  BuildSubCommand({required bool verboseHelp}) {
67
    requiresPubspecYaml();
68
    usesFatalWarningsOption(verboseHelp: verboseHelp);
69
  }
70 71 72

  @override
  bool get reportNullSafety => true;
73

74 75
  bool get supported => true;

76 77 78 79 80 81 82 83 84 85 86
  /// Display a message describing the current null safety runtime mode
  /// that was selected.
  ///
  /// This is similar to the run message in run_hot.dart
  @protected
  void displayNullSafetyMode(BuildInfo buildInfo) {
    globals.printStatus('');
    if (buildInfo.nullSafetyMode ==  NullSafetyMode.sound) {
      globals.printStatus('💪 Building with sound null safety 💪', emphasis: true);
    } else {
      globals.printStatus(
87
        'Building without sound null safety',
88 89 90 91 92 93 94 95
        emphasis: true,
      );
      globals.printStatus(
        'For more information see https://dart.dev/null-safety/unsound-null-safety',
      );
    }
    globals.printStatus('');
  }
96
}