diff --git a/packages/flutter_tools/lib/src/build_system/depfile.dart b/packages/flutter_tools/lib/src/build_system/depfile.dart index 7a5070426d..d59687e8c8 100644 --- a/packages/flutter_tools/lib/src/build_system/depfile.dart +++ b/packages/flutter_tools/lib/src/build_system/depfile.dart @@ -2,22 +2,54 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import '../base/file_system.dart'; -import '../globals.dart' as globals; +import 'package:meta/meta.dart'; +import 'package:platform/platform.dart'; -/// A class for representing depfile formats. -class Depfile { - /// Create a [Depfile] from a list of [input] files and [output] files. - const Depfile(this.inputs, this.outputs); +import '../base/file_system.dart'; +import '../base/logger.dart'; + +/// A service for creating and parsing [Depfile]s. +class DepfileService { + DepfileService({ + @required Logger logger, + @required FileSystem fileSystem, + @required Platform platform, + }) : _logger = logger, + _fileSystem = fileSystem, + _platform = platform; + + final Logger _logger; + final FileSystem _fileSystem; + final Platform _platform; + static final RegExp _separatorExpr = RegExp(r'([^\\]) '); + static final RegExp _escapeExpr = RegExp(r'\\(.)'); + + /// Given an [depfile] File, write the depfile contents. + /// + /// If either [inputs] or [outputs] is empty, ensures the file does not + /// exist. + void writeToFile(Depfile depfile, File output) { + if (depfile.inputs.isEmpty || depfile.outputs.isEmpty) { + if (output.existsSync()) { + output.deleteSync(); + } + return; + } + final StringBuffer buffer = StringBuffer(); + _writeFilesToBuffer(depfile.outputs, buffer); + buffer.write(': '); + _writeFilesToBuffer(depfile.inputs, buffer); + output.writeAsStringSync(buffer.toString()); + } /// Parse the depfile contents from [file]. /// /// If the syntax is invalid, returns an empty [Depfile]. - factory Depfile.parse(File file) { + Depfile parse(File file) { final String contents = file.readAsStringSync(); final List colonSeparated = contents.split(': '); if (colonSeparated.length != 2) { - globals.printError('Invalid depfile: ${file.path}'); + _logger.printError('Invalid depfile: ${file.path}'); return const Depfile([], []); } final List inputs = _processList(colonSeparated[1].trim()); @@ -25,11 +57,12 @@ class Depfile { return Depfile(inputs, outputs); } + /// Parse the output of dart2js's used dependencies. /// /// The [file] contains a list of newline separated file URIs. The output /// file must be manually specified. - factory Depfile.parseDart2js(File file, File output) { + Depfile parseDart2js(File file, File output) { final List inputs = []; for (final String rawUri in file.readAsLinesSync()) { if (rawUri.trim().isEmpty) { @@ -42,38 +75,14 @@ class Depfile { if (fileUri.scheme != 'file') { continue; } - inputs.add(globals.fs.file(fileUri)); + inputs.add(_fileSystem.file(fileUri)); } return Depfile(inputs, [output]); } - /// The input files for this depfile. - final List inputs; - - /// The output files for this depfile. - final List outputs; - - /// Given an [depfile] File, write the depfile contents. - /// - /// If either [inputs] or [outputs] is empty, ensures the file does not - /// exist. - void writeToFile(File depfile) { - if (inputs.isEmpty || outputs.isEmpty) { - if (depfile.existsSync()) { - depfile.deleteSync(); - } - return; - } - final StringBuffer buffer = StringBuffer(); - _writeFilesToBuffer(outputs, buffer); - buffer.write(': '); - _writeFilesToBuffer(inputs, buffer); - depfile.writeAsStringSync(buffer.toString()); - } - void _writeFilesToBuffer(List files, StringBuffer buffer) { for (final File outputFile in files) { - if (globals.platform.isWindows) { + if (_platform.isWindows) { // Foward slashes and spaces in a depfile have to be escaped on windows. final String path = outputFile.path .replaceAll(r'\', r'\\') @@ -87,10 +96,7 @@ class Depfile { } } - static final RegExp _separatorExpr = RegExp(r'([^\\]) '); - static final RegExp _escapeExpr = RegExp(r'\\(.)'); - - static List _processList(String rawText) { + List _processList(String rawText) { return rawText // Put every file on right-hand side on the separate line .replaceAllMapped(_separatorExpr, (Match match) => '${match.group(1)}\n') @@ -101,7 +107,19 @@ class Depfile { // The tool doesn't write duplicates to these lists. This call is an attempt to // be resillient to the outputs of other tools which write or user edits to depfiles. .toSet() - .map((String path) => globals.fs.file(path)) + .map(_fileSystem.file) .toList(); } } + +/// A class for representing depfile formats. +class Depfile { + /// Create a [Depfile] from a list of [input] files and [output] files. + const Depfile(this.inputs, this.outputs); + + /// The input files for this depfile. + final List inputs; + + /// The output files for this depfile. + final List outputs; +} diff --git a/packages/flutter_tools/lib/src/build_system/targets/android.dart b/packages/flutter_tools/lib/src/build_system/targets/android.dart index f7a8405cb2..5d28b2897b 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/android.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/android.dart @@ -63,7 +63,15 @@ abstract class AndroidAssetBundle extends Target { } if (_copyAssets) { final Depfile assetDepfile = await copyAssets(environment, outputDirectory); - assetDepfile.writeToFile(environment.buildDir.childFile('flutter_assets.d')); + final DepfileService depfileService = DepfileService( + fileSystem: globals.fs, + logger: globals.logger, + platform: globals.platform, + ); + depfileService.writeToFile( + assetDepfile, + environment.buildDir.childFile('flutter_assets.d'), + ); } } diff --git a/packages/flutter_tools/lib/src/build_system/targets/assets.dart b/packages/flutter_tools/lib/src/build_system/targets/assets.dart index 670065876c..ade1722d27 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/assets.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/assets.dart @@ -108,7 +108,15 @@ class CopyAssets extends Target { .childDirectory('flutter_assets'); output.createSync(recursive: true); final Depfile depfile = await copyAssets(environment, output); - depfile.writeToFile(environment.buildDir.childFile('flutter_assets.d')); + final DepfileService depfileService = DepfileService( + fileSystem: globals.fs, + logger: globals.logger, + platform: globals.platform, + ); + depfileService.writeToFile( + depfile, + environment.buildDir.childFile('flutter_assets.d'), + ); } } diff --git a/packages/flutter_tools/lib/src/build_system/targets/dart.dart b/packages/flutter_tools/lib/src/build_system/targets/dart.dart index 9a03afb959..9e7143aee2 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/dart.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/dart.dart @@ -114,7 +114,15 @@ class CopyFlutterBundle extends Target { .copySync(environment.outputDir.childFile('isolate_snapshot_data').path); } final Depfile assetDepfile = await copyAssets(environment, environment.outputDir); - assetDepfile.writeToFile(environment.buildDir.childFile('flutter_assets.d')); + final DepfileService depfileService = DepfileService( + fileSystem: globals.fs, + logger: globals.logger, + platform: globals.platform, + ); + depfileService.writeToFile( + assetDepfile, + environment.buildDir.childFile('flutter_assets.d'), + ); } @override diff --git a/packages/flutter_tools/lib/src/build_system/targets/ios.dart b/packages/flutter_tools/lib/src/build_system/targets/ios.dart index 88204c2f13..668424e6e5 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/ios.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/ios.dart @@ -284,7 +284,15 @@ abstract class IosAssetBundle extends Target { // Copy the assets. final Depfile assetDepfile = await copyAssets(environment, assetDirectory); - assetDepfile.writeToFile(environment.buildDir.childFile('flutter_assets.d')); + final DepfileService depfileService = DepfileService( + fileSystem: globals.fs, + logger: globals.logger, + platform: globals.platform, + ); + depfileService.writeToFile( + assetDepfile, + environment.buildDir.childFile('flutter_assets.d'), + ); // Copy the plist from either the project or module. diff --git a/packages/flutter_tools/lib/src/build_system/targets/linux.dart b/packages/flutter_tools/lib/src/build_system/targets/linux.dart index 5f61e37778..b106fae379 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/linux.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/linux.dart @@ -98,7 +98,15 @@ class UnpackLinuxDebug extends Target { } } final Depfile depfile = Depfile(inputs, outputs); - depfile.writeToFile(environment.buildDir.childFile('linux_engine_sources.d')); + final DepfileService depfileService = DepfileService( + fileSystem: globals.fs, + logger: globals.logger, + platform: globals.platform, + ); + depfileService.writeToFile( + depfile, + environment.buildDir.childFile('linux_engine_sources.d'), + ); } } @@ -151,6 +159,14 @@ class DebugBundleLinuxAssets extends Target { .copySync(outputDirectory.childFile('kernel_blob.bin').path); } final Depfile depfile = await copyAssets(environment, outputDirectory); - depfile.writeToFile(environment.buildDir.childFile('flutter_assets.d')); + final DepfileService depfileService = DepfileService( + fileSystem: globals.fs, + logger: globals.logger, + platform: globals.platform, + ); + depfileService.writeToFile( + depfile, + environment.buildDir.childFile('flutter_assets.d'), + ); } } diff --git a/packages/flutter_tools/lib/src/build_system/targets/macos.dart b/packages/flutter_tools/lib/src/build_system/targets/macos.dart index 73685123e3..a59cdba091 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/macos.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/macos.dart @@ -286,7 +286,15 @@ abstract class MacOSBundleFlutterAssets extends Target { .childDirectory('flutter_assets'); assetDirectory.createSync(recursive: true); final Depfile depfile = await copyAssets(environment, assetDirectory); - depfile.writeToFile(environment.buildDir.childFile('flutter_assets.d')); + final DepfileService depfileService = DepfileService( + fileSystem: globals.fs, + logger: globals.logger, + platform: globals.platform, + ); + depfileService.writeToFile( + depfile, + environment.buildDir.childFile('flutter_assets.d'), + ); // Copy Info.plist template. assetDirectory.parent.childFile('Info.plist') diff --git a/packages/flutter_tools/lib/src/build_system/targets/web.dart b/packages/flutter_tools/lib/src/build_system/targets/web.dart index 9c1738de0a..05a7bc73fc 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/web.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/web.dart @@ -191,11 +191,19 @@ class Dart2JSTarget extends Target { '${dart2jsDeps.path}'); return; } - final Depfile depfile = Depfile.parseDart2js( + final DepfileService depfileService = DepfileService( + fileSystem: globals.fs, + logger: globals.logger, + platform: globals.platform, + ); + final Depfile depfile = depfileService.parseDart2js( environment.buildDir.childFile('main.dart.js.deps'), outputFile, ); - depfile.writeToFile(environment.buildDir.childFile('dart2js.d')); + depfileService.writeToFile( + depfile, + environment.buildDir.childFile('dart2js.d'), + ); } } @@ -247,7 +255,15 @@ class WebReleaseBundle extends Target { final Directory outputDirectory = environment.outputDir.childDirectory('assets'); outputDirectory.createSync(recursive: true); final Depfile depfile = await copyAssets(environment, environment.outputDir.childDirectory('assets')); - depfile.writeToFile(environment.buildDir.childFile('flutter_assets.d')); + final DepfileService depfileService = DepfileService( + fileSystem: globals.fs, + logger: globals.logger, + platform: globals.platform, + ); + depfileService.writeToFile( + depfile, + environment.buildDir.childFile('flutter_assets.d'), + ); final Directory webResources = environment.projectDir .childDirectory('web'); @@ -269,8 +285,10 @@ class WebReleaseBundle extends Target { outputResourcesFiles.add(outputFile); } final Depfile resourceFile = Depfile(inputResourceFiles, outputResourcesFiles); - resourceFile.writeToFile(environment.buildDir.childFile('web_resources.d')); - + depfileService.writeToFile( + resourceFile, + environment.buildDir.childFile('web_resources.d'), + ); } } @@ -320,7 +338,15 @@ class WebServiceWorker extends Target { final String serviceWorker = generateServiceWorker(uriToHash); serviceWorkerFile .writeAsStringSync(serviceWorker); - depfile.writeToFile(environment.buildDir.childFile('service_worker.d')); + final DepfileService depfileService = DepfileService( + fileSystem: globals.fs, + logger: globals.logger, + platform: globals.platform, + ); + depfileService.writeToFile( + depfile, + environment.buildDir.childFile('service_worker.d'), + ); } } diff --git a/packages/flutter_tools/lib/src/bundle.dart b/packages/flutter_tools/lib/src/bundle.dart index de0a04060c..d0e7d99611 100644 --- a/packages/flutter_tools/lib/src/bundle.dart +++ b/packages/flutter_tools/lib/src/bundle.dart @@ -149,7 +149,12 @@ Future buildWithAssemble({ if (!outputDepfile.parent.existsSync()) { outputDepfile.parent.createSync(recursive: true); } - depfile.writeToFile(outputDepfile); + final DepfileService depfileService = DepfileService( + fileSystem: globals.fs, + logger: globals.logger, + platform: globals.platform, + ); + depfileService.writeToFile(depfile, outputDepfile); } } diff --git a/packages/flutter_tools/lib/src/commands/assemble.dart b/packages/flutter_tools/lib/src/commands/assemble.dart index 6a8ca21a5d..4dac90e60b 100644 --- a/packages/flutter_tools/lib/src/commands/assemble.dart +++ b/packages/flutter_tools/lib/src/commands/assemble.dart @@ -202,7 +202,12 @@ class AssembleCommand extends FlutterCommand { if (argResults.wasParsed('depfile')) { final File depfileFile = globals.fs.file(stringArg('depfile')); final Depfile depfile = Depfile(result.inputFiles, result.outputFiles); - depfile.writeToFile(globals.fs.file(depfileFile)); + final DepfileService depfileService = DepfileService( + fileSystem: globals.fs, + logger: globals.logger, + platform: globals.platform, + ); + depfileService.writeToFile(depfile, globals.fs.file(depfileFile)); } return FlutterCommandResult.success(); } diff --git a/packages/flutter_tools/test/general.shard/build_system/depfile_test.dart b/packages/flutter_tools/test/general.shard/build_system/depfile_test.dart index 1f31c4a4a3..d39013eb42 100644 --- a/packages/flutter_tools/test/general.shard/build_system/depfile_test.dart +++ b/packages/flutter_tools/test/general.shard/build_system/depfile_test.dart @@ -4,34 +4,40 @@ import 'package:file/memory.dart'; import 'package:flutter_tools/src/base/file_system.dart'; +import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/build_system/depfile.dart'; -import 'package:flutter_tools/src/globals.dart' as globals; +import 'package:mockito/mockito.dart'; import 'package:platform/platform.dart'; import '../../src/common.dart'; -import '../../src/testbed.dart'; void main() { - Testbed testbed; + FileSystem fileSystem; + DepfileService depfileService; setUp(() { - testbed = Testbed(); + fileSystem = MemoryFileSystem.test(); + depfileService = DepfileService( + logger: MockLogger(), + fileSystem: fileSystem, + platform: FakePlatform(operatingSystem: 'linux'), + ); }); - test('Can parse depfile from file', () => testbed.run(() { - final File depfileSource = globals.fs.file('example.d')..writeAsStringSync(''' + testWithoutContext('Can parse depfile from file', () { + final File depfileSource = fileSystem.file('example.d')..writeAsStringSync(''' a.txt: b.txt '''); - final Depfile depfile = Depfile.parse(depfileSource); + final Depfile depfile = depfileService.parse(depfileSource); expect(depfile.inputs.single.path, 'b.txt'); expect(depfile.outputs.single.path, 'a.txt'); - })); + }); - test('Can parse depfile with multiple inputs', () => testbed.run(() { - final File depfileSource = globals.fs.file('example.d')..writeAsStringSync(''' + testWithoutContext('Can parse depfile with multiple inputs', () { + final File depfileSource = fileSystem.file('example.d')..writeAsStringSync(''' a.txt: b.txt c.txt d.txt '''); - final Depfile depfile = Depfile.parse(depfileSource); + final Depfile depfile = depfileService.parse(depfileSource); expect(depfile.inputs.map((File file) => file.path), [ 'b.txt', @@ -39,13 +45,13 @@ a.txt: b.txt c.txt d.txt 'd.txt', ]); expect(depfile.outputs.single.path, 'a.txt'); - })); + }); - test('Can parse depfile with multiple outputs', () => testbed.run(() { - final File depfileSource = globals.fs.file('example.d')..writeAsStringSync(''' + testWithoutContext('Can parse depfile with multiple outputs', () { + final File depfileSource = fileSystem.file('example.d')..writeAsStringSync(''' a.txt c.txt d.txt: b.txt '''); - final Depfile depfile = Depfile.parse(depfileSource); + final Depfile depfile = depfileService.parse(depfileSource); expect(depfile.inputs.single.path, 'b.txt'); expect(depfile.outputs.map((File file) => file.path), [ @@ -53,120 +59,122 @@ a.txt c.txt d.txt: b.txt 'c.txt', 'd.txt', ]); - })); + }); - test('Can parse depfile with windows file paths', () => testbed.run(() { - final File depfileSource = globals.fs.file('example.d')..writeAsStringSync(r''' + testWithoutContext('Can parse depfile with windows file paths', () { + fileSystem = MemoryFileSystem.test(style: FileSystemStyle.windows); + depfileService = DepfileService( + logger: MockLogger(), + fileSystem: fileSystem, + platform: FakePlatform(operatingSystem: 'windows'), + ); + final File depfileSource = fileSystem.file('example.d')..writeAsStringSync(r''' C:\\a.txt: C:\\b.txt '''); - final Depfile depfile = Depfile.parse(depfileSource); + final Depfile depfile = depfileService.parse(depfileSource); expect(depfile.inputs.single.path, r'C:\b.txt'); expect(depfile.outputs.single.path, r'C:\a.txt'); - }, overrides: { - FileSystem: () => MemoryFileSystem(style: FileSystemStyle.windows), - })); + }); - test('Can escape depfile with windows file paths and spaces in directory names', () => testbed.run(() { - final File inputFile = globals.fs.directory(r'Hello Flutter').childFile('a.txt').absolute + testWithoutContext('Can escape depfile with windows file paths and spaces in directory names', () { + fileSystem = MemoryFileSystem.test(style: FileSystemStyle.windows); + depfileService = DepfileService( + logger: MockLogger(), + fileSystem: fileSystem, + platform: FakePlatform(operatingSystem: 'windows'), + ); + final File inputFile = fileSystem.directory(r'Hello Flutter').childFile('a.txt').absolute ..createSync(recursive: true); - final File outputFile = globals.fs.directory(r'Hello Flutter').childFile('b.txt').absolute + final File outputFile = fileSystem.directory(r'Hello Flutter').childFile('b.txt').absolute ..createSync(); final Depfile depfile = Depfile([inputFile], [outputFile]); - final File outputDepfile = globals.fs.file('depfile'); - depfile.writeToFile(outputDepfile); + final File outputDepfile = fileSystem.file('depfile'); + depfileService.writeToFile(depfile, outputDepfile); expect(outputDepfile.readAsStringSync(), contains(r'C:\\Hello\ Flutter\\a.txt')); expect(outputDepfile.readAsStringSync(), contains(r'C:\\Hello\ Flutter\\b.txt')); - }, overrides: { - FileSystem: () => MemoryFileSystem(style: FileSystemStyle.windows), - Platform: () => FakePlatform(operatingSystem: 'windows'), - })); + }); - test('Can escape depfile with spaces in directory names', () => testbed.run(() { - final File inputFile = globals.fs.directory(r'Hello Flutter').childFile('a.txt').absolute + testWithoutContext('Can escape depfile with spaces in directory names', () { + final File inputFile = fileSystem.directory(r'Hello Flutter').childFile('a.txt').absolute ..createSync(recursive: true); - final File outputFile = globals.fs.directory(r'Hello Flutter').childFile('b.txt').absolute + final File outputFile = fileSystem.directory(r'Hello Flutter').childFile('b.txt').absolute ..createSync(); final Depfile depfile = Depfile([inputFile], [outputFile]); - final File outputDepfile = globals.fs.file('depfile'); - depfile.writeToFile(outputDepfile); + final File outputDepfile = fileSystem.file('depfile'); + depfileService.writeToFile(depfile, outputDepfile); expect(outputDepfile.readAsStringSync(), contains(r'/Hello\ Flutter/a.txt')); expect(outputDepfile.readAsStringSync(), contains(r'/Hello\ Flutter/b.txt')); - }, overrides: { - FileSystem: () => MemoryFileSystem(style: FileSystemStyle.posix), - Platform: () => FakePlatform(operatingSystem: 'linux'), - })); + }); - test('Resillient to weird whitespace', () => testbed.run(() { - final File depfileSource = globals.fs.file('example.d')..writeAsStringSync(r''' + testWithoutContext('Resillient to weird whitespace', () { + final File depfileSource = fileSystem.file('example.d')..writeAsStringSync(r''' a.txt : b.txt c.txt '''); - final Depfile depfile = Depfile.parse(depfileSource); + final Depfile depfile = depfileService.parse(depfileSource); expect(depfile.inputs, hasLength(2)); expect(depfile.outputs.single.path, 'a.txt'); - })); + }); - test('Resillient to duplicate files', () => testbed.run(() { - final File depfileSource = globals.fs.file('example.d')..writeAsStringSync(r''' + testWithoutContext('Resillient to duplicate files', () { + final File depfileSource = fileSystem.file('example.d')..writeAsStringSync(r''' a.txt: b.txt b.txt '''); - final Depfile depfile = Depfile.parse(depfileSource); + final Depfile depfile = depfileService.parse(depfileSource); expect(depfile.inputs.single.path, 'b.txt'); expect(depfile.outputs.single.path, 'a.txt'); - })); + }); - test('Resillient to malformed file, missing :', () => testbed.run(() { - final File depfileSource = globals.fs.file('example.d')..writeAsStringSync(r''' + testWithoutContext('Resillient to malformed file, missing :', () { + final File depfileSource = fileSystem.file('example.d')..writeAsStringSync(r''' a.text b.txt '''); - final Depfile depfile = Depfile.parse(depfileSource); + final Depfile depfile = depfileService.parse(depfileSource); expect(depfile.inputs, isEmpty); expect(depfile.outputs, isEmpty); - })); + }); - test('Can parse dart2js output format', () => testbed.run(() { - final File dart2jsDependencyFile = globals.fs.file('main.dart.js.deps')..writeAsStringSync(r''' + testWithoutContext('Can parse dart2js output format', () { + final File dart2jsDependencyFile = fileSystem.file('main.dart.js.deps')..writeAsStringSync(r''' file:///Users/foo/collection.dart file:///Users/foo/algorithms.dart file:///Users/foo/canonicalized_map.dart '''); - final Depfile depfile = Depfile.parseDart2js(dart2jsDependencyFile, globals.fs.file('foo.dart.js')); + final Depfile depfile = depfileService.parseDart2js(dart2jsDependencyFile, fileSystem.file('foo.dart.js')); expect(depfile.inputs.map((File file) => file.path), [ - globals.fs.path.absolute(globals.fs.path.join('Users', 'foo', 'collection.dart')), - globals.fs.path.absolute(globals.fs.path.join('Users', 'foo', 'algorithms.dart')), - globals.fs.path.absolute(globals.fs.path.join('Users', 'foo', 'canonicalized_map.dart')), + fileSystem.path.absolute(fileSystem.path.join('Users', 'foo', 'collection.dart')), + fileSystem.path.absolute(fileSystem.path.join('Users', 'foo', 'algorithms.dart')), + fileSystem.path.absolute(fileSystem.path.join('Users', 'foo', 'canonicalized_map.dart')), ]); expect(depfile.outputs.single.path, 'foo.dart.js'); - }, overrides: { - FileSystem: () => MemoryFileSystem(style: FileSystemStyle.posix) - })); + }); - test('Can parse handle invalid uri', () => testbed.run(() { - final File dart2jsDependencyFile = globals.fs.file('main.dart.js.deps')..writeAsStringSync(''' + testWithoutContext('Can parse handle invalid uri', () { + final File dart2jsDependencyFile = fileSystem.file('main.dart.js.deps')..writeAsStringSync(''' file:///Users/foo/collection.dart abcdevf file:///Users/foo/canonicalized_map.dart '''); - final Depfile depfile = Depfile.parseDart2js(dart2jsDependencyFile, globals.fs.file('foo.dart.js')); + final Depfile depfile = depfileService.parseDart2js(dart2jsDependencyFile, fileSystem.file('foo.dart.js')); expect(depfile.inputs.map((File file) => file.path), [ - globals.fs.path.absolute(globals.fs.path.join('Users', 'foo', 'collection.dart')), - globals.fs.path.absolute(globals.fs.path.join('Users', 'foo', 'canonicalized_map.dart')), + fileSystem.path.absolute(fileSystem.path.join('Users', 'foo', 'collection.dart')), + fileSystem.path.absolute(fileSystem.path.join('Users', 'foo', 'canonicalized_map.dart')), ]); expect(depfile.outputs.single.path, 'foo.dart.js'); - }, overrides: { - FileSystem: () => MemoryFileSystem(style: FileSystemStyle.posix) - })); + }); } + +class MockLogger extends Mock implements Logger {} \ No newline at end of file diff --git a/packages/flutter_tools/test/general.shard/build_system/targets/web_test.dart b/packages/flutter_tools/test/general.shard/build_system/targets/web_test.dart index f1d2d3ab85..e7cc0e05c0 100644 --- a/packages/flutter_tools/test/general.shard/build_system/targets/web_test.dart +++ b/packages/flutter_tools/test/general.shard/build_system/targets/web_test.dart @@ -24,6 +24,7 @@ void main() { Environment environment; MockPlatform mockPlatform; MockPlatform mockWindowsPlatform; + DepfileService depfileService; setUp(() { mockPlatform = MockPlatform(); @@ -53,6 +54,11 @@ void main() { kTargetFile: globals.fs.path.join('foo', 'lib', 'main.dart'), } ); + depfileService = DepfileService( + fileSystem: globals.fs, + logger: globals.logger, + platform: globals.platform, + ); environment.buildDir.createSync(recursive: true); }, overrides: { Platform: () => mockPlatform, @@ -315,7 +321,7 @@ void main() { await const Dart2JSTarget().build(environment); expect(environment.buildDir.childFile('dart2js.d').existsSync(), true); - final Depfile depfile = Depfile.parse(environment.buildDir.childFile('dart2js.d')); + final Depfile depfile = depfileService.parse(environment.buildDir.childFile('dart2js.d')); expect(depfile.inputs.single.path, globals.fs.path.absolute('a.dart')); expect(depfile.outputs.single.path,