[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
This commit is contained in:
blendthink 2022-11-12 03:48:01 +09:00 committed by GitHub
parent 338841afd3
commit 229b39eda5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 15 deletions

View File

@ -334,17 +334,15 @@ class BuildInfo {
'-P$projectArg',
];
if (dartDefineConfigJsonMap != null) {
final List<String> items = <String>[];
for (final String gradleConf in result) {
final String key = gradleConf.split('=')[0].substring(2);
if (dartDefineConfigJsonMap!.containsKey(key)) {
final Iterable<String> 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 {
items.add('-P$key=${dartDefineConfigJsonMap?[key]}');
result.add('-P$key=$value');
}
}
result.addAll(items);
});
}
return result;
}

View File

@ -230,6 +230,7 @@ void main() {
treeShakeIcons: true,
trackWidgetCreation: true,
dartDefines: <String>['foo=2', 'bar=2'],
dartDefineConfigJsonMap: <String, Object>{'baz': '2'},
dartObfuscation: true,
splitDebugInfoPath: 'foo/',
extraFrontEndOptions: <String>['--enable-experiment=non-nullable', 'bar'],
@ -252,6 +253,7 @@ void main() {
'-Pcode-size-directory=foo/code-size',
'-Pfoo=bar',
'-Pfizz=bazz',
'-Pbaz=2',
]);
});
@ -317,7 +319,7 @@ void main() {
dartObfuscation: true,
);
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 {
@ -330,7 +332,7 @@ void main() {
dartObfuscation: true,
);
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 {
@ -342,7 +344,7 @@ void main() {
dartObfuscation: true,
);
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'));
});
});