Unverified Commit dbcd7868 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] remove most globals from asset system and remove Cache...

[flutter_tools] remove most globals from asset system and remove Cache manipulation in unit tests (#70011)
parent 1c4b50ec
This diff is collapsed.
...@@ -11,6 +11,7 @@ import '../../base/logger.dart'; ...@@ -11,6 +11,7 @@ import '../../base/logger.dart';
import '../../build_info.dart'; import '../../build_info.dart';
import '../../convert.dart'; import '../../convert.dart';
import '../../devfs.dart'; import '../../devfs.dart';
import '../../globals.dart' as globals;
import '../build_system.dart'; import '../build_system.dart';
import '../depfile.dart'; import '../depfile.dart';
import 'common.dart'; import 'common.dart';
...@@ -47,6 +48,7 @@ Future<Depfile> copyAssets(Environment environment, Directory outputDirectory, { ...@@ -47,6 +48,7 @@ Future<Depfile> copyAssets(Environment environment, Directory outputDirectory, {
final AssetBundle assetBundle = AssetBundleFactory.defaultInstance( final AssetBundle assetBundle = AssetBundleFactory.defaultInstance(
logger: environment.logger, logger: environment.logger,
fileSystem: environment.fileSystem, fileSystem: environment.fileSystem,
platform: globals.platform,
).createBundle(); ).createBundle();
final int resultCode = await assetBundle.build( final int resultCode = await assetBundle.build(
manifestPath: pubspecFile.path, manifestPath: pubspecFile.path,
......
...@@ -114,6 +114,7 @@ Future<T> runInContext<T>( ...@@ -114,6 +114,7 @@ Future<T> runInContext<T>(
return AssetBundleFactory.defaultInstance( return AssetBundleFactory.defaultInstance(
logger: globals.logger, logger: globals.logger,
fileSystem: globals.fs, fileSystem: globals.fs,
platform: globals.platform,
); );
}, },
BuildSystem: () => FlutterBuildSystem( BuildSystem: () => FlutterBuildSystem(
......
...@@ -10,7 +10,6 @@ import 'package:file/memory.dart'; ...@@ -10,7 +10,6 @@ import 'package:file/memory.dart';
import 'package:flutter_tools/src/asset.dart'; import 'package:flutter_tools/src/asset.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/globals.dart' as globals; import 'package:flutter_tools/src/globals.dart' as globals;
import '../src/common.dart'; import '../src/common.dart';
...@@ -48,12 +47,6 @@ $fontsSection ...@@ -48,12 +47,6 @@ $fontsSection
'''); ''');
} }
void establishFlutterRoot() {
// Setting flutterRoot here so that it picks up the MemoryFileSystem's
// path separator.
Cache.flutterRoot = getFlutterRoot();
}
void writePackagesFile(String packages) { void writePackagesFile(String packages) {
globals.fs.file('.packages') globals.fs.file('.packages')
..createSync() ..createSync()
...@@ -113,7 +106,6 @@ $fontsSection ...@@ -113,7 +106,6 @@ $fontsSection
}); });
testUsingContext('App includes neither font manifest nor fonts when no defines fonts', () async { testUsingContext('App includes neither font manifest nor fonts when no defines fonts', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
writePubspecFile('pubspec.yaml', 'test'); writePubspecFile('pubspec.yaml', 'test');
...@@ -130,7 +122,6 @@ $fontsSection ...@@ -130,7 +122,6 @@ $fontsSection
}); });
testUsingContext('App font uses font file from package', () async { testUsingContext('App font uses font file from package', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
const String fontsSection = ''' const String fontsSection = '''
...@@ -159,7 +150,6 @@ $fontsSection ...@@ -159,7 +150,6 @@ $fontsSection
}); });
testUsingContext('App font uses local font file and package font file', () async { testUsingContext('App font uses local font file and package font file', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
const String fontsSection = ''' const String fontsSection = '''
...@@ -192,7 +182,6 @@ $fontsSection ...@@ -192,7 +182,6 @@ $fontsSection
}); });
testUsingContext('App uses package font with own font file', () async { testUsingContext('App uses package font with own font file', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
writePubspecFile('pubspec.yaml', 'test'); writePubspecFile('pubspec.yaml', 'test');
...@@ -226,7 +215,6 @@ $fontsSection ...@@ -226,7 +215,6 @@ $fontsSection
}); });
testUsingContext('App uses package font with font file from another package', () async { testUsingContext('App uses package font with font file from another package', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
writePubspecFile('pubspec.yaml', 'test'); writePubspecFile('pubspec.yaml', 'test');
...@@ -261,7 +249,6 @@ $fontsSection ...@@ -261,7 +249,6 @@ $fontsSection
}); });
testUsingContext('App uses package font with properties and own font file', () async { testUsingContext('App uses package font with properties and own font file', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
writePubspecFile('pubspec.yaml', 'test'); writePubspecFile('pubspec.yaml', 'test');
...@@ -297,7 +284,6 @@ $fontsSection ...@@ -297,7 +284,6 @@ $fontsSection
}); });
testUsingContext('App uses local font and package font with own font file.', () async { testUsingContext('App uses local font and package font with own font file.', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
const String fontsSection = ''' const String fontsSection = '''
......
...@@ -10,7 +10,6 @@ import 'package:file/memory.dart'; ...@@ -10,7 +10,6 @@ import 'package:file/memory.dart';
import 'package:flutter_tools/src/asset.dart'; import 'package:flutter_tools/src/asset.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/globals.dart' as globals; import 'package:flutter_tools/src/globals.dart' as globals;
import '../src/common.dart'; import '../src/common.dart';
...@@ -56,10 +55,6 @@ $assetsSection ...@@ -56,10 +55,6 @@ $assetsSection
'''); ''');
} }
void establishFlutterRoot() {
Cache.flutterRoot = getFlutterRoot();
}
void writePackagesFile(String packages) { void writePackagesFile(String packages) {
globals.fs.file('.packages') globals.fs.file('.packages')
..createSync() ..createSync()
...@@ -120,7 +115,6 @@ $assetsSection ...@@ -120,7 +115,6 @@ $assetsSection
group('AssetBundle assets from packages', () { group('AssetBundle assets from packages', () {
testUsingContext('No assets are bundled when the package has no assets', () async { testUsingContext('No assets are bundled when the package has no assets', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
writePubspecFile('pubspec.yaml', 'test'); writePubspecFile('pubspec.yaml', 'test');
...@@ -145,7 +139,6 @@ $assetsSection ...@@ -145,7 +139,6 @@ $assetsSection
}); });
testUsingContext('No assets are bundled when the package has an asset that is not listed', () async { testUsingContext('No assets are bundled when the package has an asset that is not listed', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
writePubspecFile('pubspec.yaml', 'test'); writePubspecFile('pubspec.yaml', 'test');
...@@ -174,7 +167,6 @@ $assetsSection ...@@ -174,7 +167,6 @@ $assetsSection
testUsingContext('One asset is bundled when the package has and lists one ' testUsingContext('One asset is bundled when the package has and lists one '
'asset its pubspec', () async { 'asset its pubspec', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
writePubspecFile('pubspec.yaml', 'test'); writePubspecFile('pubspec.yaml', 'test');
...@@ -203,7 +195,6 @@ $assetsSection ...@@ -203,7 +195,6 @@ $assetsSection
testUsingContext('One asset is bundled when the package has one asset, ' testUsingContext('One asset is bundled when the package has one asset, '
"listed in the app's pubspec", () async { "listed in the app's pubspec", () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
final List<String> assetEntries = <String>['packages/test_package/a/foo']; final List<String> assetEntries = <String>['packages/test_package/a/foo'];
...@@ -232,7 +223,6 @@ $assetsSection ...@@ -232,7 +223,6 @@ $assetsSection
testUsingContext('One asset and its variant are bundled when the package ' testUsingContext('One asset and its variant are bundled when the package '
'has an asset and a variant, and lists the asset in its pubspec', () async { 'has an asset and a variant, and lists the asset in its pubspec', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
writePubspecFile('pubspec.yaml', 'test'); writePubspecFile('pubspec.yaml', 'test');
...@@ -261,7 +251,6 @@ $assetsSection ...@@ -261,7 +251,6 @@ $assetsSection
testUsingContext('One asset and its variant are bundled when the package ' testUsingContext('One asset and its variant are bundled when the package '
'has an asset and a variant, and the app lists the asset in its pubspec', () async { 'has an asset and a variant, and the app lists the asset in its pubspec', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
writePubspecFile( writePubspecFile(
...@@ -293,7 +282,6 @@ $assetsSection ...@@ -293,7 +282,6 @@ $assetsSection
testUsingContext('Two assets are bundled when the package has and lists ' testUsingContext('Two assets are bundled when the package has and lists '
'two assets in its pubspec', () async { 'two assets in its pubspec', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
writePubspecFile('pubspec.yaml', 'test'); writePubspecFile('pubspec.yaml', 'test');
...@@ -322,7 +310,6 @@ $assetsSection ...@@ -322,7 +310,6 @@ $assetsSection
}); });
testUsingContext("Two assets are bundled when the package has two assets, listed in the app's pubspec", () async { testUsingContext("Two assets are bundled when the package has two assets, listed in the app's pubspec", () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
final List<String> assetEntries = <String>[ final List<String> assetEntries = <String>[
...@@ -358,7 +345,6 @@ $assetsSection ...@@ -358,7 +345,6 @@ $assetsSection
}); });
testUsingContext('Two assets are bundled when two packages each have and list an asset their pubspec', () async { testUsingContext('Two assets are bundled when two packages each have and list an asset their pubspec', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
writePubspecFile( writePubspecFile(
...@@ -398,7 +384,6 @@ $assetsSection ...@@ -398,7 +384,6 @@ $assetsSection
}); });
testUsingContext("Two assets are bundled when two packages each have an asset, listed in the app's pubspec", () async { testUsingContext("Two assets are bundled when two packages each have an asset, listed in the app's pubspec", () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
final List<String> assetEntries = <String>[ final List<String> assetEntries = <String>[
...@@ -442,7 +427,6 @@ $assetsSection ...@@ -442,7 +427,6 @@ $assetsSection
testUsingContext('One asset is bundled when the app depends on a package, ' testUsingContext('One asset is bundled when the app depends on a package, '
'listing in its pubspec an asset from another package', () async { 'listing in its pubspec an asset from another package', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
writePubspecFile( writePubspecFile(
'pubspec.yaml', 'pubspec.yaml',
...@@ -478,7 +462,6 @@ $assetsSection ...@@ -478,7 +462,6 @@ $assetsSection
}); });
testUsingContext('Asset paths can contain URL reserved characters', () async { testUsingContext('Asset paths can contain URL reserved characters', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
writePubspecFile('pubspec.yaml', 'test'); writePubspecFile('pubspec.yaml', 'test');
...@@ -508,7 +491,6 @@ $assetsSection ...@@ -508,7 +491,6 @@ $assetsSection
group('AssetBundle assets from scanned paths', () { group('AssetBundle assets from scanned paths', () {
testUsingContext('Two assets are bundled when scanning their directory', () async { testUsingContext('Two assets are bundled when scanning their directory', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
writePubspecFile('pubspec.yaml', 'test'); writePubspecFile('pubspec.yaml', 'test');
...@@ -539,7 +521,6 @@ $assetsSection ...@@ -539,7 +521,6 @@ $assetsSection
}); });
testUsingContext('Two assets are bundled when listing one and scanning second directory', () async { testUsingContext('Two assets are bundled when listing one and scanning second directory', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
writePubspecFile('pubspec.yaml', 'test'); writePubspecFile('pubspec.yaml', 'test');
...@@ -556,8 +537,8 @@ $assetsSection ...@@ -556,8 +537,8 @@ $assetsSection
writeAssets('p/p/', assetsOnDisk); writeAssets('p/p/', assetsOnDisk);
const String expectedAssetManifest = const String expectedAssetManifest =
'{"packages/test_package/abc/bar":["packages/test_package/abc/bar"],' '{"packages/test_package/a/foo":["packages/test_package/a/foo"],'
'"packages/test_package/a/foo":["packages/test_package/a/foo"]}'; '"packages/test_package/abc/bar":["packages/test_package/abc/bar"]}';
await buildAndVerifyAssets( await buildAndVerifyAssets(
assetsOnDisk, assetsOnDisk,
...@@ -570,7 +551,6 @@ $assetsSection ...@@ -570,7 +551,6 @@ $assetsSection
}); });
testUsingContext('One asset is bundled with variant, scanning wrong directory', () async { testUsingContext('One asset is bundled with variant, scanning wrong directory', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
writePubspecFile('pubspec.yaml', 'test'); writePubspecFile('pubspec.yaml', 'test');
...@@ -600,7 +580,6 @@ $assetsSection ...@@ -600,7 +580,6 @@ $assetsSection
group('AssetBundle assets from scanned paths with MemoryFileSystem', () { group('AssetBundle assets from scanned paths with MemoryFileSystem', () {
testUsingContext('One asset is bundled with variant, scanning directory', () async { testUsingContext('One asset is bundled with variant, scanning directory', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
writePubspecFile('pubspec.yaml', 'test'); writePubspecFile('pubspec.yaml', 'test');
...@@ -630,7 +609,6 @@ $assetsSection ...@@ -630,7 +609,6 @@ $assetsSection
}); });
testUsingContext('No asset is bundled with variant, no assets or directories are listed', () async { testUsingContext('No asset is bundled with variant, no assets or directories are listed', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
writePubspecFile('pubspec.yaml', 'test'); writePubspecFile('pubspec.yaml', 'test');
...@@ -659,7 +637,6 @@ $assetsSection ...@@ -659,7 +637,6 @@ $assetsSection
}); });
testUsingContext('Expect error generating manifest, wrong non-existing directory is listed', () async { testUsingContext('Expect error generating manifest, wrong non-existing directory is listed', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
writePubspecFile('pubspec.yaml', 'test'); writePubspecFile('pubspec.yaml', 'test');
......
...@@ -10,7 +10,6 @@ import 'package:flutter_tools/src/asset.dart'; ...@@ -10,7 +10,6 @@ import 'package:flutter_tools/src/asset.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/bundle.dart'; import 'package:flutter_tools/src/bundle.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/devfs.dart'; import 'package:flutter_tools/src/devfs.dart';
import 'package:flutter_tools/src/globals.dart' as globals; import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
...@@ -19,10 +18,6 @@ import '../src/common.dart'; ...@@ -19,10 +18,6 @@ import '../src/common.dart';
import '../src/context.dart'; import '../src/context.dart';
void main() { void main() {
setUpAll(() {
Cache.flutterRoot = getFlutterRoot();
});
group('AssetBundle.build', () { group('AssetBundle.build', () {
FileSystem testFileSystem; FileSystem testFileSystem;
......
...@@ -10,7 +10,6 @@ import 'package:file/memory.dart'; ...@@ -10,7 +10,6 @@ import 'package:file/memory.dart';
import 'package:flutter_tools/src/asset.dart'; import 'package:flutter_tools/src/asset.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/globals.dart' as globals; import 'package:flutter_tools/src/globals.dart' as globals;
import '../src/common.dart'; import '../src/common.dart';
...@@ -41,7 +40,6 @@ void main() { ...@@ -41,7 +40,6 @@ void main() {
testUsingContext('main asset and variants', () async { testUsingContext('main asset and variants', () async {
// Setting flutterRoot here so that it picks up the MemoryFileSystem's // Setting flutterRoot here so that it picks up the MemoryFileSystem's
// path separator. // path separator.
Cache.flutterRoot = getFlutterRoot();
writeEmptySchemaFile(globals.fs); writeEmptySchemaFile(globals.fs);
globals.fs.file('pubspec.yaml') globals.fs.file('pubspec.yaml')
......
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