From cfe4fedca26d894f1db7d7b2d089618356efcc26 Mon Sep 17 00:00:00 2001 From: Andrew Kolos Date: Fri, 9 Jun 2023 21:20:50 +0000 Subject: [PATCH] rename generated asset manifest file back to `AssetManifest.bin` (from `AssetManifest.smcbin`) (#128529) Closes https://github.com/flutter/flutter/issues/128456, which is now linked to in a code comment in this change. Reopens https://github.com/flutter/flutter/issues/124883. This effectively reverts https://github.com/flutter/flutter/pull/126077 and is intended to be cherry-picked into stable. --- .../lib/src/services/asset_manifest.dart | 7 ++++- .../test/painting/image_resolution_test.dart | 2 +- .../test/services/asset_bundle_test.dart | 18 ++++++------ .../test/services/asset_manifest_test.dart | 2 +- .../test/widgets/image_resolution_test.dart | 2 +- packages/flutter_tools/lib/src/asset.dart | 2 +- .../flutter_tools/lib/src/commands/test.dart | 6 +++- .../commands.shard/hermetic/test_test.dart | 4 +-- .../asset_bundle_package_fonts_test.dart | 2 +- .../asset_bundle_package_test.dart | 6 ++-- .../test/general.shard/asset_bundle_test.dart | 28 +++++++++---------- .../asset_bundle_variant_test.dart | 2 +- 12 files changed, 45 insertions(+), 36 deletions(-) diff --git a/packages/flutter/lib/src/services/asset_manifest.dart b/packages/flutter/lib/src/services/asset_manifest.dart index 1fb06dba8a..d487e10984 100644 --- a/packages/flutter/lib/src/services/asset_manifest.dart +++ b/packages/flutter/lib/src/services/asset_manifest.dart @@ -7,7 +7,12 @@ import 'package:flutter/foundation.dart'; import 'asset_bundle.dart'; import 'message_codecs.dart'; -const String _kAssetManifestFilename = 'AssetManifest.smcbin'; +// We use .bin as the extension since it is well-known to represent +// data in some arbitrary binary format. Using a well-known extension here +// is important for web, because some web servers will not serve files with +// unrecognized file extensions by default. +// See https://github.com/flutter/flutter/issues/128456. +const String _kAssetManifestFilename = 'AssetManifest.bin'; /// Contains details about available assets and their variants. /// See [Asset variants](https://docs.flutter.dev/development/ui/assets-and-images#asset-variants) diff --git a/packages/flutter/test/painting/image_resolution_test.dart b/packages/flutter/test/painting/image_resolution_test.dart index bfc9c6ede1..2a784de9e0 100644 --- a/packages/flutter/test/painting/image_resolution_test.dart +++ b/packages/flutter/test/painting/image_resolution_test.dart @@ -18,7 +18,7 @@ class TestAssetBundle extends CachingAssetBundle { @override Future load(String key) async { - if (key == 'AssetManifest.smcbin') { + if (key == 'AssetManifest.bin') { return const StandardMessageCodec().encodeMessage(_assetBundleMap)!; } diff --git a/packages/flutter/test/services/asset_bundle_test.dart b/packages/flutter/test/services/asset_bundle_test.dart index 961482d0cb..efa2f7d7cc 100644 --- a/packages/flutter/test/services/asset_bundle_test.dart +++ b/packages/flutter/test/services/asset_bundle_test.dart @@ -19,7 +19,7 @@ class TestAssetBundle extends CachingAssetBundle { return ByteData.view(Uint8List.fromList(const Utf8Encoder().convert('{"one": ["one"]}')).buffer); } - if (key == 'AssetManifest.smcbin') { + if (key == 'AssetManifest.bin') { return const StandardMessageCodec().encodeMessage({ 'one': [] })!; @@ -76,8 +76,8 @@ void main() { expect(firstLoadStructuredDataResult, 'one'); expect(secondLoadStructuredDataResult, 'one'); - final String firstLoadStructuredBinaryDataResult = await bundle.loadStructuredBinaryData('AssetManifest.smcbin', (ByteData value) => Future.value('one')); - final String secondLoadStructuredBinaryDataResult = await bundle.loadStructuredBinaryData('AssetManifest.smcbin', (ByteData value) => Future.value('two')); + final String firstLoadStructuredBinaryDataResult = await bundle.loadStructuredBinaryData('AssetManifest.bin', (ByteData value) => Future.value('one')); + final String secondLoadStructuredBinaryDataResult = await bundle.loadStructuredBinaryData('AssetManifest.bin', (ByteData value) => Future.value('two')); expect(firstLoadStructuredBinaryDataResult, 'one'); expect(secondLoadStructuredBinaryDataResult, 'one'); }); @@ -95,9 +95,9 @@ void main() { final String secondLoadStructuredDataResult = await bundle.loadStructuredData('AssetManifest.json', (String value) => Future.value('two')); expect(secondLoadStructuredDataResult, 'two'); - await bundle.loadStructuredBinaryData('AssetManifest.smcbin', (ByteData value) => Future.value('one')); + await bundle.loadStructuredBinaryData('AssetManifest.bin', (ByteData value) => Future.value('one')); bundle.clear(); - final String secondLoadStructuredBinaryDataResult = await bundle.loadStructuredBinaryData('AssetManifest.smcbin', (ByteData value) => Future.value('two')); + final String secondLoadStructuredBinaryDataResult = await bundle.loadStructuredBinaryData('AssetManifest.bin', (ByteData value) => Future.value('two')); expect(secondLoadStructuredBinaryDataResult, 'two'); }); @@ -114,9 +114,9 @@ void main() { final String secondLoadStructuredDataResult = await bundle.loadStructuredData('AssetManifest.json', (String value) => Future.value('two')); expect(secondLoadStructuredDataResult, 'two'); - await bundle.loadStructuredBinaryData('AssetManifest.smcbin', (ByteData value) => Future.value('one')); - bundle.evict('AssetManifest.smcbin'); - final String secondLoadStructuredBinaryDataResult = await bundle.loadStructuredBinaryData('AssetManifest.smcbin', (ByteData value) => Future.value('two')); + await bundle.loadStructuredBinaryData('AssetManifest.bin', (ByteData value) => Future.value('one')); + bundle.evict('AssetManifest.bin'); + final String secondLoadStructuredBinaryDataResult = await bundle.loadStructuredBinaryData('AssetManifest.bin', (ByteData value) => Future.value('two')); expect(secondLoadStructuredBinaryDataResult, 'two'); }); @@ -191,7 +191,7 @@ void main() { test('loadStructuredBinaryData correctly loads ByteData', () async { final TestAssetBundle bundle = TestAssetBundle(); final Map assetManifest = - await bundle.loadStructuredBinaryData('AssetManifest.smcbin', (ByteData data) => const StandardMessageCodec().decodeMessage(data) as Map); + await bundle.loadStructuredBinaryData('AssetManifest.bin', (ByteData data) => const StandardMessageCodec().decodeMessage(data) as Map); expect(assetManifest.keys.toList(), equals(['one'])); expect(assetManifest['one'], []); }); diff --git a/packages/flutter/test/services/asset_manifest_test.dart b/packages/flutter/test/services/asset_manifest_test.dart index 11342333ac..c0edd9136e 100644 --- a/packages/flutter/test/services/asset_manifest_test.dart +++ b/packages/flutter/test/services/asset_manifest_test.dart @@ -10,7 +10,7 @@ import 'package:flutter_test/flutter_test.dart'; class TestAssetBundle extends AssetBundle { @override Future load(String key) async { - if (key == 'AssetManifest.smcbin') { + if (key == 'AssetManifest.bin') { final Map> binManifestData = >{ 'assets/foo.png': [ { diff --git a/packages/flutter/test/widgets/image_resolution_test.dart b/packages/flutter/test/widgets/image_resolution_test.dart index 620cbdff8f..46f0478058 100644 --- a/packages/flutter/test/widgets/image_resolution_test.dart +++ b/packages/flutter/test/widgets/image_resolution_test.dart @@ -40,7 +40,7 @@ class TestAssetBundle extends CachingAssetBundle { Future load(String key) { late ByteData data; switch (key) { - case 'AssetManifest.smcbin': + case 'AssetManifest.bin': data = manifest; case 'assets/image.png': data = testByteData(1.0); diff --git a/packages/flutter_tools/lib/src/asset.dart b/packages/flutter_tools/lib/src/asset.dart index 4eb71f8b89..7c8f054517 100644 --- a/packages/flutter_tools/lib/src/asset.dart +++ b/packages/flutter_tools/lib/src/asset.dart @@ -167,7 +167,7 @@ class ManifestAssetBundle implements AssetBundle { // We assume the main asset is designed for a device pixel ratio of 1.0. static const String _kAssetManifestJsonFilename = 'AssetManifest.json'; - static const String _kAssetManifestBinFilename = 'AssetManifest.smcbin'; + static const String _kAssetManifestBinFilename = 'AssetManifest.bin'; static const String _kNoticeFile = 'NOTICES'; // Comically, this can't be name with the more common .gz file extension diff --git a/packages/flutter_tools/lib/src/commands/test.dart b/packages/flutter_tools/lib/src/commands/test.dart index 091ea5a9f6..8bd076edcd 100644 --- a/packages/flutter_tools/lib/src/commands/test.dart +++ b/packages/flutter_tools/lib/src/commands/test.dart @@ -541,7 +541,11 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { } bool _needRebuild(Map entries) { - final File manifest = globals.fs.file(globals.fs.path.join('build', 'unit_test_assets', 'AssetManifest.json')); + // TODO(andrewkolos): This logic might fail in the future if we change the + // schema of the contents of the asset manifest file and the user does not + // perform a `flutter clean` after upgrading. + // See https://github.com/flutter/flutter/issues/128563. + final File manifest = globals.fs.file(globals.fs.path.join('build', 'unit_test_assets', 'AssetManifest.bin')); if (!manifest.existsSync()) { return true; } diff --git a/packages/flutter_tools/test/commands.shard/hermetic/test_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/test_test.dart index 764695d17e..2c8d81e6e4 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/test_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/test_test.dart @@ -743,7 +743,7 @@ dev_dependencies: '--no-pub', ]); - final bool fileExists = await fs.isFile(globals.fs.path.join('build', 'unit_test_assets', 'AssetManifest.json')); + final bool fileExists = await fs.isFile(globals.fs.path.join('build', 'unit_test_assets', 'AssetManifest.bin')); expect(fileExists, true); }, overrides: { @@ -764,7 +764,7 @@ dev_dependencies: '--no-test-assets', ]); - final bool fileExists = await fs.isFile(globals.fs.path.join('build', 'unit_test_assets', 'AssetManifest.json')); + final bool fileExists = await fs.isFile(globals.fs.path.join('build', 'unit_test_assets', 'AssetManifest.bin')); expect(fileExists, false); }, overrides: { diff --git a/packages/flutter_tools/test/general.shard/asset_bundle_package_fonts_test.dart b/packages/flutter_tools/test/general.shard/asset_bundle_package_fonts_test.dart index de7afe549e..febaa31742 100644 --- a/packages/flutter_tools/test/general.shard/asset_bundle_package_fonts_test.dart +++ b/packages/flutter_tools/test/general.shard/asset_bundle_package_fonts_test.dart @@ -111,7 +111,7 @@ $fontsSection final AssetBundle bundle = AssetBundleFactory.instance.createBundle(); await bundle.build(packagesPath: '.packages'); - expect(bundle.entries.keys, unorderedEquals(['AssetManifest.smcbin', + expect(bundle.entries.keys, unorderedEquals(['AssetManifest.bin', 'AssetManifest.json', 'FontManifest.json', 'NOTICES.Z'])); }, overrides: { FileSystem: () => testFileSystem, diff --git a/packages/flutter_tools/test/general.shard/asset_bundle_package_test.dart b/packages/flutter_tools/test/general.shard/asset_bundle_package_test.dart index c45d4e0647..cc7f68a0a0 100644 --- a/packages/flutter_tools/test/general.shard/asset_bundle_package_test.dart +++ b/packages/flutter_tools/test/general.shard/asset_bundle_package_test.dart @@ -95,7 +95,7 @@ $assetsSection final Map assetManifest = const StandardMessageCodec().decodeMessage( ByteData.sublistView( Uint8List.fromList( - await bundle.entries['AssetManifest.smcbin']!.contentsAsBytes() + await bundle.entries['AssetManifest.bin']!.contentsAsBytes() ) ) ) as Map; @@ -140,7 +140,7 @@ $assetsSection final AssetBundle bundle = AssetBundleFactory.instance.createBundle(); await bundle.build(packagesPath: '.packages'); expect(bundle.entries.keys, unorderedEquals( - ['NOTICES.Z', 'AssetManifest.json', 'AssetManifest.smcbin', 'FontManifest.json'])); + ['NOTICES.Z', 'AssetManifest.json', 'AssetManifest.bin', 'FontManifest.json'])); const String expectedAssetManifest = '{}'; expect( utf8.decode(await bundle.entries['AssetManifest.json']!.contentsAsBytes()), @@ -166,7 +166,7 @@ $assetsSection final AssetBundle bundle = AssetBundleFactory.instance.createBundle(); await bundle.build(packagesPath: '.packages'); expect(bundle.entries.keys, unorderedEquals( - ['NOTICES.Z', 'AssetManifest.json', 'AssetManifest.smcbin', 'FontManifest.json'])); + ['NOTICES.Z', 'AssetManifest.json', 'AssetManifest.bin', 'FontManifest.json'])); const String expectedAssetManifest = '{}'; expect( utf8.decode(await bundle.entries['AssetManifest.json']!.contentsAsBytes()), diff --git a/packages/flutter_tools/test/general.shard/asset_bundle_test.dart b/packages/flutter_tools/test/general.shard/asset_bundle_test.dart index 77b4129749..11837c7fb2 100644 --- a/packages/flutter_tools/test/general.shard/asset_bundle_test.dart +++ b/packages/flutter_tools/test/general.shard/asset_bundle_test.dart @@ -51,7 +51,7 @@ void main() { final AssetBundle bundle = AssetBundleFactory.instance.createBundle(); await bundle.build(packagesPath: '.packages'); expect(bundle.entries.keys, - unorderedEquals(['AssetManifest.json', 'AssetManifest.smcbin']) + unorderedEquals(['AssetManifest.json', 'AssetManifest.bin']) ); const String expectedJsonAssetManifest = '{}'; const Map expectedBinAssetManifest = {}; @@ -60,7 +60,7 @@ void main() { expectedJsonAssetManifest, ); expect( - const StandardMessageCodec().decodeMessage(ByteData.sublistView(Uint8List.fromList(await bundle.entries['AssetManifest.smcbin']!.contentsAsBytes()))), + const StandardMessageCodec().decodeMessage(ByteData.sublistView(Uint8List.fromList(await bundle.entries['AssetManifest.bin']!.contentsAsBytes()))), expectedBinAssetManifest ); @@ -103,7 +103,7 @@ flutter: expect(bundle.entries.keys, unorderedEquals([ 'AssetManifest.json', - 'AssetManifest.smcbin', + 'AssetManifest.bin', 'FontManifest.json', 'NOTICES.Z', 'assets/foo/dog.png', @@ -128,7 +128,7 @@ flutter: final AssetBundle bundle = AssetBundleFactory.instance.createBundle(); await bundle.build(packagesPath: '.packages'); expect(bundle.entries.keys, unorderedEquals(['AssetManifest.json', - 'AssetManifest.smcbin', 'FontManifest.json', 'NOTICES.Z', 'assets/foo/bar.txt'])); + 'AssetManifest.bin', 'FontManifest.json', 'NOTICES.Z', 'assets/foo/bar.txt'])); // Simulate modifying the files by updating the filestat time manually. globals.fs.file(globals.fs.path.join('assets', 'foo', 'fizz.txt')) ..createSync(recursive: true) @@ -137,7 +137,7 @@ flutter: expect(bundle.needsBuild(), true); await bundle.build(packagesPath: '.packages'); expect(bundle.entries.keys, unorderedEquals(['AssetManifest.json', - 'AssetManifest.smcbin', 'FontManifest.json', 'NOTICES.Z', 'assets/foo/bar.txt', + 'AssetManifest.bin', 'FontManifest.json', 'NOTICES.Z', 'assets/foo/bar.txt', 'assets/foo/fizz.txt'])); }, overrides: { FileSystem: () => testFileSystem, @@ -158,7 +158,7 @@ flutter: final AssetBundle bundle = AssetBundleFactory.instance.createBundle(); await bundle.build(packagesPath: '.packages'); expect(bundle.entries.keys, unorderedEquals(['AssetManifest.json', - 'AssetManifest.smcbin', 'FontManifest.json', 'NOTICES.Z', 'assets/foo/bar.txt'])); + 'AssetManifest.bin', 'FontManifest.json', 'NOTICES.Z', 'assets/foo/bar.txt'])); expect(bundle.needsBuild(), false); // Delete the wildcard directory and update pubspec file. @@ -180,7 +180,7 @@ name: example''') expect(bundle.needsBuild(), true); await bundle.build(packagesPath: '.packages'); expect(bundle.entries.keys, unorderedEquals(['AssetManifest.json', - 'AssetManifest.smcbin', 'FontManifest.json', 'NOTICES.Z', 'assets/foo/bar.txt'])); + 'AssetManifest.bin', 'FontManifest.json', 'NOTICES.Z', 'assets/foo/bar.txt'])); }, overrides: { FileSystem: () => testFileSystem, ProcessManager: () => FakeProcessManager.any(), @@ -204,7 +204,7 @@ flutter: final AssetBundle bundle = AssetBundleFactory.instance.createBundle(); await bundle.build(packagesPath: '.packages'); expect(bundle.entries.keys, unorderedEquals(['AssetManifest.json', - 'AssetManifest.smcbin', 'FontManifest.json', 'NOTICES.Z', 'assets/foo/bar.txt'])); + 'AssetManifest.bin', 'FontManifest.json', 'NOTICES.Z', 'assets/foo/bar.txt'])); expect(bundle.needsBuild(), false); }, overrides: { FileSystem: () => testFileSystem, @@ -237,7 +237,7 @@ flutter: ).createBundle(); await bundle.build(packagesPath: '.packages', deferredComponentsEnabled: true); expect(bundle.entries.keys, unorderedEquals(['AssetManifest.json', - 'AssetManifest.smcbin', 'FontManifest.json', 'NOTICES.Z', 'assets/foo/bar.txt'])); + 'AssetManifest.bin', 'FontManifest.json', 'NOTICES.Z', 'assets/foo/bar.txt'])); expect(bundle.deferredComponentsEntries.length, 1); expect(bundle.deferredComponentsEntries['component1']!.length, 2); expect(bundle.needsBuild(), false); @@ -268,7 +268,7 @@ flutter: await bundle.build(packagesPath: '.packages'); expect(bundle.entries.keys, unorderedEquals(['assets/foo/bar.txt', 'assets/bar/barbie.txt', 'assets/wild/dash.txt', 'AssetManifest.json', - 'AssetManifest.smcbin', 'FontManifest.json', 'NOTICES.Z'])); + 'AssetManifest.bin', 'FontManifest.json', 'NOTICES.Z'])); expect(bundle.deferredComponentsEntries.isEmpty, true); expect(bundle.needsBuild(), false); }, overrides: { @@ -302,7 +302,7 @@ flutter: ).createBundle(); await bundle.build(packagesPath: '.packages', deferredComponentsEnabled: true); expect(bundle.entries.keys, unorderedEquals(['assets/foo/bar.txt', - 'AssetManifest.json', 'AssetManifest.smcbin', 'FontManifest.json', 'NOTICES.Z'])); + 'AssetManifest.json', 'AssetManifest.bin', 'FontManifest.json', 'NOTICES.Z'])); expect(bundle.deferredComponentsEntries.length, 1); expect(bundle.deferredComponentsEntries['component1']!.length, 2); expect(bundle.needsBuild(), false); @@ -316,7 +316,7 @@ flutter: await bundle.build(packagesPath: '.packages', deferredComponentsEnabled: true); expect(bundle.entries.keys, unorderedEquals(['assets/foo/bar.txt', - 'AssetManifest.json', 'AssetManifest.smcbin', 'FontManifest.json', 'NOTICES.Z'])); + 'AssetManifest.json', 'AssetManifest.bin', 'FontManifest.json', 'NOTICES.Z'])); expect(bundle.deferredComponentsEntries.length, 1); expect(bundle.deferredComponentsEntries['component1']!.length, 3); }, overrides: { @@ -663,7 +663,7 @@ flutter: await bundle.build(packagesPath: '.packages'); expect(bundle.entries.keys, unorderedEquals(['packages/foo/bar/fizz.txt', - 'AssetManifest.json', 'AssetManifest.smcbin', 'FontManifest.json', 'NOTICES.Z'])); + 'AssetManifest.json', 'AssetManifest.bin', 'FontManifest.json', 'NOTICES.Z'])); expect(bundle.needsBuild(), false); // Does not track dependency's wildcard directories. @@ -799,7 +799,7 @@ flutter: expect(await bundle.build(packagesPath: '.packages'), 0); expect(bundle.entries.keys, unorderedEquals(['assets/foo.txt', - 'AssetManifest.json', 'AssetManifest.smcbin', 'FontManifest.json', 'NOTICES.Z'])); + 'AssetManifest.json', 'AssetManifest.bin', 'FontManifest.json', 'NOTICES.Z'])); }, overrides: { FileSystem: () => MemoryFileSystem.test(), ProcessManager: () => FakeProcessManager.any(), diff --git a/packages/flutter_tools/test/general.shard/asset_bundle_variant_test.dart b/packages/flutter_tools/test/general.shard/asset_bundle_variant_test.dart index 93c1e5c21c..8136ea1b31 100644 --- a/packages/flutter_tools/test/general.shard/asset_bundle_variant_test.dart +++ b/packages/flutter_tools/test/general.shard/asset_bundle_variant_test.dart @@ -33,7 +33,7 @@ void main() { } Future> extractAssetManifestSmcBinFromBundle(ManifestAssetBundle bundle) async { - final List manifest = await bundle.entries['AssetManifest.smcbin']!.contentsAsBytes(); + final List manifest = await bundle.entries['AssetManifest.bin']!.contentsAsBytes(); final ByteData asByteData = ByteData.view(Uint8List.fromList(manifest).buffer); final Map decoded = const StandardMessageCodec().decodeMessage(asByteData)! as Map; return decoded;