Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
[flutter_tools] dont include material shaders in web builds (#116538)
Browse files Browse the repository at this point in the history
* [flutter_tools] dont include material shaders in web builds

* add test
  • Loading branch information
jonahwilliams committed Dec 5, 2022
1 parent 06e7c7a commit 27281da
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/flutter_tools/lib/src/asset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ class ManifestAssetBundle implements AssetBundle {
// For all platforms, include the shaders unconditionally. They are
// small, and whether they're used is determined only by the app source
// code and not by the Flutter manifest.
..._getMaterialShaders(),
if (targetPlatform != TargetPlatform.web_javascript)
..._getMaterialShaders(),
];
for (final _Asset asset in materialAssets) {
final File assetFile = asset.lookupAssetFile(_fileSystem);
Expand Down
60 changes: 60 additions & 0 deletions packages/flutter_tools/test/general.shard/asset_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:file/memory.dart';
import 'package:flutter_tools/src/asset.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/globals.dart' as globals;

Expand Down Expand Up @@ -81,6 +83,64 @@ void main() {
);
});
});

const String packageConfig = '''
{
"configVersion": 2,
"packages":[
{
"name": "my_package",
"rootUri": "file:///",
"packageUri": "lib/",
"languageVersion": "2.17"
}
]
}
''';

const String pubspecDotYaml = '''
name: my_package
''';

testUsingContext('Bundles material shaders on non-web platforms', () async {
final String shaderPath = globals.fs.path.join(
Cache.flutterRoot!,
'packages', 'flutter', 'lib', 'src', 'material', 'shaders', 'ink_sparkle.frag'
);
globals.fs.file(shaderPath).createSync(recursive: true);
globals.fs.file('.dart_tool/package_config.json')
..createSync(recursive: true)
..writeAsStringSync(packageConfig);
globals.fs.file('pubspec.yaml').writeAsStringSync(pubspecDotYaml);
final AssetBundle asset = AssetBundleFactory.instance.createBundle();

await asset.build(packagesPath: '.packages', targetPlatform: TargetPlatform.android_arm);

expect(asset.entries.keys, contains('shaders/ink_sparkle.frag'));
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.empty(),
});

testUsingContext('Does not bundles material shaders on web platforms', () async {
final String shaderPath = globals.fs.path.join(
Cache.flutterRoot!,
'packages', 'flutter', 'lib', 'src', 'material', 'shaders', 'ink_sparkle.frag'
);
globals.fs.file(shaderPath).createSync(recursive: true);
globals.fs.file('.dart_tool/package_config.json')
..createSync(recursive: true)
..writeAsStringSync(packageConfig);
globals.fs.file('pubspec.yaml').writeAsStringSync(pubspecDotYaml);
final AssetBundle asset = AssetBundleFactory.instance.createBundle();

await asset.build(packagesPath: '.packages', targetPlatform: TargetPlatform.web_javascript);

expect(asset.entries.keys, isNot(contains('shaders/ink_sparkle.frag')));
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.empty(),
});
}

Future<String> getValueAsString(String key, AssetBundle asset) async {
Expand Down

0 comments on commit 27281da

Please sign in to comment.