Skip to content

Commit

Permalink
refactor: remove implicit globals dependencies in writeBundle (#143…
Browse files Browse the repository at this point in the history
…343)

This is in service of flutter/flutter#141194

This will make it easier to get the `flutter run -d <browser>` and `flutter build fuschia` cases easier to get under test.
  • Loading branch information
andrewkolos authored Feb 13, 2024
1 parent 66367dd commit e8a75aa
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
28 changes: 16 additions & 12 deletions packages/flutter_tools/lib/src/bundle_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

import 'package:meta/meta.dart';
import 'package:pool/pool.dart';
import 'package:process/process.dart';

import 'artifacts.dart';
import 'asset.dart' hide defaultManifestPath;
import 'base/common.dart';
import 'base/file_system.dart';
Expand Down Expand Up @@ -137,16 +139,18 @@ Future<AssetBundle?> buildAssets({
Future<void> writeBundle(
Directory bundleDir,
Map<String, AssetBundleEntry> assetEntries, {
Logger? loggerOverride,
required TargetPlatform targetPlatform,
required ImpellerStatus impellerStatus,
required ProcessManager processManager,
required FileSystem fileSystem,
required Artifacts artifacts,
required Logger logger,
}) async {
loggerOverride ??= globals.logger;
if (bundleDir.existsSync()) {
try {
bundleDir.deleteSync(recursive: true);
} on FileSystemException catch (err) {
loggerOverride.printWarning(
logger.printWarning(
'Failed to clean up asset directory ${bundleDir.path}: $err\n'
'To clean build artifacts, use the command "flutter clean".'
);
Expand All @@ -155,17 +159,17 @@ Future<void> writeBundle(
bundleDir.createSync(recursive: true);

final ShaderCompiler shaderCompiler = ShaderCompiler(
processManager: globals.processManager,
logger: globals.logger,
fileSystem: globals.fs,
artifacts: globals.artifacts!,
processManager: processManager,
logger: logger,
fileSystem: fileSystem,
artifacts: artifacts,
);

final SceneImporter sceneImporter = SceneImporter(
processManager: globals.processManager,
logger: globals.logger,
fileSystem: globals.fs,
artifacts: globals.artifacts!,
processManager: processManager,
logger: logger,
fileSystem: fileSystem,
artifacts: artifacts,
);

// Limit number of open files to avoid running out of file descriptors.
Expand All @@ -179,7 +183,7 @@ Future<void> writeBundle(
// to `%23.ext`. However, we have to keep it this way since the
// platform channels in the framework will URI encode these values,
// 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);
final DevFSContent devFSContent = entry.value.content;
if (devFSContent is DevFSFileContent) {
Expand Down
4 changes: 4 additions & 0 deletions packages/flutter_tools/lib/src/commands/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,10 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
assetBundle.entries,
targetPlatform: TargetPlatform.tester,
impellerStatus: impellerStatus,
processManager: globals.processManager,
fileSystem: globals.fs,
artifacts: globals.artifacts!,
logger: globals.logger,
);
}
}
Expand Down
4 changes: 4 additions & 0 deletions packages/flutter_tools/lib/src/isolated/devfs_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,10 @@ class WebDevFS implements DevFS {
bundle.entries,
targetPlatform: TargetPlatform.web_javascript,
impellerStatus: ImpellerStatus.disabled,
processManager: globals.processManager,
fileSystem: globals.fs,
artifacts: globals.artifacts!,
logger: globals.logger,
);
}
}
Expand Down
20 changes: 16 additions & 4 deletions packages/flutter_tools/test/general.shard/asset_bundle_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,12 @@ flutter:
await writeBundle(
directory,
const <String, AssetBundleEntry>{},
loggerOverride: testLogger,
targetPlatform: TargetPlatform.android,
impellerStatus: ImpellerStatus.disabled,
processManager: globals.processManager,
fileSystem: globals.fs,
artifacts: globals.artifacts!,
logger: testLogger,
);

expect(testLogger.warningText, contains('Expected Error Text'));
Expand Down Expand Up @@ -659,9 +662,12 @@ flutter:
await writeBundle(
output,
bundle.entries,
loggerOverride: testLogger,
targetPlatform: TargetPlatform.android,
impellerStatus: ImpellerStatus.disabled,
processManager: globals.processManager,
fileSystem: globals.fs,
artifacts: globals.artifacts!,
logger: testLogger,
);

}, overrides: <Type, Generator>{
Expand Down Expand Up @@ -707,9 +713,12 @@ flutter:
await writeBundle(
output,
bundle.entries,
loggerOverride: testLogger,
targetPlatform: TargetPlatform.web_javascript,
impellerStatus: ImpellerStatus.disabled,
processManager: globals.processManager,
fileSystem: globals.fs,
artifacts: globals.artifacts!,
logger: testLogger,
);

}, overrides: <Type, Generator>{
Expand Down Expand Up @@ -790,9 +799,12 @@ flutter:
await writeBundle(
output,
bundle.entries,
loggerOverride: testLogger,
targetPlatform: TargetPlatform.web_javascript,
impellerStatus: ImpellerStatus.disabled,
processManager: globals.processManager,
fileSystem: globals.fs,
artifacts: globals.artifacts!,
logger: testLogger,
);
expect((globals.processManager as FakeProcessManager).hasRemainingExpectations, false);
}, overrides: <Type, Generator>{
Expand Down

0 comments on commit e8a75aa

Please sign in to comment.