Unverified Commit 229b39ed authored by blendthink's avatar blendthink Committed by GitHub

[flutter_tools] Fix so that the value set by `--dart-define-from-file` can be...

[flutter_tools] Fix so that the value set by `--dart-define-from-file` can be passed to Gradle (#114297)

* Add dartDefineConfigJsonMap to the checklist

* Fix typo

* Align formatting with other code

* Fix toGradleConfig method
parent 338841af
...@@ -333,18 +333,16 @@ class BuildInfo { ...@@ -333,18 +333,16 @@ class BuildInfo {
for (String projectArg in androidProjectArgs) for (String projectArg in androidProjectArgs)
'-P$projectArg', '-P$projectArg',
]; ];
if(dartDefineConfigJsonMap != null) { if (dartDefineConfigJsonMap != null) {
final List<String> items = <String>[]; final Iterable<String> gradleConfKeys = result.map((final String gradleConf) => gradleConf.split('=')[0].substring(2));
for (final String gradleConf in result) { dartDefineConfigJsonMap!.forEach((String key, Object value) {
final String key = gradleConf.split('=')[0].substring(2); if (gradleConfKeys.contains(key)) {
if (dartDefineConfigJsonMap!.containsKey(key)) {
globals.printWarning( globals.printWarning(
'The key: [$key] already exists, you cannot use gradle variables that have been used by the system!'); 'The key: [$key] already exists, you cannot use gradle variables that have been used by the system!');
} else { } else {
items.add('-P$key=${dartDefineConfigJsonMap?[key]}'); result.add('-P$key=$value');
} }
} });
result.addAll(items);
} }
return result; return result;
} }
......
...@@ -230,6 +230,7 @@ void main() { ...@@ -230,6 +230,7 @@ void main() {
treeShakeIcons: true, treeShakeIcons: true,
trackWidgetCreation: true, trackWidgetCreation: true,
dartDefines: <String>['foo=2', 'bar=2'], dartDefines: <String>['foo=2', 'bar=2'],
dartDefineConfigJsonMap: <String, Object>{'baz': '2'},
dartObfuscation: true, dartObfuscation: true,
splitDebugInfoPath: 'foo/', splitDebugInfoPath: 'foo/',
extraFrontEndOptions: <String>['--enable-experiment=non-nullable', 'bar'], extraFrontEndOptions: <String>['--enable-experiment=non-nullable', 'bar'],
...@@ -252,6 +253,7 @@ void main() { ...@@ -252,6 +253,7 @@ void main() {
'-Pcode-size-directory=foo/code-size', '-Pcode-size-directory=foo/code-size',
'-Pfoo=bar', '-Pfoo=bar',
'-Pfizz=bazz', '-Pfizz=bazz',
'-Pbaz=2',
]); ]);
}); });
...@@ -287,7 +289,7 @@ void main() { ...@@ -287,7 +289,7 @@ void main() {
treeShakeIcons: true, treeShakeIcons: true,
trackWidgetCreation: true, trackWidgetCreation: true,
dartDefines: <String>['foo=2', 'bar=2'], dartDefines: <String>['foo=2', 'bar=2'],
dartDefineConfigJsonMap: <String,Object>{ 'DART_DEFINES' : 'Define a variable, but it occupies the variable name of the system'}, dartDefineConfigJsonMap: <String, Object>{'DART_DEFINES': 'Define a variable, but it occupies the variable name of the system'},
dartObfuscation: true, dartObfuscation: true,
); );
buildInfo.toEnvironmentConfig(); buildInfo.toEnvironmentConfig();
...@@ -313,11 +315,11 @@ void main() { ...@@ -313,11 +315,11 @@ void main() {
treeShakeIcons: true, treeShakeIcons: true,
trackWidgetCreation: true, trackWidgetCreation: true,
dartDefines: <String>['foo=2', 'bar=2'], dartDefines: <String>['foo=2', 'bar=2'],
dartDefineConfigJsonMap: <String,Object>{ 'dart-defines' : 'Define a variable, but it occupies the variable name of the system'}, dartDefineConfigJsonMap: <String, Object>{'dart-defines': 'Define a variable, but it occupies the variable name of the system'},
dartObfuscation: true, dartObfuscation: true,
); );
buildInfo.toGradleConfig(); buildInfo.toGradleConfig();
expect(testLogger.warningText, contains('he key: [dart-defines] already exists, you cannot use gradle variables that have been used by the system')); 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 { testUsingContext('toGradleConfig repeated variable with not set', () async {
...@@ -326,11 +328,11 @@ void main() { ...@@ -326,11 +328,11 @@ void main() {
treeShakeIcons: true, treeShakeIcons: true,
trackWidgetCreation: true, trackWidgetCreation: true,
dartDefines: <String>['dart-defines=Define a variable, but it occupies the variable name of the system'], dartDefines: <String>['dart-defines=Define a variable, but it occupies the variable name of the system'],
dartDefineConfigJsonMap: <String,Object>{ 'dart-defines' : 'Define a variable, but it occupies the variable name of the system'}, dartDefineConfigJsonMap: <String, Object>{'dart-defines': 'Define a variable, but it occupies the variable name of the system'},
dartObfuscation: true, dartObfuscation: true,
); );
buildInfo.toGradleConfig(); buildInfo.toGradleConfig();
expect(testLogger.warningText, contains('he key: [dart-defines] already exists, you cannot use gradle variables that have been used by the system')); 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 { testUsingContext('toGradleConfig with androidProjectArgs override gradle project variant', () async {
...@@ -338,11 +340,11 @@ void main() { ...@@ -338,11 +340,11 @@ void main() {
treeShakeIcons: true, treeShakeIcons: true,
trackWidgetCreation: true, trackWidgetCreation: true,
androidProjectArgs: <String>['applicationId=com.google'], androidProjectArgs: <String>['applicationId=com.google'],
dartDefineConfigJsonMap: <String,Object>{ 'applicationId' : 'override applicationId'}, dartDefineConfigJsonMap: <String, Object>{'applicationId': 'override applicationId'},
dartObfuscation: true, dartObfuscation: true,
); );
buildInfo.toGradleConfig(); buildInfo.toGradleConfig();
expect(testLogger.warningText, contains('The key: [applicationId] already exists, you cannot use gradle variables that have been used')); expect(testLogger.warningText, contains('The key: [applicationId] already exists, you cannot use gradle variables that have been used by the system'));
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment