Unverified Commit e8a75aa0 authored by Andrew Kolos's avatar Andrew Kolos Committed by GitHub

refactor: remove implicit globals dependencies in `writeBundle` (#143343)

This is in service of https://github.com/flutter/flutter/pull/141194

This will make it easier to get the `flutter run -d <browser>` and `flutter build fuschia` cases easier to get under test.
parent 66367dd8
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:pool/pool.dart'; import 'package:pool/pool.dart';
import 'package:process/process.dart';
import 'artifacts.dart';
import 'asset.dart' hide defaultManifestPath; import 'asset.dart' hide defaultManifestPath;
import 'base/common.dart'; import 'base/common.dart';
import 'base/file_system.dart'; import 'base/file_system.dart';
...@@ -137,16 +139,18 @@ Future<AssetBundle?> buildAssets({ ...@@ -137,16 +139,18 @@ Future<AssetBundle?> buildAssets({
Future<void> writeBundle( Future<void> writeBundle(
Directory bundleDir, Directory bundleDir,
Map<String, AssetBundleEntry> assetEntries, { Map<String, AssetBundleEntry> assetEntries, {
Logger? loggerOverride,
required TargetPlatform targetPlatform, required TargetPlatform targetPlatform,
required ImpellerStatus impellerStatus, required ImpellerStatus impellerStatus,
required ProcessManager processManager,
required FileSystem fileSystem,
required Artifacts artifacts,
required Logger logger,
}) async { }) async {
loggerOverride ??= globals.logger;
if (bundleDir.existsSync()) { if (bundleDir.existsSync()) {
try { try {
bundleDir.deleteSync(recursive: true); bundleDir.deleteSync(recursive: true);
} on FileSystemException catch (err) { } on FileSystemException catch (err) {
loggerOverride.printWarning( logger.printWarning(
'Failed to clean up asset directory ${bundleDir.path}: $err\n' 'Failed to clean up asset directory ${bundleDir.path}: $err\n'
'To clean build artifacts, use the command "flutter clean".' 'To clean build artifacts, use the command "flutter clean".'
); );
...@@ -155,17 +159,17 @@ Future<void> writeBundle( ...@@ -155,17 +159,17 @@ Future<void> writeBundle(
bundleDir.createSync(recursive: true); bundleDir.createSync(recursive: true);
final ShaderCompiler shaderCompiler = ShaderCompiler( final ShaderCompiler shaderCompiler = ShaderCompiler(
processManager: globals.processManager, processManager: processManager,
logger: globals.logger, logger: logger,
fileSystem: globals.fs, fileSystem: fileSystem,
artifacts: globals.artifacts!, artifacts: artifacts,
); );
final SceneImporter sceneImporter = SceneImporter( final SceneImporter sceneImporter = SceneImporter(
processManager: globals.processManager, processManager: processManager,
logger: globals.logger, logger: logger,
fileSystem: globals.fs, fileSystem: fileSystem,
artifacts: globals.artifacts!, artifacts: artifacts,
); );
// Limit number of open files to avoid running out of file descriptors. // Limit number of open files to avoid running out of file descriptors.
...@@ -179,7 +183,7 @@ Future<void> writeBundle( ...@@ -179,7 +183,7 @@ Future<void> writeBundle(
// to `%23.ext`. However, we have to keep it this way since the // to `%23.ext`. However, we have to keep it this way since the
// platform channels in the framework will URI encode these values, // platform channels in the framework will URI encode these values,
// and the native APIs will look for files this way. // and the native APIs will look for files this way.
final File file = globals.fs.file(globals.fs.path.join(bundleDir.path, entry.key)); final File file = fileSystem.file(fileSystem.path.join(bundleDir.path, entry.key));
file.parent.createSync(recursive: true); file.parent.createSync(recursive: true);
final DevFSContent devFSContent = entry.value.content; final DevFSContent devFSContent = entry.value.content;
if (devFSContent is DevFSFileContent) { if (devFSContent is DevFSFileContent) {
......
...@@ -591,6 +591,10 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { ...@@ -591,6 +591,10 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
assetBundle.entries, assetBundle.entries,
targetPlatform: TargetPlatform.tester, targetPlatform: TargetPlatform.tester,
impellerStatus: impellerStatus, impellerStatus: impellerStatus,
processManager: globals.processManager,
fileSystem: globals.fs,
artifacts: globals.artifacts!,
logger: globals.logger,
); );
} }
} }
......
...@@ -886,6 +886,10 @@ class WebDevFS implements DevFS { ...@@ -886,6 +886,10 @@ class WebDevFS implements DevFS {
bundle.entries, bundle.entries,
targetPlatform: TargetPlatform.web_javascript, targetPlatform: TargetPlatform.web_javascript,
impellerStatus: ImpellerStatus.disabled, impellerStatus: ImpellerStatus.disabled,
processManager: globals.processManager,
fileSystem: globals.fs,
artifacts: globals.artifacts!,
logger: globals.logger,
); );
} }
} }
......
...@@ -537,9 +537,12 @@ flutter: ...@@ -537,9 +537,12 @@ flutter:
await writeBundle( await writeBundle(
directory, directory,
const <String, AssetBundleEntry>{}, const <String, AssetBundleEntry>{},
loggerOverride: testLogger,
targetPlatform: TargetPlatform.android, targetPlatform: TargetPlatform.android,
impellerStatus: ImpellerStatus.disabled, impellerStatus: ImpellerStatus.disabled,
processManager: globals.processManager,
fileSystem: globals.fs,
artifacts: globals.artifacts!,
logger: testLogger,
); );
expect(testLogger.warningText, contains('Expected Error Text')); expect(testLogger.warningText, contains('Expected Error Text'));
...@@ -659,9 +662,12 @@ flutter: ...@@ -659,9 +662,12 @@ flutter:
await writeBundle( await writeBundle(
output, output,
bundle.entries, bundle.entries,
loggerOverride: testLogger,
targetPlatform: TargetPlatform.android, targetPlatform: TargetPlatform.android,
impellerStatus: ImpellerStatus.disabled, impellerStatus: ImpellerStatus.disabled,
processManager: globals.processManager,
fileSystem: globals.fs,
artifacts: globals.artifacts!,
logger: testLogger,
); );
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -707,9 +713,12 @@ flutter: ...@@ -707,9 +713,12 @@ flutter:
await writeBundle( await writeBundle(
output, output,
bundle.entries, bundle.entries,
loggerOverride: testLogger,
targetPlatform: TargetPlatform.web_javascript, targetPlatform: TargetPlatform.web_javascript,
impellerStatus: ImpellerStatus.disabled, impellerStatus: ImpellerStatus.disabled,
processManager: globals.processManager,
fileSystem: globals.fs,
artifacts: globals.artifacts!,
logger: testLogger,
); );
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -790,9 +799,12 @@ flutter: ...@@ -790,9 +799,12 @@ flutter:
await writeBundle( await writeBundle(
output, output,
bundle.entries, bundle.entries,
loggerOverride: testLogger,
targetPlatform: TargetPlatform.web_javascript, targetPlatform: TargetPlatform.web_javascript,
impellerStatus: ImpellerStatus.disabled, impellerStatus: ImpellerStatus.disabled,
processManager: globals.processManager,
fileSystem: globals.fs,
artifacts: globals.artifacts!,
logger: testLogger,
); );
expect((globals.processManager as FakeProcessManager).hasRemainingExpectations, false); expect((globals.processManager as FakeProcessManager).hasRemainingExpectations, false);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
......
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