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