[flutter_tools] Reland: fix multiple dart defines (#54973)
This commit is contained in:
@@ -19,7 +19,6 @@ import '../base/terminal.dart';
|
||||
import '../base/utils.dart';
|
||||
import '../build_info.dart';
|
||||
import '../cache.dart';
|
||||
import '../convert.dart';
|
||||
import '../flutter_manifest.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../project.dart';
|
||||
@@ -331,7 +330,7 @@ Future<void> buildGradleApp({
|
||||
command.add('-Pshrink=true');
|
||||
}
|
||||
if (androidBuildInfo.buildInfo.dartDefines?.isNotEmpty ?? false) {
|
||||
command.add('-Pdart-defines=${jsonEncode(androidBuildInfo.buildInfo.dartDefines)}');
|
||||
command.add('-Pdart-defines=${androidBuildInfo.buildInfo.dartDefines.join(',')}');
|
||||
}
|
||||
if (shouldBuildPluginAsAar) {
|
||||
// Pass a system flag instead of a project flag, so this flag can be
|
||||
|
||||
@@ -14,7 +14,6 @@ import 'build_system/targets/dart.dart';
|
||||
import 'build_system/targets/icon_tree_shaker.dart';
|
||||
import 'build_system/targets/ios.dart';
|
||||
import 'cache.dart';
|
||||
import 'convert.dart';
|
||||
import 'globals.dart' as globals;
|
||||
import 'ios/bitcode.dart';
|
||||
import 'project.dart';
|
||||
@@ -87,7 +86,7 @@ class AotBuilder {
|
||||
kBuildMode: getNameForBuildMode(buildInfo.mode),
|
||||
kTargetPlatform: getNameForTargetPlatform(platform),
|
||||
kIconTreeShakerFlag: buildInfo.treeShakeIcons.toString(),
|
||||
kDartDefines: jsonEncode(buildInfo.dartDefines),
|
||||
kDartDefines: buildInfo.dartDefines.join(','),
|
||||
kBitcodeFlag: bitcode.toString(),
|
||||
if (buildInfo?.extraGenSnapshotOptions?.isNotEmpty ?? false)
|
||||
kExtraGenSnapshotOptions: buildInfo.extraGenSnapshotOptions.join(','),
|
||||
|
||||
@@ -7,7 +7,6 @@ import '../../base/build.dart';
|
||||
import '../../base/file_system.dart';
|
||||
import '../../build_info.dart';
|
||||
import '../../compile.dart';
|
||||
import '../../convert.dart';
|
||||
import '../../globals.dart' as globals;
|
||||
import '../../project.dart';
|
||||
import '../build_system.dart';
|
||||
@@ -390,21 +389,10 @@ abstract class CopyFlutterAotBundle extends Target {
|
||||
}
|
||||
}
|
||||
|
||||
/// Dart defines are encoded inside [Environment] as a JSON array.
|
||||
/// Dart defines are encoded inside [Environment] as a comma-separated list.
|
||||
List<String> parseDartDefines(Environment environment) {
|
||||
if (!environment.defines.containsKey(kDartDefines) || environment.defines[kDartDefines].isEmpty) {
|
||||
return const <String>[];
|
||||
}
|
||||
|
||||
final String dartDefinesJson = environment.defines[kDartDefines];
|
||||
try {
|
||||
final List<Object> parsedDefines = jsonDecode(dartDefinesJson) as List<Object>;
|
||||
return parsedDefines.cast<String>();
|
||||
} on FormatException {
|
||||
throw Exception(
|
||||
'The value of -D$kDartDefines is not formatted correctly.\n'
|
||||
'The value must be a JSON-encoded list of strings but was:\n'
|
||||
'$dartDefinesJson'
|
||||
);
|
||||
}
|
||||
return environment.defines[kDartDefines].split(',');
|
||||
}
|
||||
|
||||
@@ -168,6 +168,8 @@ class Dart2JSTarget extends Target {
|
||||
'--libraries-spec=$specPath',
|
||||
'-o',
|
||||
outputKernel.path,
|
||||
for (final String dartDefine in dartDefines)
|
||||
'-D$dartDefine',
|
||||
'--packages=$packageFile',
|
||||
'--cfe-only',
|
||||
environment.buildDir.childFile('main.dart').path,
|
||||
|
||||
@@ -17,7 +17,6 @@ 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;
|
||||
@@ -130,7 +129,7 @@ Future<void> buildWithAssemble({
|
||||
kTrackWidgetCreation: trackWidgetCreation?.toString(),
|
||||
kIconTreeShakerFlag: treeShakeIcons ? 'true' : null,
|
||||
if (dartDefines != null && dartDefines.isNotEmpty)
|
||||
kDartDefines: jsonEncode(dartDefines),
|
||||
kDartDefines: dartDefines.join(','),
|
||||
},
|
||||
artifacts: globals.artifacts,
|
||||
fileSystem: globals.fs,
|
||||
|
||||
@@ -87,6 +87,7 @@ class AssembleCommand extends FlutterCommand {
|
||||
'root of the current Flutter project.',
|
||||
);
|
||||
argParser.addOption(kExtraGenSnapshotOptions);
|
||||
argParser.addOption(kDartDefines);
|
||||
argParser.addOption(
|
||||
'resource-pool-size',
|
||||
help: 'The maximum number of concurrent tasks the build system will run.',
|
||||
@@ -182,6 +183,10 @@ class AssembleCommand extends FlutterCommand {
|
||||
if (argResults.wasParsed(kExtraGenSnapshotOptions)) {
|
||||
results[kExtraGenSnapshotOptions] = argResults[kExtraGenSnapshotOptions] as String;
|
||||
}
|
||||
// Workaround for dart-define formatting
|
||||
if (argResults.wasParsed(kDartDefines)) {
|
||||
results[kDartDefines] = argResults[kDartDefines] as String;
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ import '../base/terminal.dart';
|
||||
import '../base/utils.dart';
|
||||
import '../build_info.dart';
|
||||
import '../cache.dart';
|
||||
import '../convert.dart';
|
||||
import '../flutter_manifest.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../project.dart';
|
||||
@@ -236,7 +235,7 @@ List<String> _xcodeBuildSettingsLines({
|
||||
}
|
||||
|
||||
if (buildInfo.dartDefines?.isNotEmpty ?? false) {
|
||||
xcodeBuildSettings.add('DART_DEFINES=${jsonEncode(buildInfo.dartDefines)}');
|
||||
xcodeBuildSettings.add('DART_DEFINES=${buildInfo.dartDefines.join(',')}');
|
||||
}
|
||||
|
||||
if (buildInfo.extraFrontEndOptions?.isNotEmpty ?? false) {
|
||||
|
||||
@@ -13,7 +13,6 @@ import '../build_system/build_system.dart';
|
||||
import '../build_system/targets/dart.dart';
|
||||
import '../build_system/targets/icon_tree_shaker.dart';
|
||||
import '../build_system/targets/web.dart';
|
||||
import '../convert.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../platform_plugins.dart';
|
||||
import '../plugins.dart';
|
||||
@@ -49,7 +48,7 @@ Future<void> buildWeb(
|
||||
kTargetFile: target,
|
||||
kInitializePlatform: initializePlatform.toString(),
|
||||
kHasWebPlugins: hasWebPlugins.toString(),
|
||||
kDartDefines: jsonEncode(buildInfo.dartDefines),
|
||||
kDartDefines: buildInfo.dartDefines.join(','),
|
||||
kCspMode: csp.toString(),
|
||||
kIconTreeShakerFlag: buildInfo.treeShakeIcons.toString(),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user