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