[flutter_tools] Allow providing dart-defines to Android, iOS, macOS builds (#51714)

This commit is contained in:
Jonah Williams
2020-03-05 12:38:40 -08:00
committed by GitHub
parent aed961993d
commit ee60eeea3e
46 changed files with 293 additions and 257 deletions

View File

@@ -17,6 +17,7 @@ import 'build_system/depfile.dart';
import 'build_system/targets/dart.dart';
import 'build_system/targets/icon_tree_shaker.dart';
import 'cache.dart';
import 'convert.dart';
import 'dart/package_map.dart';
import 'devfs.dart';
import 'globals.dart' as globals;
@@ -54,7 +55,7 @@ class BundleBuilder {
/// The default `manifestPath` is `pubspec.yaml`
Future<void> build({
@required TargetPlatform platform,
BuildMode buildMode,
BuildInfo buildInfo,
String mainPath,
String manifestPath = defaultManifestPath,
String applicationKernelFilePath,
@@ -77,7 +78,7 @@ class BundleBuilder {
packagesPath ??= globals.fs.path.absolute(PackageMap.globalPackagesPath);
final FlutterProject flutterProject = FlutterProject.current();
await buildWithAssemble(
buildMode: buildMode ?? BuildMode.debug,
buildMode: buildInfo.mode,
targetPlatform: platform,
mainPath: mainPath,
flutterProject: flutterProject,
@@ -86,6 +87,7 @@ class BundleBuilder {
precompiled: precompiledSnapshot,
trackWidgetCreation: trackWidgetCreation,
treeShakeIcons: treeShakeIcons,
dartDefines: buildInfo.dartDefines,
);
// Work around for flutter_tester placing kernel artifacts in odd places.
if (applicationKernelFilePath != null) {
@@ -111,6 +113,7 @@ Future<void> buildWithAssemble({
@required bool precompiled,
bool trackWidgetCreation,
@required bool treeShakeIcons,
List<String> dartDefines,
}) async {
// If the precompiled flag was not passed, force us into debug mode.
buildMode = precompiled ? buildMode : BuildMode.debug;
@@ -126,6 +129,8 @@ Future<void> buildWithAssemble({
kTargetPlatform: getNameForTargetPlatform(targetPlatform),
kTrackWidgetCreation: trackWidgetCreation?.toString(),
kIconTreeShakerFlag: treeShakeIcons ? 'true' : null,
if (dartDefines != null && dartDefines.isNotEmpty)
kDartDefines: jsonEncode(dartDefines),
},
);
final Target target = buildMode == BuildMode.debug