consolidate AssetBundle::entries and AssetBundle::entryKinds into a new type, AssetBundleEntry (#142029)

Part of work on https://github.com/flutter/flutter/pull/141194

The [`AssetBundle`](0833929c99/packages/flutter_tools/lib/src/asset.dart (L80)) class contains two members, `entries` and `entryKinds`. `entries` contains asset data indexed by asset key. `entryKinds` contains the "kinds" of these assets, again indexed by asset key.

**Change.** Rather than have two separate maps, this PR proposes combining these maps into one by wrapping the asset data and kind into a single data type `AssetBundleEntry`.

**Purpose.** In https://github.com/flutter/flutter/pull/141194, I am considering associating more information with an asset. In particular, what transformers are meant to be applied to it when copying it to the build output. Rather than adding another map member onto `AssetBundle` (e.g. `entryTransformers`), I decided to make things neater by introducing the `AssetBundleEntry` type.
This commit is contained in:
Andrew Kolos
2024-01-23 14:00:46 -08:00
committed by GitHub
parent 2bd5abf829
commit cbe0ceafe2
9 changed files with 127 additions and 104 deletions

View File

@@ -648,8 +648,7 @@ flutter:
await writeBundle(
directory,
<String, DevFSContent>{},
<String, AssetKind>{},
const <String, AssetBundleEntry>{},
loggerOverride: testLogger,
targetPlatform: TargetPlatform.android,
impellerStatus: ImpellerStatus.disabled,
@@ -672,12 +671,9 @@ assets:
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(packagesPath: '.packages');
final DevFSStringContent? assetManifest = bundle.entries['AssetManifest.json']
as DevFSStringContent?;
final DevFSStringContent? fontManifest = bundle.entries['FontManifest.json']
as DevFSStringContent?;
final DevFSStringContent? license = bundle.entries['NOTICES']
as DevFSStringContent?;
final AssetBundleEntry? assetManifest = bundle.entries['AssetManifest.json'];
final AssetBundleEntry? fontManifest = bundle.entries['FontManifest.json'];
final AssetBundleEntry? license = bundle.entries['NOTICES'];
await bundle.build(packagesPath: '.packages');
@@ -775,7 +771,6 @@ flutter:
await writeBundle(
output,
bundle.entries,
bundle.entryKinds,
loggerOverride: testLogger,
targetPlatform: TargetPlatform.android,
impellerStatus: ImpellerStatus.disabled,
@@ -822,7 +817,6 @@ flutter:
await writeBundle(
output,
bundle.entries,
bundle.entryKinds,
loggerOverride: testLogger,
targetPlatform: TargetPlatform.web_javascript,
impellerStatus: ImpellerStatus.disabled,
@@ -906,7 +900,6 @@ flutter:
await writeBundle(
output,
bundle.entries,
bundle.entryKinds,
loggerOverride: testLogger,
targetPlatform: TargetPlatform.web_javascript,
impellerStatus: ImpellerStatus.disabled,
@@ -1081,8 +1074,8 @@ flutter:
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
expect(await bundle.build(packagesPath: '.packages'), 0);
expect((bundle.entries['FontManifest.json']! as DevFSStringContent).string, '[]');
expect((bundle.entries['AssetManifest.json']! as DevFSStringContent).string, '{}');
expect((bundle.entries['FontManifest.json']!.content as DevFSStringContent).string, '[]');
expect((bundle.entries['AssetManifest.json']!.content as DevFSStringContent).string, '{}');
expect(testLogger.errorText, contains(
'package:foo has `uses-material-design: true` set'
));
@@ -1153,10 +1146,10 @@ flutter:
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
expect(await bundle.build(packagesPath: '.packages'), 0);
expect((bundle.entries['FontManifest.json']! as DevFSStringContent).string, '[]');
expect((bundle.entries['FontManifest.json']!.content as DevFSStringContent).string, '[]');
// The assets from deferred components and regular assets
// are both included in alphabetical order
expect((bundle.entries['AssetManifest.json']! as DevFSStringContent).string, '{"assets/apple.jpg":["assets/apple.jpg"],"assets/bar.jpg":["assets/bar.jpg"],"assets/foo.jpg":["assets/foo.jpg"],"assets/zebra.jpg":["assets/zebra.jpg"]}');
expect((bundle.entries['AssetManifest.json']!.content as DevFSStringContent).string, '{"assets/apple.jpg":["assets/apple.jpg"],"assets/bar.jpg":["assets/bar.jpg"],"assets/foo.jpg":["assets/foo.jpg"],"assets/zebra.jpg":["assets/zebra.jpg"]}');
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),

View File

@@ -621,9 +621,14 @@ void main() {
return const CompilerOutput('lib/foo.dill', 0, <Uri>[]);
};
final FakeBundle bundle = FakeBundle()
..entries['foo.frag'] = DevFSByteContent(<int>[1, 2, 3, 4])
..entries['not.frag'] = DevFSByteContent(<int>[1, 2, 3, 4])
..entryKinds['foo.frag'] = AssetKind.shader;
..entries['foo.frag'] = AssetBundleEntry(
DevFSByteContent(<int>[1, 2, 3, 4]),
kind: AssetKind.shader,
)
..entries['not.frag'] = AssetBundleEntry(
DevFSByteContent(<int>[1, 2, 3, 4]),
kind: AssetKind.regular,
);
final UpdateFSReport report = await devFS.update(
mainUri: Uri.parse('lib/main.dart'),
@@ -673,7 +678,10 @@ void main() {
return const CompilerOutput('lib/foo.dill', 0, <Uri>[]);
};
final FakeBundle bundle = FakeBundle()
..entries['FontManifest.json'] = DevFSByteContent(<int>[1, 2, 3, 4]);
..entries['FontManifest.json'] = AssetBundleEntry(
DevFSByteContent(<int>[1, 2, 3, 4]),
kind: AssetKind.regular,
);
final UpdateFSReport report = await devFS.update(
mainUri: Uri.parse('lib/main.dart'),
@@ -745,13 +753,10 @@ class FakeBundle extends AssetBundle {
}
@override
Map<String, Map<String, DevFSContent>> get deferredComponentsEntries => <String, Map<String, DevFSContent>>{};
Map<String, Map<String, AssetBundleEntry>> get deferredComponentsEntries => <String, Map<String, AssetBundleEntry>>{};
@override
final Map<String, DevFSContent> entries = <String, DevFSContent>{};
@override
final Map<String, AssetKind> entryKinds = <String, AssetKind>{};
final Map<String, AssetBundleEntry> entries = <String, AssetBundleEntry>{};
@override
List<File> get inputFiles => <File>[];