@@ -234,26 +234,79 @@ bool _writeFlutterPluginsList(
234
234
'macos' : swiftPackageManagerEnabledMacos,
235
235
};
236
236
237
- // Only notify if the plugins list has changed. [date_created] will always be different,
238
- // [version] is not relevant for this check.
239
- final String ? oldPluginsFileStringContent = _readFileContent (pluginsFile);
240
- bool pluginsChanged = true ;
241
- if (oldPluginsFileStringContent != null ) {
242
- try {
243
- final Object ? decodedJson = jsonDecode (oldPluginsFileStringContent);
244
- if (decodedJson is Map <String , Object ?>) {
245
- final String jsonOfNewPluginsMap = jsonEncode (pluginsMap);
246
- final String jsonOfOldPluginsMap = jsonEncode (decodedJson[_kFlutterPluginsPluginListKey]);
247
- pluginsChanged = jsonOfNewPluginsMap != jsonOfOldPluginsMap;
248
- }
249
- } on FormatException catch (_) {}
237
+ // Only write the plugins file if its content have changed. This ensures
238
+ // that flutter assemble targets that depend on this file aren't invalidated
239
+ // unnecessarily.
240
+ final (: bool pluginsChanged, : bool contentsChanged) = _detectFlutterPluginsListChanges (
241
+ pluginsFile,
242
+ result,
243
+ );
244
+ if (pluginsChanged || contentsChanged) {
245
+ final String pluginFileContent = json.encode (result);
246
+ pluginsFile.writeAsStringSync (pluginFileContent, flush: true );
250
247
}
251
- final String pluginFileContent = json.encode (result);
252
- pluginsFile.writeAsStringSync (pluginFileContent, flush: true );
253
248
254
249
return pluginsChanged;
255
250
}
256
251
252
+ /// Find what has changed in the .flutter-plugins-dependencies JSON file.
253
+ ///
254
+ /// [pluginsChanged] is [true] if anything changed in the 'plugins' property.
255
+ /// This indicates that platform-specific tooling like 'pod install' should be
256
+ /// re-run.
257
+ ///
258
+ /// [contentsChanged] is [true] if [newJson] has changes that should be saved to
259
+ /// disk.
260
+ ({bool pluginsChanged, bool contentsChanged}) _detectFlutterPluginsListChanges (
261
+ File pluginsFile,
262
+ Map <String , Object > newJson,
263
+ ) {
264
+ final String ? oldPluginsFileStringContent = _readFileContent (pluginsFile);
265
+ if (oldPluginsFileStringContent == null ) {
266
+ return (pluginsChanged: true , contentsChanged: true );
267
+ }
268
+
269
+ try {
270
+ final Object ? oldJson = jsonDecode (oldPluginsFileStringContent);
271
+ if (oldJson is ! Map <String , Object ?>) {
272
+ return (pluginsChanged: true , contentsChanged: true );
273
+ }
274
+
275
+ // Check if plugins changed.
276
+ final String jsonOfNewPluginsMap = jsonEncode (newJson[_kFlutterPluginsPluginListKey]);
277
+ final String jsonOfOldPluginsMap = jsonEncode (oldJson[_kFlutterPluginsPluginListKey]);
278
+ if (jsonOfNewPluginsMap != jsonOfOldPluginsMap) {
279
+ return (pluginsChanged: true , contentsChanged: true );
280
+ }
281
+
282
+ // Create a copy of the new JSON so that the input isn't mutated when we
283
+ // drop properties that should be ignored.
284
+ final Map <String , Object ?> newJsonCopy = < String , Object ? > {...newJson};
285
+
286
+ // The 'info' property is a comment that doesn't affect functionality.
287
+ // The 'dependencyGraph' property is deprecated and shouldn't be used.
288
+ // The 'date_created' property is always updated.
289
+ // The 'plugins' property has already been checked by the logic above.
290
+ const List <String > ignoredKeys = < String > [
291
+ 'info' ,
292
+ 'dependencyGraph' ,
293
+ 'date_created' ,
294
+ _kFlutterPluginsPluginListKey,
295
+ ];
296
+ for (final String key in ignoredKeys) {
297
+ oldJson.remove (key);
298
+ newJsonCopy.remove (key);
299
+ }
300
+
301
+ final String old = jsonEncode (oldJson);
302
+ final String updated = jsonEncode (newJsonCopy);
303
+
304
+ return (pluginsChanged: false , contentsChanged: old != updated);
305
+ } on FormatException catch (_) {
306
+ return (pluginsChanged: true , contentsChanged: true );
307
+ }
308
+ }
309
+
257
310
/// Creates a map representation of the [plugins] for those supported by [platformKey] .
258
311
/// All given [plugins] must provide an implementation for the [platformKey] .
259
312
List <Map <String , Object >> _createPluginMapOfPlatform (List <Plugin > plugins, String platformKey) {
0 commit comments