Unverified Commit 6d1966ef authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] make gallery hot reload 5x faster with one neat trick (#56224)

parent c8c55b40
......@@ -74,7 +74,8 @@ class ManifestAssetBundle implements AssetBundle {
final Map<String, DevFSContent> entries = <String, DevFSContent>{};
// If an asset corresponds to a wildcard directory, then it may have been
// updated without changes to the manifest.
// updated without changes to the manifest. These are only tracked for
// the current project.
final Map<Uri, Directory> _wildcardDirectories = <Uri, Directory>{};
final LicenseCollector licenseCollector = LicenseCollector(fileSystem: globals.fs);
......@@ -203,7 +204,8 @@ class ManifestAssetBundle implements AssetBundle {
final Map<_Asset, List<_Asset>> packageAssets = _parseAssets(
packageConfig,
packageFlutterManifest,
wildcardDirectories,
// Do not track wildcard directories for dependencies.
<Uri>[],
packageBasePath,
packageName: package.name,
);
......
......@@ -14,6 +14,7 @@ import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/devfs.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:mockito/mockito.dart';
import 'package:platform/platform.dart';
import '../src/common.dart';
import '../src/context.dart';
......@@ -223,6 +224,48 @@ assets:
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('does not track wildcard directories from dependencies', () async {
globals.fs.file('.packages').writeAsStringSync(r'''
example:lib/
foo:foo/lib/
''');
globals.fs.file(globals.fs.path.join('assets', 'foo', 'bar.txt'))
.createSync(recursive: true);
globals.fs.file('pubspec.yaml')
..createSync()
..writeAsStringSync(r'''
name: example
dependencies:
foo: any
''');
globals.fs.file('foo/pubspec.yaml')
..createSync(recursive: true)
..writeAsStringSync(r'''
name: foo
flutter:
assets:
- bar/
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
globals.fs.file('foo/bar/fizz.txt').createSync(recursive: true);
await bundle.build(manifestPath: 'pubspec.yaml');
expect(bundle.entries, hasLength(4));
expect(bundle.needsBuild(manifestPath: 'pubspec.yaml'), false);
// Does not track dependency's wildcard directories.
globals.fs.file(globals.fs.path.join('assets', 'foo', 'bar.txt'))
.deleteSync();
expect(bundle.needsBuild(manifestPath: 'pubspec.yaml'), false);
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
Platform: () => FakePlatform(operatingSystem: 'linux'),
});
}
class MockDirectory extends Mock implements Directory {}
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