refactor asset bundle code to not depend on the global Cache.flutterRoot (#142277)
Fixes https://github.com/flutter/flutter/issues/142285. Part of work on https://github.com/flutter/flutter/pull/141194. This is a refactor. There should be no changes in tool behavior.
This commit is contained in:
@@ -368,6 +368,11 @@ flutter:
|
||||
logger: logger,
|
||||
fileSystem: testFileSystem,
|
||||
platform: platform,
|
||||
flutterRoot: Cache.defaultFlutterRoot(
|
||||
platform: platform,
|
||||
fileSystem: testFileSystem,
|
||||
userMessages: UserMessages(),
|
||||
),
|
||||
splitDeferredAssets: true,
|
||||
);
|
||||
|
||||
@@ -379,15 +384,6 @@ flutter:
|
||||
return bundle;
|
||||
}
|
||||
|
||||
late String? previousCacheFlutterRootValue;
|
||||
|
||||
setUp(() {
|
||||
previousCacheFlutterRootValue = Cache.flutterRoot;
|
||||
Cache.flutterRoot = Cache.defaultFlutterRoot(platform: platform, fileSystem: testFileSystem, userMessages: UserMessages());
|
||||
});
|
||||
|
||||
tearDown(() => Cache.flutterRoot = previousCacheFlutterRootValue);
|
||||
|
||||
testWithoutContext('correctly bundles assets given a simple asset manifest with flavors', () async {
|
||||
testFileSystem.file('.packages').createSync();
|
||||
testFileSystem.file(testFileSystem.path.join('assets', 'common', 'image.png')).createSync(recursive: true);
|
||||
|
||||
@@ -42,14 +42,15 @@ void main() {
|
||||
group('AssetBundle asset variants (with Unix-style paths)', () {
|
||||
late Platform platform;
|
||||
late FileSystem fs;
|
||||
late String flutterRoot;
|
||||
|
||||
setUp(() {
|
||||
platform = FakePlatform();
|
||||
fs = MemoryFileSystem.test();
|
||||
Cache.flutterRoot = Cache.defaultFlutterRoot(
|
||||
flutterRoot = Cache.defaultFlutterRoot(
|
||||
platform: platform,
|
||||
fileSystem: fs,
|
||||
userMessages: UserMessages()
|
||||
userMessages: UserMessages(),
|
||||
);
|
||||
|
||||
fs.file('.packages').createSync();
|
||||
@@ -94,6 +95,7 @@ ${assets.map((String entry) => ' - $entry').join('\n')}
|
||||
logger: BufferLogger.test(),
|
||||
fileSystem: fs,
|
||||
platform: platform,
|
||||
flutterRoot: flutterRoot,
|
||||
);
|
||||
|
||||
await bundle.build(
|
||||
@@ -147,6 +149,7 @@ ${assets.map((String entry) => ' - $entry').join('\n')}
|
||||
final ManifestAssetBundle bundle = ManifestAssetBundle(
|
||||
logger: BufferLogger.test(),
|
||||
fileSystem: fs,
|
||||
flutterRoot: flutterRoot,
|
||||
platform: platform,
|
||||
);
|
||||
|
||||
@@ -203,6 +206,7 @@ ${assets.map((String entry) => ' - $entry').join('\n')}
|
||||
logger: BufferLogger.test(),
|
||||
fileSystem: fs,
|
||||
platform: platform,
|
||||
flutterRoot: flutterRoot,
|
||||
);
|
||||
|
||||
await bundle.build(
|
||||
@@ -248,6 +252,7 @@ ${assets.map((String entry) => ' - $entry').join('\n')}
|
||||
logger: BufferLogger.test(),
|
||||
fileSystem: fs,
|
||||
platform: platform,
|
||||
flutterRoot: flutterRoot,
|
||||
);
|
||||
|
||||
await bundle.build(
|
||||
@@ -274,11 +279,12 @@ ${assets.map((String entry) => ' - $entry').join('\n')}
|
||||
group('AssetBundle asset variants (with Windows-style filepaths)', () {
|
||||
late final Platform platform;
|
||||
late final FileSystem fs;
|
||||
late final String flutterRoot;
|
||||
|
||||
setUp(() {
|
||||
platform = FakePlatform(operatingSystem: 'windows');
|
||||
fs = MemoryFileSystem.test(style: FileSystemStyle.windows);
|
||||
Cache.flutterRoot = Cache.defaultFlutterRoot(
|
||||
flutterRoot = Cache.defaultFlutterRoot(
|
||||
platform: platform,
|
||||
fileSystem: fs,
|
||||
userMessages: UserMessages()
|
||||
@@ -318,6 +324,7 @@ flutter:
|
||||
logger: BufferLogger.test(),
|
||||
fileSystem: fs,
|
||||
platform: platform,
|
||||
flutterRoot: flutterRoot,
|
||||
);
|
||||
|
||||
await bundle.build(
|
||||
|
||||
@@ -26,16 +26,8 @@ void main() {
|
||||
group('Assets (${style.name} file system)', () {
|
||||
late FileSystem fileSystem;
|
||||
late BufferLogger logger;
|
||||
late String? previousCacheFlutterRootValue;
|
||||
late Platform platform;
|
||||
|
||||
setUpAll(() {
|
||||
previousCacheFlutterRootValue = Cache.flutterRoot;
|
||||
});
|
||||
|
||||
tearDownAll(() {
|
||||
Cache.flutterRoot = previousCacheFlutterRootValue;
|
||||
});
|
||||
late String flutterRoot;
|
||||
|
||||
setUp(() {
|
||||
fileSystem = MemoryFileSystem(
|
||||
@@ -44,7 +36,7 @@ void main() {
|
||||
logger = BufferLogger.test();
|
||||
platform = FakePlatform(
|
||||
operatingSystem: style == Style.posix ? 'linux' : 'windows');
|
||||
Cache.flutterRoot = Cache.defaultFlutterRoot(
|
||||
flutterRoot = Cache.defaultFlutterRoot(
|
||||
platform: platform,
|
||||
fileSystem: fileSystem,
|
||||
userMessages: UserMessages(),
|
||||
@@ -60,6 +52,7 @@ void main() {
|
||||
fileSystem: fileSystem,
|
||||
platform: platform,
|
||||
splitDeferredAssets: true,
|
||||
flutterRoot: flutterRoot,
|
||||
);
|
||||
|
||||
fileSystem.file(fileSystem.path.join('font', 'pubspec.yaml'))
|
||||
@@ -157,6 +150,7 @@ dependencies:
|
||||
fileSystem: fileSystem,
|
||||
platform: platform,
|
||||
splitDeferredAssets: true,
|
||||
flutterRoot: flutterRoot,
|
||||
);
|
||||
|
||||
await assetBundle.build(
|
||||
@@ -175,7 +169,7 @@ dependencies:
|
||||
testWithoutContext('bundles material shaders on non-web platforms',
|
||||
() async {
|
||||
final String shaderPath = fileSystem.path.join(
|
||||
Cache.flutterRoot!,
|
||||
flutterRoot,
|
||||
'packages',
|
||||
'flutter',
|
||||
'lib',
|
||||
@@ -205,6 +199,7 @@ dependencies:
|
||||
logger: logger,
|
||||
fileSystem: fileSystem,
|
||||
platform: platform,
|
||||
flutterRoot: flutterRoot,
|
||||
);
|
||||
|
||||
await assetBundle.build(
|
||||
@@ -219,7 +214,7 @@ dependencies:
|
||||
testWithoutContext('bundles material shaders on web platforms',
|
||||
() async {
|
||||
final String shaderPath = fileSystem.path.join(
|
||||
Cache.flutterRoot!,
|
||||
flutterRoot,
|
||||
'packages',
|
||||
'flutter',
|
||||
'lib',
|
||||
@@ -249,6 +244,7 @@ dependencies:
|
||||
logger: logger,
|
||||
fileSystem: fileSystem,
|
||||
platform: platform,
|
||||
flutterRoot: flutterRoot,
|
||||
);
|
||||
|
||||
await assetBundle.build(
|
||||
|
||||
Reference in New Issue
Block a user