Skip to content

Commit d0d9da8

Browse files
[flutter_tools] prevent wildcard assets from causing build invalidation issues (flutter#56472)
1 parent 4fd4a7e commit d0d9da8

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

packages/flutter_tools/lib/src/asset.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,19 @@ class ManifestAssetBundle implements AssetBundle {
272272
final DevFSStringContent licenses = DevFSStringContent(licenseResult.combinedLicenses);
273273
additionalDependencies = licenseResult.dependencies;
274274

275+
if (wildcardDirectories.isNotEmpty) {
276+
// Force the depfile to contain missing files so that Gradle does not skip
277+
// the task. Wildcard directories are not compatible with full incremental
278+
// builds. For more context see https://github.com/flutter/flutter/issues/56466 .
279+
globals.printTrace(
280+
'Manifest contained wildcard assets. Inserting missing file into '
281+
'build graph to force rerun. for more information see #56466.'
282+
);
283+
final int suffix = Object().hashCode;
284+
additionalDependencies.add(
285+
globals.fs.file('DOES_NOT_EXIST_RERUN_FOR_WILDCARD$suffix').absolute);
286+
}
287+
275288
_setIfChanged(_assetManifestJson, assetManifest);
276289
_setIfChanged(kFontManifestJson, fontManifest);
277290
_setIfChanged(_license, licenses);

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

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,83 @@ assets:
224224
ProcessManager: () => FakeProcessManager.any(),
225225
});
226226

227+
testUsingContext('inserts dummy file into additionalDependencies when '
228+
'wildcards are used', () async {
229+
globals.fs.file('.packages').createSync();
230+
globals.fs.file(globals.fs.path.join('assets', 'bar.txt')).createSync(recursive: true);
231+
globals.fs.file('pubspec.yaml')
232+
..createSync()
233+
..writeAsStringSync(r'''
234+
name: example
235+
flutter:
236+
assets:
237+
- assets/
238+
''');
239+
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
240+
241+
expect(await bundle.build(manifestPath: 'pubspec.yaml'), 0);
242+
expect(bundle.additionalDependencies.single.path, contains('DOES_NOT_EXIST_RERUN_FOR_WILDCARD'));
243+
}, overrides: <Type, Generator>{
244+
FileSystem: () => MemoryFileSystem.test(),
245+
ProcessManager: () => FakeProcessManager.any(),
246+
});
247+
248+
testUsingContext('Does not insert dummy file into additionalDependencies '
249+
'when wildcards are not used', () async {
250+
globals.fs.file('.packages').createSync();
251+
globals.fs.file(globals.fs.path.join('assets', 'bar.txt')).createSync(recursive: true);
252+
globals.fs.file('pubspec.yaml')
253+
..createSync()
254+
..writeAsStringSync(r'''
255+
name: example
256+
flutter:
257+
assets:
258+
- assets/bar.txt
259+
''');
260+
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
261+
262+
expect(await bundle.build(manifestPath: 'pubspec.yaml'), 0);
263+
expect(bundle.additionalDependencies, isEmpty);
264+
}, overrides: <Type, Generator>{
265+
FileSystem: () => MemoryFileSystem.test(),
266+
ProcessManager: () => FakeProcessManager.any(),
267+
});
268+
269+
testUsingContext('Does not insert dummy file into additionalDependencies '
270+
'when wildcards are used by dependencies', () async {
271+
globals.fs.file('.packages').writeAsStringSync(r'''
272+
example:lib/
273+
foo:foo/lib/
274+
''');
275+
globals.fs.file(globals.fs.path.join('assets', 'foo', 'bar.txt'))
276+
.createSync(recursive: true);
277+
globals.fs.file('pubspec.yaml')
278+
..createSync()
279+
..writeAsStringSync(r'''
280+
name: example
281+
dependencies:
282+
foo: any
283+
''');
284+
globals.fs.file('foo/pubspec.yaml')
285+
..createSync(recursive: true)
286+
..writeAsStringSync(r'''
287+
name: foo
288+
289+
flutter:
290+
assets:
291+
- bar/
292+
''');
293+
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
294+
globals.fs.file('foo/bar/fizz.txt').createSync(recursive: true);
295+
296+
expect(await bundle.build(manifestPath: 'pubspec.yaml'), 0);
297+
expect(bundle.additionalDependencies, isEmpty);
298+
}, overrides: <Type, Generator>{
299+
FileSystem: () => MemoryFileSystem.test(),
300+
ProcessManager: () => FakeProcessManager.any(),
301+
Platform: () => FakePlatform(operatingSystem: 'linux'),
302+
});
303+
227304
testUsingContext('does not track wildcard directories from dependencies', () async {
228305
globals.fs.file('.packages').writeAsStringSync(r'''
229306
example:lib/

0 commit comments

Comments
 (0)