Skip to content

Commit 25bed91

Browse files
authored
do not include entries from --dart-define-from-file files in the gradle config or environment during build (#136865)
Fixes flutter/flutter#130599 and flutter/flutter#136444
1 parent b5d8d77 commit 25bed91

File tree

4 files changed

+3
-108
lines changed

4 files changed

+3
-108
lines changed

packages/flutter_tools/lib/src/build_info.dart

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class BuildInfo {
3939
this.webRenderer = WebRendererMode.auto,
4040
required this.treeShakeIcons,
4141
this.performanceMeasurementFile,
42-
this.dartDefineConfigJsonMap = const <String, Object?>{},
4342
this.packagesPath = '.dart_tool/package_config.json', // TODO(zanderso): make this required and remove the default.
4443
this.nullSafetyMode = NullSafetyMode.sound,
4544
this.codeSizeDirectory,
@@ -141,17 +140,6 @@ class BuildInfo {
141140
/// rerun tasks.
142141
final String? performanceMeasurementFile;
143142

144-
/// Configure a constant pool file.
145-
/// Additional constant values to be made available in the Dart program.
146-
///
147-
/// These values can be used with the const `fromEnvironment` constructors of
148-
/// [String] the key and field are json values
149-
/// json value
150-
///
151-
/// An additional field `dartDefineConfigJsonMap` is provided to represent the native JSON value of the configuration file
152-
///
153-
final Map<String, Object?> dartDefineConfigJsonMap;
154-
155143
/// If provided, an output directory where one or more v8-style heap snapshots
156144
/// will be written for code size profiling.
157145
final String? codeSizeDirectory;
@@ -277,11 +265,7 @@ class BuildInfo {
277265
///
278266
/// Fields that are `null` are excluded from this configuration.
279267
Map<String, String> toEnvironmentConfig() {
280-
final Map<String, String> map = <String, String>{};
281-
dartDefineConfigJsonMap.forEach((String key, Object? value) {
282-
map[key] = '$value';
283-
});
284-
final Map<String, String> environmentMap = <String, String>{
268+
return <String, String>{
285269
if (dartDefines.isNotEmpty)
286270
'DART_DEFINES': encodeDartDefines(dartDefines),
287271
'DART_OBFUSCATION': dartObfuscation.toString(),
@@ -303,23 +287,13 @@ class BuildInfo {
303287
if (codeSizeDirectory != null)
304288
'CODE_SIZE_DIRECTORY': codeSizeDirectory!,
305289
};
306-
map.forEach((String key, String value) {
307-
if (environmentMap.containsKey(key)) {
308-
globals.printWarning(
309-
'The key: [$key] already exists, you cannot use environment variables that have been used by the system!');
310-
} else {
311-
// System priority is greater than user priority
312-
environmentMap[key] = value;
313-
}
314-
});
315-
return environmentMap;
316290
}
317291

318292
/// Convert this config to a series of project level arguments to be passed
319293
/// on the command line to gradle.
320294
List<String> toGradleConfig() {
321295
// PACKAGE_CONFIG not currently supported.
322-
final List<String> result = <String>[
296+
return <String>[
323297
if (dartDefines.isNotEmpty)
324298
'-Pdart-defines=${encodeDartDefines(dartDefines)}',
325299
'-Pdart-obfuscation=$dartObfuscation',
@@ -342,16 +316,6 @@ class BuildInfo {
342316
for (final String projectArg in androidProjectArgs)
343317
'-P$projectArg',
344318
];
345-
final Iterable<String> gradleConfKeys = result.map((final String gradleConf) => gradleConf.split('=')[0].substring(2));
346-
dartDefineConfigJsonMap.forEach((String key, Object? value) {
347-
if (gradleConfKeys.contains(key)) {
348-
globals.printWarning(
349-
'The key: [$key] already exists, you cannot use gradle variables that have been used by the system!');
350-
} else {
351-
result.add('-P$key=$value');
352-
}
353-
});
354-
return result;
355319
}
356320
}
357321

packages/flutter_tools/lib/src/commands/assemble.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ class AssembleCommand extends FlutterCommand {
260260

261261
final Map<String, Object?> defineConfigJsonMap = extractDartDefineConfigJsonMap();
262262
final List<String> dartDefines = extractDartDefines(defineConfigJsonMap: defineConfigJsonMap);
263-
if (dartDefines.isNotEmpty){
263+
if (dartDefines.isNotEmpty) {
264264
results[kDartDefines] = dartDefines.join(',');
265265
}
266266

packages/flutter_tools/lib/src/runner/flutter_command.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,6 @@ abstract class FlutterCommand extends Command<void> {
13041304
dartExperiments: experiments,
13051305
webRenderer: webRenderer,
13061306
performanceMeasurementFile: performanceMeasurementFile,
1307-
dartDefineConfigJsonMap: defineConfigJsonMap,
13081307
packagesPath: packagesPath ?? globals.fs.path.absolute('.dart_tool', 'package_config.json'),
13091308
nullSafetyMode: nullSafetyMode,
13101309
codeSizeDirectory: codeSizeDirectory,

packages/flutter_tools/test/general.shard/build_info_test.dart

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ void main() {
243243
treeShakeIcons: true,
244244
trackWidgetCreation: true,
245245
dartDefines: <String>['foo=2', 'bar=2'],
246-
dartDefineConfigJsonMap: <String, Object>{'baz': '2'},
247246
dartObfuscation: true,
248247
splitDebugInfoPath: 'foo/',
249248
frontendServerStarterPath: 'foo/bar/frontend_server_starter.dart',
@@ -268,7 +267,6 @@ void main() {
268267
'-Pcode-size-directory=foo/code-size',
269268
'-Pfoo=bar',
270269
'-Pfizz=bazz',
271-
'-Pbaz=2',
272270
]);
273271
});
274272

@@ -297,70 +295,4 @@ void main() {
297295
kDartDefines: 'MTIzMiw0NTY=,Mg==',
298296
}, kDartDefines), <String>['1232,456', '2']);
299297
});
300-
301-
group('Check repeated buildInfo variables', () {
302-
testUsingContext('toEnvironmentConfig repeated variable', () async {
303-
const BuildInfo buildInfo = BuildInfo(BuildMode.debug, '',
304-
treeShakeIcons: true,
305-
trackWidgetCreation: true,
306-
dartDefines: <String>['foo=2', 'bar=2'],
307-
dartDefineConfigJsonMap: <String, Object>{'DART_DEFINES': 'Define a variable, but it occupies the variable name of the system'},
308-
dartObfuscation: true,
309-
);
310-
buildInfo.toEnvironmentConfig();
311-
expect(testLogger.warningText, contains('The key: [DART_DEFINES] already exists, you cannot use environment variables that have been used by the system'));
312-
});
313-
314-
testUsingContext('toEnvironmentConfig repeated variable with DART_DEFINES not set', () async {
315-
// Simulate operation flutterCommand.getBuildInfo with `dart-define-from-file` set dartDefines
316-
const BuildInfo buildInfo = BuildInfo(BuildMode.debug, '',
317-
treeShakeIcons: true,
318-
dartDefines: <String>['DART_DEFINES=Define a variable, but it occupies the variable name of the system'],
319-
trackWidgetCreation: true,
320-
dartDefineConfigJsonMap: <String, Object>{ 'DART_DEFINES' : 'Define a variable, but it occupies the variable name of the system'},
321-
dartObfuscation: true,
322-
);
323-
buildInfo.toEnvironmentConfig();
324-
expect(testLogger.warningText, contains('The key: [DART_DEFINES] already exists, you cannot use environment variables that have been used by the system'));
325-
326-
});
327-
328-
testUsingContext('toGradleConfig repeated variable', () async {
329-
const BuildInfo buildInfo = BuildInfo(BuildMode.debug, '',
330-
treeShakeIcons: true,
331-
trackWidgetCreation: true,
332-
dartDefines: <String>['foo=2', 'bar=2'],
333-
dartDefineConfigJsonMap: <String, Object>{'dart-defines': 'Define a variable, but it occupies the variable name of the system'},
334-
dartObfuscation: true,
335-
);
336-
buildInfo.toGradleConfig();
337-
expect(testLogger.warningText, contains('The key: [dart-defines] already exists, you cannot use gradle variables that have been used by the system'));
338-
});
339-
340-
testUsingContext('toGradleConfig repeated variable with not set', () async {
341-
// Simulate operation flutterCommand.getBuildInfo with `dart-define-from-file` set dartDefines
342-
const BuildInfo buildInfo = BuildInfo(BuildMode.debug, '',
343-
treeShakeIcons: true,
344-
trackWidgetCreation: true,
345-
dartDefines: <String>['dart-defines=Define a variable, but it occupies the variable name of the system'],
346-
dartDefineConfigJsonMap: <String, Object>{'dart-defines': 'Define a variable, but it occupies the variable name of the system'},
347-
dartObfuscation: true,
348-
);
349-
buildInfo.toGradleConfig();
350-
expect(testLogger.warningText, contains('The key: [dart-defines] already exists, you cannot use gradle variables that have been used by the system'));
351-
});
352-
353-
testUsingContext('toGradleConfig with androidProjectArgs override gradle project variant', () async {
354-
const BuildInfo buildInfo = BuildInfo(BuildMode.debug, '',
355-
treeShakeIcons: true,
356-
trackWidgetCreation: true,
357-
androidProjectArgs: <String>['applicationId=com.google'],
358-
dartDefineConfigJsonMap: <String, Object>{'applicationId': 'override applicationId'},
359-
dartObfuscation: true,
360-
);
361-
buildInfo.toGradleConfig();
362-
expect(testLogger.warningText, contains('The key: [applicationId] already exists, you cannot use gradle variables that have been used by the system'));
363-
});
364-
365-
});
366298
}

0 commit comments

Comments
 (0)