1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright 2014 The Flutter Authors. All rights reserved.
// 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 '../bundle.dart';
import '../features.dart';
import '../globals.dart' as globals;
import '../project.dart';
import '../reporting/reporting.dart';
import '../runner/flutter_command.dart' show FlutterOptions, FlutterCommandResult;
import 'build.dart';
class BuildBundleCommand extends BuildSubCommand {
BuildBundleCommand({bool verboseHelp = false, this.bundleBuilder}) {
addTreeShakeIconsFlag();
usesTargetOption();
usesFilesystemOptions(hide: !verboseHelp);
usesBuildNumberOption();
addBuildModeFlags(verboseHelp: verboseHelp);
usesExtraFrontendOptions();
argParser
..addFlag(
'precompiled',
negatable: false,
help:
'If not provided, then '
'a debug build is always provided, regardless of build mode. If provided '
'then release is the default mode.',
)
// This option is still referenced by the iOS build scripts. We should
// remove it once we've updated those build scripts.
..addOption('asset-base', help: 'Ignored. Will be removed.', hide: !verboseHelp)
..addOption('manifest', defaultsTo: defaultManifestPath)
..addOption('private-key', defaultsTo: defaultPrivateKeyPath)
..addOption('depfile', defaultsTo: defaultDepfilePath)
..addOption('target-platform',
defaultsTo: 'android-arm',
allowed: const <String>[
'android-arm',
'android-arm64',
'android-x86',
'android-x64',
'ios',
'darwin-x64',
'linux-x64',
'windows-x64',
],
)
..addOption('asset-dir', defaultsTo: getAssetBuildDirectory())
..addMultiOption(FlutterOptions.kExtraGenSnapshotOptions,
splitCommas: true,
hide: true,
)
..addFlag('report-licensed-packages',
help: 'Whether to report the names of all the packages that are included '
"in the application's LICENSE file.",
defaultsTo: false);
usesPubOption();
usesTrackWidgetCreation(verboseHelp: verboseHelp);
bundleBuilder ??= BundleBuilder();
}
BundleBuilder bundleBuilder;
@override
final String name = 'bundle';
@override
final String description = 'Build the Flutter assets directory from your app.';
@override
final String usageFooter = 'The Flutter assets directory contains your '
'application code and resources; they are used by some Flutter Android and'
' iOS runtimes.';
@override
Future<Map<CustomDimensions, String>> get usageValues async {
final String projectDir = globals.fs.file(targetFile).parent.parent.path;
final FlutterProject futterProject = FlutterProject.fromPath(projectDir);
if (futterProject == null) {
return const <CustomDimensions, String>{};
}
return <CustomDimensions, String>{
CustomDimensions.commandBuildBundleTargetPlatform: stringArg('target-platform'),
CustomDimensions.commandBuildBundleIsModule: '${futterProject.isModule}',
};
}
@override
Future<FlutterCommandResult> runCommand() async {
final String targetPlatform = stringArg('target-platform');
final TargetPlatform platform = getTargetPlatformForName(targetPlatform);
if (platform == null) {
throwToolExit('Unknown platform: $targetPlatform');
}
// Check for target platforms that are only allowed via feature flags.
switch (platform) {
case TargetPlatform.darwin_x64:
if (!featureFlags.isMacOSEnabled) {
throwToolExit('macOS is not a supported target platform.');
}
break;
case TargetPlatform.windows_x64:
if (!featureFlags.isWindowsEnabled) {
throwToolExit('Windows is not a supported target platform.');
}
break;
case TargetPlatform.linux_x64:
if (!featureFlags.isLinuxEnabled) {
throwToolExit('Linux is not a supported target platform.');
}
break;
default:
break;
}
final BuildInfo buildInfo = getBuildInfo();
await bundleBuilder.build(
platform: platform,
buildInfo: buildInfo,
mainPath: targetFile,
manifestPath: stringArg('manifest'),
depfilePath: stringArg('depfile'),
privateKeyPath: stringArg('private-key'),
assetDirPath: stringArg('asset-dir'),
precompiledSnapshot: boolArg('precompiled'),
reportLicensedPackages: boolArg('report-licensed-packages'),
trackWidgetCreation: boolArg('track-widget-creation'),
extraFrontEndOptions: buildInfo.extraFrontEndOptions,
extraGenSnapshotOptions: buildInfo.extraGenSnapshotOptions,
fileSystemScheme: stringArg('filesystem-scheme'),
fileSystemRoots: stringsArg('filesystem-root'),
treeShakeIcons: buildInfo.treeShakeIcons,
);
return FlutterCommandResult.success();
}
}