| 1 | // Copyright 2014 The Flutter Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | import 'package:meta/meta.dart' ; |
| 6 | |
| 7 | import '../android/android_sdk.dart'; |
| 8 | import '../base/file_system.dart'; |
| 9 | import '../base/logger.dart'; |
| 10 | import '../base/os.dart'; |
| 11 | import '../build_system/build_system.dart'; |
| 12 | import '../commands/build_linux.dart'; |
| 13 | import '../commands/build_macos.dart'; |
| 14 | import '../commands/build_windows.dart'; |
| 15 | import '../runner/flutter_command.dart'; |
| 16 | import 'build_aar.dart'; |
| 17 | import 'build_apk.dart'; |
| 18 | import 'build_appbundle.dart'; |
| 19 | import 'build_bundle.dart'; |
| 20 | import 'build_ios.dart'; |
| 21 | import 'build_ios_framework.dart'; |
| 22 | import 'build_macos_framework.dart'; |
| 23 | import 'build_web.dart'; |
| 24 | |
| 25 | class BuildCommand extends FlutterCommand { |
| 26 | BuildCommand({ |
| 27 | required FileSystem fileSystem, |
| 28 | required BuildSystem buildSystem, |
| 29 | required OperatingSystemUtils osUtils, |
| 30 | required Logger logger, |
| 31 | required AndroidSdk? androidSdk, |
| 32 | bool verboseHelp = false, |
| 33 | }) { |
| 34 | _addSubcommand( |
| 35 | BuildAarCommand( |
| 36 | fileSystem: fileSystem, |
| 37 | androidSdk: androidSdk, |
| 38 | logger: logger, |
| 39 | verboseHelp: verboseHelp, |
| 40 | ), |
| 41 | ); |
| 42 | _addSubcommand(BuildApkCommand(logger: logger, verboseHelp: verboseHelp)); |
| 43 | _addSubcommand(BuildAppBundleCommand(logger: logger, verboseHelp: verboseHelp)); |
| 44 | _addSubcommand(BuildIOSCommand(logger: logger, verboseHelp: verboseHelp)); |
| 45 | _addSubcommand( |
| 46 | BuildIOSFrameworkCommand(logger: logger, buildSystem: buildSystem, verboseHelp: verboseHelp), |
| 47 | ); |
| 48 | _addSubcommand( |
| 49 | BuildMacOSFrameworkCommand( |
| 50 | logger: logger, |
| 51 | buildSystem: buildSystem, |
| 52 | verboseHelp: verboseHelp, |
| 53 | ), |
| 54 | ); |
| 55 | _addSubcommand(BuildIOSArchiveCommand(logger: logger, verboseHelp: verboseHelp)); |
| 56 | _addSubcommand(BuildBundleCommand(logger: logger, verboseHelp: verboseHelp)); |
| 57 | _addSubcommand( |
| 58 | BuildWebCommand(fileSystem: fileSystem, logger: logger, verboseHelp: verboseHelp), |
| 59 | ); |
| 60 | _addSubcommand(BuildMacosCommand(logger: logger, verboseHelp: verboseHelp)); |
| 61 | _addSubcommand( |
| 62 | BuildLinuxCommand(logger: logger, operatingSystemUtils: osUtils, verboseHelp: verboseHelp), |
| 63 | ); |
| 64 | _addSubcommand( |
| 65 | BuildWindowsCommand(logger: logger, operatingSystemUtils: osUtils, verboseHelp: verboseHelp), |
| 66 | ); |
| 67 | } |
| 68 | |
| 69 | void _addSubcommand(BuildSubCommand command) { |
| 70 | if (command.supported) { |
| 71 | addSubcommand(command); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | @override |
| 76 | final name = 'build' ; |
| 77 | |
| 78 | @override |
| 79 | final description = 'Build an executable app or install bundle.' ; |
| 80 | |
| 81 | @override |
| 82 | String get category => FlutterCommandCategory.project; |
| 83 | |
| 84 | @override |
| 85 | Future<FlutterCommandResult> runCommand() async => FlutterCommandResult.fail(); |
| 86 | } |
| 87 | |
| 88 | abstract class BuildSubCommand extends FlutterCommand { |
| 89 | BuildSubCommand({required this.logger, required bool verboseHelp}) { |
| 90 | requiresPubspecYaml(); |
| 91 | usesFatalWarningsOption(verboseHelp: verboseHelp); |
| 92 | } |
| 93 | |
| 94 | @protected |
| 95 | final Logger logger; |
| 96 | |
| 97 | /// Whether this command is supported and should be shown. |
| 98 | bool get supported => true; |
| 99 | } |
| 100 | |