Unverified Commit 4bd9bcd7 authored by Kevin Moore's avatar Kevin Moore Committed by GitHub

tool: DRY up DepfileService (#125922)

parent f704c689
......@@ -18,6 +18,7 @@ import '../base/utils.dart';
import '../cache.dart';
import '../convert.dart';
import '../reporting/reporting.dart';
import 'depfile.dart';
import 'exceptions.dart';
import 'file_store.dart';
import 'source.dart';
......@@ -524,6 +525,11 @@ class Environment {
/// When [true], the main entrypoint is wrapped and the wrapper becomes
/// the new entrypoint.
final bool generateDartPluginRegistry;
late final DepfileService depFileService = DepfileService(
logger: logger,
fileSystem: fileSystem,
);
}
/// The result information from the build system.
......
......@@ -69,11 +69,7 @@ abstract class AndroidAssetBundle extends Target {
buildMode: buildMode,
shaderTarget: ShaderTarget.impellerAndroid,
);
final DepfileService depfileService = DepfileService(
fileSystem: environment.fileSystem,
logger: environment.logger,
);
depfileService.writeToFile(
environment.depFileService.writeToFile(
assetDepfile,
environment.buildDir.childFile('flutter_assets.d'),
);
......@@ -264,11 +260,7 @@ class AndroidAot extends AotElfBase {
outputs.add(environment.fileSystem.file(unit.path));
}
}
final DepfileService depfileService = DepfileService(
fileSystem: environment.fileSystem,
logger: environment.logger,
);
depfileService.writeToFile(
environment.depFileService.writeToFile(
Depfile(<File>[], outputs),
environment.buildDir.childFile('flutter_$name.d'),
writeEmpty: true,
......@@ -351,11 +343,7 @@ class AndroidAotBundle extends Target {
inputs.add(manifestFile);
outputs.add(destinationFile);
}
final DepfileService depfileService = DepfileService(
fileSystem: environment.fileSystem,
logger: environment.logger,
);
depfileService.writeToFile(
environment.depFileService.writeToFile(
Depfile(inputs, outputs),
environment.buildDir.childFile('flutter_$name.d'),
writeEmpty: true,
......@@ -433,11 +421,7 @@ class AndroidAotDeferredComponentsBundle extends Target {
libDepfile.inputs.add(manifestFile);
}
final DepfileService depfileService = DepfileService(
fileSystem: environment.fileSystem,
logger: environment.logger,
);
depfileService.writeToFile(
environment.depFileService.writeToFile(
libDepfile,
environment.buildDir.childFile('flutter_$name.d'),
writeEmpty: true,
......
......@@ -323,11 +323,7 @@ class CopyAssets extends Target {
targetPlatform: TargetPlatform.android,
shaderTarget: ShaderTarget.sksl,
);
final DepfileService depfileService = DepfileService(
fileSystem: environment.fileSystem,
logger: environment.logger,
);
depfileService.writeToFile(
environment.depFileService.writeToFile(
depfile,
environment.buildDir.childFile('flutter_assets.d'),
);
......
......@@ -77,11 +77,7 @@ class CopyFlutterBundle extends Target {
buildMode: buildMode,
shaderTarget: ShaderTarget.sksl,
);
final DepfileService depfileService = DepfileService(
fileSystem: environment.fileSystem,
logger: environment.logger,
);
depfileService.writeToFile(
environment.depFileService.writeToFile(
assetDepfile,
environment.buildDir.childFile('flutter_assets.d'),
);
......
......@@ -74,10 +74,6 @@ class DeferredComponentsGenSnapshotValidatorTarget extends Target {
@override
Future<void> build(Environment environment) async {
final DepfileService depfileService = DepfileService(
fileSystem: environment.fileSystem,
logger: environment.logger,
);
validator = DeferredComponentsGenSnapshotValidator(
environment,
title: title,
......@@ -100,7 +96,7 @@ class DeferredComponentsGenSnapshotValidatorTarget extends Target {
validator!.handleResults();
depfileService.writeToFile(
environment.depFileService.writeToFile(
Depfile(validator!.inputs, validator!.outputs),
environment.buildDir.childFile('flutter_$name.d'),
);
......
......@@ -526,11 +526,7 @@ abstract class IosAssetBundle extends Target {
flutterProject.ios.appFrameworkInfoPlist,
],
);
final DepfileService depfileService = DepfileService(
fileSystem: environment.fileSystem,
logger: environment.logger,
);
depfileService.writeToFile(
environment.depFileService.writeToFile(
assetDepfile,
environment.buildDir.childFile('flutter_assets.d'),
);
......
......@@ -84,11 +84,7 @@ class UnpackLinux extends Target {
platform: targetPlatform,
)
);
final DepfileService depfileService = DepfileService(
fileSystem: environment.fileSystem,
logger: environment.logger,
);
depfileService.writeToFile(
environment.depFileService.writeToFile(
depfile,
environment.buildDir.childFile(_kLinuxDepfile),
);
......@@ -147,11 +143,7 @@ abstract class BundleLinuxAssets extends Target {
},
shaderTarget: ShaderTarget.sksl,
);
final DepfileService depfileService = DepfileService(
fileSystem: environment.fileSystem,
logger: environment.logger,
);
depfileService.writeToFile(
environment.depFileService.writeToFile(
depfile,
environment.buildDir.childFile('flutter_assets.d'),
);
......
......@@ -57,10 +57,6 @@ class GenerateLocalizationsTarget extends Target {
logger: environment.logger,
defaultArbDir: defaultArbDir,
);
final DepfileService depfileService = DepfileService(
logger: environment.logger,
fileSystem: environment.fileSystem,
);
generateLocalizations(
logger: environment.logger,
options: options,
......@@ -87,7 +83,7 @@ class GenerateLocalizationsTarget extends Target {
environment.fileSystem.file(outputFile),
],
);
depfileService.writeToFile(
environment.depFileService.writeToFile(
depfile,
environment.buildDir.childFile('gen_localizations.d'),
);
......
......@@ -419,11 +419,7 @@ abstract class MacOSBundleFlutterAssets extends Target {
targetPlatform: TargetPlatform.darwin,
shaderTarget: ShaderTarget.sksl,
);
final DepfileService depfileService = DepfileService(
fileSystem: environment.fileSystem,
logger: environment.logger,
);
depfileService.writeToFile(
environment.depFileService.writeToFile(
assetDepfile,
environment.buildDir.childFile('flutter_assets.d'),
);
......
......@@ -218,16 +218,13 @@ class Dart2JSTarget extends Dart2WebTarget {
'${dart2jsDeps.path}');
return;
}
final DepfileService depfileService = DepfileService(
fileSystem: globals.fs,
logger: globals.logger,
);
final Depfile depfile = depfileService.parseDart2js(
final DepfileService depFileService = environment.depFileService;
final Depfile depFile = depFileService.parseDart2js(
environment.buildDir.childFile('app.dill.deps'),
outputJSFile,
);
depfileService.writeToFile(
depfile,
depFileService.writeToFile(
depFile,
environment.buildDir.childFile('dart2js.d'),
);
}
......@@ -409,10 +406,7 @@ class WebReleaseBundle extends Target {
targetPlatform: TargetPlatform.web_javascript,
shaderTarget: ShaderTarget.sksl,
);
final DepfileService depfileService = DepfileService(
fileSystem: globals.fs,
logger: globals.logger,
);
final DepfileService depfileService = environment.depFileService;
depfileService.writeToFile(
depfile,
environment.buildDir.childFile('flutter_assets.d'),
......@@ -627,11 +621,7 @@ class WebServiceWorker extends Target {
);
serviceWorkerFile
.writeAsStringSync(serviceWorker);
final DepfileService depfileService = DepfileService(
fileSystem: globals.fs,
logger: globals.logger,
);
depfileService.writeToFile(
environment.depFileService.writeToFile(
depfile,
environment.buildDir.childFile('service_worker.d'),
);
......
......@@ -88,11 +88,7 @@ class UnpackWindows extends Target {
platform: TargetPlatform.windows_x64
)
);
final DepfileService depfileService = DepfileService(
fileSystem: environment.fileSystem,
logger: environment.logger,
);
depfileService.writeToFile(
environment.depFileService.writeToFile(
depfile,
environment.buildDir.childFile(_kWindowsDepfile),
);
......@@ -145,11 +141,7 @@ abstract class BundleWindowsAssets extends Target {
targetPlatform: TargetPlatform.windows_x64,
shaderTarget: ShaderTarget.sksl,
);
final DepfileService depfileService = DepfileService(
fileSystem: environment.fileSystem,
logger: environment.logger,
);
depfileService.writeToFile(
environment.depFileService.writeToFile(
depfile,
environment.buildDir.childFile('flutter_assets.d'),
);
......
......@@ -90,11 +90,7 @@ class BundleBuilder {
if (!outputDepfile.parent.existsSync()) {
outputDepfile.parent.createSync(recursive: true);
}
final DepfileService depfileService = DepfileService(
fileSystem: globals.fs,
logger: globals.logger,
);
depfileService.writeToFile(depfile, outputDepfile);
environment.depFileService.writeToFile(depfile, outputDepfile);
// Work around for flutter_tester placing kernel artifacts in odd places.
if (applicationKernelFilePath != null) {
......
......@@ -140,7 +140,7 @@ class AssembleCommand extends FlutterCommand {
final FlutterProject flutterProject = FlutterProject.current();
try {
return CustomDimensions(
commandBuildBundleTargetPlatform: environment.defines[kTargetPlatform],
commandBuildBundleTargetPlatform: _environment.defines[kTargetPlatform],
commandBuildBundleIsModule: flutterProject.isModule,
);
} on Exception {
......@@ -151,7 +151,7 @@ class AssembleCommand extends FlutterCommand {
@override
Future<Set<DevelopmentArtifact>> get requiredArtifacts async {
final String? platform = environment.defines[kTargetPlatform];
final String? platform = _environment.defines[kTargetPlatform];
if (platform == null) {
return super.requiredArtifacts;
}
......@@ -204,10 +204,10 @@ class AssembleCommand extends FlutterCommand {
return false;
}
late final Environment environment = createEnvironment();
late final Environment _environment = _createEnvironment();
/// The environmental configuration for a build invocation.
Environment createEnvironment() {
Environment _createEnvironment() {
final FlutterProject flutterProject = FlutterProject.current();
String? output = stringArg('output');
if (output == null) {
......@@ -289,7 +289,7 @@ class AssembleCommand extends FlutterCommand {
Target? target;
List<String> decodedDefines;
try {
decodedDefines = decodeDartDefines(environment.defines, kDartDefines);
decodedDefines = decodeDartDefines(_environment.defines, kDartDefines);
} on FormatException {
throwToolExit(
'Error parsing assemble command: your generated configuration may be out of date. '
......@@ -314,7 +314,7 @@ class AssembleCommand extends FlutterCommand {
final ArgResults argumentResults = argResults!;
final BuildResult result = await _buildSystem.build(
target!,
environment,
_environment,
buildSystemConfig: BuildSystemConfig(
resourcePoolSize: argumentResults.wasParsed('resource-pool-size')
? int.tryParse(stringArg('resource-pool-size')!)
......@@ -346,11 +346,7 @@ class AssembleCommand extends FlutterCommand {
if (argumentResults.wasParsed('depfile')) {
final File depfileFile = globals.fs.file(stringArg('depfile'));
final Depfile depfile = Depfile(result.inputFiles, result.outputFiles);
final DepfileService depfileService = DepfileService(
fileSystem: globals.fs,
logger: globals.logger,
);
depfileService.writeToFile(depfile, globals.fs.file(depfileFile));
_environment.depFileService.writeToFile(depfile, globals.fs.file(depfileFile));
}
return FlutterCommandResult.success();
}
......
......@@ -67,11 +67,7 @@ flutter:
expect(depfile, exists);
final DepfileService depfileService = DepfileService(
logger: BufferLogger.test(),
fileSystem: fileSystem,
);
final Depfile dependencies = depfileService.parse(depfile);
final Depfile dependencies = environment.depFileService.parse(depfile);
expect(
dependencies.inputs.firstWhereOrNull((File file) => file.path == '/bar/LICENSE'),
......
......@@ -39,7 +39,6 @@ void main() {
operatingSystem: 'windows',
environment: <String, String>{},
);
late DepfileService depfileService;
setUp(() {
testbed = Testbed(setup: () {
......@@ -61,10 +60,6 @@ void main() {
logger: globals.logger,
fileSystem: globals.fs,
);
depfileService = DepfileService(
fileSystem: globals.fs,
logger: globals.logger,
);
environment.buildDir.createSync(recursive: true);
}, overrides: <Type, Generator>{
Platform: () => linux,
......@@ -573,7 +568,7 @@ void main() {
await Dart2JSTarget(WebRendererMode.auto).build(environment);
expect(environment.buildDir.childFile('dart2js.d'), exists);
final Depfile depfile = depfileService.parse(environment.buildDir.childFile('dart2js.d'));
final Depfile depfile = environment.depFileService.parse(environment.buildDir.childFile('dart2js.d'));
expect(depfile.inputs.single.path, globals.fs.path.absolute('a.dart'));
expect(depfile.outputs.single.path,
......
......@@ -9,7 +9,6 @@ import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/build_system/depfile.dart';
import 'package:flutter_tools/src/build_system/targets/common.dart';
import 'package:flutter_tools/src/build_system/targets/windows.dart';
import 'package:flutter_tools/src/convert.dart';
......@@ -31,10 +30,6 @@ void main() {
kBuildMode: 'debug',
},
);
final DepfileService depfileService = DepfileService(
logger: BufferLogger.test(),
fileSystem: fileSystem,
);
environment.buildDir.createSync(recursive: true);
final String windowsDesktopPath = artifacts.getArtifactPath(Artifact.windowsDesktopPath, platform: TargetPlatform.windows_x64, mode: BuildMode.debug);
......@@ -83,9 +78,9 @@ void main() {
// Depfile is created correctly.
expect(outputDepfile, exists);
final List<String> inputPaths = depfileService.parse(outputDepfile)
final List<String> inputPaths = environment.depFileService.parse(outputDepfile)
.inputs.map((File file) => file.path).toList();
final List<String> outputPaths = depfileService.parse(outputDepfile)
final List<String> outputPaths = environment.depFileService.parse(outputDepfile)
.outputs.map((File file) => file.path).toList();
// Depfile has expected sources.
......
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