diff --git a/packages/flutter_tools/lib/src/build_info.dart b/packages/flutter_tools/lib/src/build_info.dart index 853c947637..2f642581dd 100644 --- a/packages/flutter_tools/lib/src/build_info.dart +++ b/packages/flutter_tools/lib/src/build_info.dart @@ -39,7 +39,6 @@ class BuildInfo { this.webRenderer = WebRendererMode.auto, required this.treeShakeIcons, this.performanceMeasurementFile, - this.dartDefineConfigJsonMap = const {}, this.packagesPath = '.dart_tool/package_config.json', // TODO(zanderso): make this required and remove the default. this.nullSafetyMode = NullSafetyMode.sound, this.codeSizeDirectory, @@ -141,17 +140,6 @@ class BuildInfo { /// rerun tasks. final String? performanceMeasurementFile; - /// Configure a constant pool file. - /// Additional constant values to be made available in the Dart program. - /// - /// These values can be used with the const `fromEnvironment` constructors of - /// [String] the key and field are json values - /// json value - /// - /// An additional field `dartDefineConfigJsonMap` is provided to represent the native JSON value of the configuration file - /// - final Map dartDefineConfigJsonMap; - /// If provided, an output directory where one or more v8-style heap snapshots /// will be written for code size profiling. final String? codeSizeDirectory; @@ -277,11 +265,7 @@ class BuildInfo { /// /// Fields that are `null` are excluded from this configuration. Map toEnvironmentConfig() { - final Map map = {}; - dartDefineConfigJsonMap.forEach((String key, Object? value) { - map[key] = '$value'; - }); - final Map environmentMap = { + return { if (dartDefines.isNotEmpty) 'DART_DEFINES': encodeDartDefines(dartDefines), 'DART_OBFUSCATION': dartObfuscation.toString(), @@ -303,23 +287,13 @@ class BuildInfo { if (codeSizeDirectory != null) 'CODE_SIZE_DIRECTORY': codeSizeDirectory!, }; - map.forEach((String key, String value) { - if (environmentMap.containsKey(key)) { - globals.printWarning( - 'The key: [$key] already exists, you cannot use environment variables that have been used by the system!'); - } else { - // System priority is greater than user priority - environmentMap[key] = value; - } - }); - return environmentMap; } /// Convert this config to a series of project level arguments to be passed /// on the command line to gradle. List toGradleConfig() { // PACKAGE_CONFIG not currently supported. - final List result = [ + return [ if (dartDefines.isNotEmpty) '-Pdart-defines=${encodeDartDefines(dartDefines)}', '-Pdart-obfuscation=$dartObfuscation', @@ -342,16 +316,6 @@ class BuildInfo { for (final String projectArg in androidProjectArgs) '-P$projectArg', ]; - final Iterable gradleConfKeys = result.map((final String gradleConf) => gradleConf.split('=')[0].substring(2)); - dartDefineConfigJsonMap.forEach((String key, Object? value) { - if (gradleConfKeys.contains(key)) { - globals.printWarning( - 'The key: [$key] already exists, you cannot use gradle variables that have been used by the system!'); - } else { - result.add('-P$key=$value'); - } - }); - return result; } } diff --git a/packages/flutter_tools/lib/src/commands/assemble.dart b/packages/flutter_tools/lib/src/commands/assemble.dart index 1f9a212c07..542568c02e 100644 --- a/packages/flutter_tools/lib/src/commands/assemble.dart +++ b/packages/flutter_tools/lib/src/commands/assemble.dart @@ -260,7 +260,7 @@ class AssembleCommand extends FlutterCommand { final Map defineConfigJsonMap = extractDartDefineConfigJsonMap(); final List dartDefines = extractDartDefines(defineConfigJsonMap: defineConfigJsonMap); - if (dartDefines.isNotEmpty){ + if (dartDefines.isNotEmpty) { results[kDartDefines] = dartDefines.join(','); } diff --git a/packages/flutter_tools/lib/src/runner/flutter_command.dart b/packages/flutter_tools/lib/src/runner/flutter_command.dart index 13af44547b..a52083fb0d 100644 --- a/packages/flutter_tools/lib/src/runner/flutter_command.dart +++ b/packages/flutter_tools/lib/src/runner/flutter_command.dart @@ -1304,7 +1304,6 @@ abstract class FlutterCommand extends Command { dartExperiments: experiments, webRenderer: webRenderer, performanceMeasurementFile: performanceMeasurementFile, - dartDefineConfigJsonMap: defineConfigJsonMap, packagesPath: packagesPath ?? globals.fs.path.absolute('.dart_tool', 'package_config.json'), nullSafetyMode: nullSafetyMode, codeSizeDirectory: codeSizeDirectory, diff --git a/packages/flutter_tools/test/general.shard/build_info_test.dart b/packages/flutter_tools/test/general.shard/build_info_test.dart index 131a8530a8..ae1c92529d 100644 --- a/packages/flutter_tools/test/general.shard/build_info_test.dart +++ b/packages/flutter_tools/test/general.shard/build_info_test.dart @@ -243,7 +243,6 @@ void main() { treeShakeIcons: true, trackWidgetCreation: true, dartDefines: ['foo=2', 'bar=2'], - dartDefineConfigJsonMap: {'baz': '2'}, dartObfuscation: true, splitDebugInfoPath: 'foo/', frontendServerStarterPath: 'foo/bar/frontend_server_starter.dart', @@ -268,7 +267,6 @@ void main() { '-Pcode-size-directory=foo/code-size', '-Pfoo=bar', '-Pfizz=bazz', - '-Pbaz=2', ]); }); @@ -297,70 +295,4 @@ void main() { kDartDefines: 'MTIzMiw0NTY=,Mg==', }, kDartDefines), ['1232,456', '2']); }); - - group('Check repeated buildInfo variables', () { - testUsingContext('toEnvironmentConfig repeated variable', () async { - const BuildInfo buildInfo = BuildInfo(BuildMode.debug, '', - treeShakeIcons: true, - trackWidgetCreation: true, - dartDefines: ['foo=2', 'bar=2'], - dartDefineConfigJsonMap: {'DART_DEFINES': 'Define a variable, but it occupies the variable name of the system'}, - dartObfuscation: true, - ); - buildInfo.toEnvironmentConfig(); - expect(testLogger.warningText, contains('The key: [DART_DEFINES] already exists, you cannot use environment variables that have been used by the system')); - }); - - testUsingContext('toEnvironmentConfig repeated variable with DART_DEFINES not set', () async { - // Simulate operation flutterCommand.getBuildInfo with `dart-define-from-file` set dartDefines - const BuildInfo buildInfo = BuildInfo(BuildMode.debug, '', - treeShakeIcons: true, - dartDefines: ['DART_DEFINES=Define a variable, but it occupies the variable name of the system'], - trackWidgetCreation: true, - dartDefineConfigJsonMap: { 'DART_DEFINES' : 'Define a variable, but it occupies the variable name of the system'}, - dartObfuscation: true, - ); - buildInfo.toEnvironmentConfig(); - expect(testLogger.warningText, contains('The key: [DART_DEFINES] already exists, you cannot use environment variables that have been used by the system')); - - }); - - testUsingContext('toGradleConfig repeated variable', () async { - const BuildInfo buildInfo = BuildInfo(BuildMode.debug, '', - treeShakeIcons: true, - trackWidgetCreation: true, - dartDefines: ['foo=2', 'bar=2'], - dartDefineConfigJsonMap: {'dart-defines': 'Define a variable, but it occupies the variable name of the system'}, - dartObfuscation: true, - ); - buildInfo.toGradleConfig(); - expect(testLogger.warningText, contains('The key: [dart-defines] already exists, you cannot use gradle variables that have been used by the system')); - }); - - testUsingContext('toGradleConfig repeated variable with not set', () async { - // Simulate operation flutterCommand.getBuildInfo with `dart-define-from-file` set dartDefines - const BuildInfo buildInfo = BuildInfo(BuildMode.debug, '', - treeShakeIcons: true, - trackWidgetCreation: true, - dartDefines: ['dart-defines=Define a variable, but it occupies the variable name of the system'], - dartDefineConfigJsonMap: {'dart-defines': 'Define a variable, but it occupies the variable name of the system'}, - dartObfuscation: true, - ); - buildInfo.toGradleConfig(); - expect(testLogger.warningText, contains('The key: [dart-defines] already exists, you cannot use gradle variables that have been used by the system')); - }); - - testUsingContext('toGradleConfig with androidProjectArgs override gradle project variant', () async { - const BuildInfo buildInfo = BuildInfo(BuildMode.debug, '', - treeShakeIcons: true, - trackWidgetCreation: true, - androidProjectArgs: ['applicationId=com.google'], - dartDefineConfigJsonMap: {'applicationId': 'override applicationId'}, - dartObfuscation: true, - ); - buildInfo.toGradleConfig(); - expect(testLogger.warningText, contains('The key: [applicationId] already exists, you cannot use gradle variables that have been used by the system')); - }); - - }); }