switch dart2js build to depfile, remove Source.function (#42977)
This commit is contained in:
@@ -114,7 +114,7 @@ void main() {
|
||||
expect(buildResult.hasException, false);
|
||||
}));
|
||||
|
||||
test('Throws exception if it does not produce a specified output', () => testbed.run(() async {
|
||||
test('Does not throw exception if it does not produce a specified output', () => testbed.run(() async {
|
||||
final Target badTarget = TestTarget((Environment environment) async {})
|
||||
..inputs = const <Source>[
|
||||
Source.pattern('{PROJECT_DIR}/foo.dart'),
|
||||
@@ -124,8 +124,7 @@ void main() {
|
||||
];
|
||||
final BuildResult result = await buildSystem.build(badTarget, environment);
|
||||
|
||||
expect(result.hasException, true);
|
||||
expect(result.exceptions.values.single.exception, isInstanceOf<FileSystemException>());
|
||||
expect(result.hasException, false);
|
||||
}));
|
||||
|
||||
test('Saves a stamp file with inputs and outputs', () => testbed.run(() async {
|
||||
|
||||
@@ -26,7 +26,6 @@ a.txt: b.txt
|
||||
}));
|
||||
|
||||
test('Can parse depfile with multiple inputs', () => testbed.run(() {
|
||||
final FileSystem fs = MemoryFileSystem();
|
||||
final File depfileSource = fs.file('example.d')..writeAsStringSync('''
|
||||
a.txt: b.txt c.txt d.txt
|
||||
''');
|
||||
@@ -41,7 +40,6 @@ a.txt: b.txt c.txt d.txt
|
||||
}));
|
||||
|
||||
test('Can parse depfile with multiple outputs', () => testbed.run(() {
|
||||
final FileSystem fs = MemoryFileSystem();
|
||||
final File depfileSource = fs.file('example.d')..writeAsStringSync('''
|
||||
a.txt c.txt d.txt: b.txt
|
||||
''');
|
||||
@@ -56,7 +54,6 @@ a.txt c.txt d.txt: b.txt
|
||||
}));
|
||||
|
||||
test('Can parse depfile with windows file paths', () => testbed.run(() {
|
||||
final FileSystem fs = MemoryFileSystem();
|
||||
final File depfileSource = fs.file('example.d')..writeAsStringSync(r'''
|
||||
C:\\a.txt: C:\\b.txt
|
||||
''');
|
||||
@@ -69,7 +66,6 @@ C:\\a.txt: C:\\b.txt
|
||||
}));
|
||||
|
||||
test('Resillient to weird whitespace', () => testbed.run(() {
|
||||
final FileSystem fs = MemoryFileSystem();
|
||||
final File depfileSource = fs.file('example.d')..writeAsStringSync(r'''
|
||||
a.txt
|
||||
: b.txt c.txt
|
||||
@@ -83,7 +79,6 @@ a.txt
|
||||
}));
|
||||
|
||||
test('Resillient to duplicate files', () => testbed.run(() {
|
||||
final FileSystem fs = MemoryFileSystem();
|
||||
final File depfileSource = fs.file('example.d')..writeAsStringSync(r'''
|
||||
a.txt: b.txt b.txt
|
||||
''');
|
||||
@@ -94,7 +89,6 @@ a.txt: b.txt b.txt
|
||||
}));
|
||||
|
||||
test('Resillient to malformed file, missing :', () => testbed.run(() {
|
||||
final FileSystem fs = MemoryFileSystem();
|
||||
final File depfileSource = fs.file('example.d')..writeAsStringSync(r'''
|
||||
a.text b.txt
|
||||
''');
|
||||
@@ -103,4 +97,42 @@ a.text b.txt
|
||||
expect(depfile.inputs, isEmpty);
|
||||
expect(depfile.outputs, isEmpty);
|
||||
}));
|
||||
|
||||
test('Can parse dart2js output format', () => testbed.run(() {
|
||||
final File dart2jsDependencyFile = fs.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, fs.file('foo.dart.js'));
|
||||
|
||||
expect(depfile.inputs.map((File file) => file.path), <String>[
|
||||
fs.path.absolute(fs.path.join('Users', 'foo', 'collection.dart')),
|
||||
fs.path.absolute(fs.path.join('Users', 'foo', 'algorithms.dart')),
|
||||
fs.path.absolute(fs.path.join('Users', 'foo', 'canonicalized_map.dart')),
|
||||
]);
|
||||
expect(depfile.outputs.single.path, 'foo.dart.js');
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => MemoryFileSystem(style: FileSystemStyle.posix)
|
||||
}));
|
||||
|
||||
test('Can parse handle invalid uri', () => testbed.run(() {
|
||||
final File dart2jsDependencyFile = fs.file('main.dart.js.deps')..writeAsStringSync('''
|
||||
file:///Users/foo/collection.dart
|
||||
abcdevf
|
||||
file:///Users/foo/canonicalized_map.dart
|
||||
''');
|
||||
|
||||
final Depfile depfile = Depfile.parseDart2js(dart2jsDependencyFile, fs.file('foo.dart.js'));
|
||||
|
||||
expect(depfile.inputs.map((File file) => file.path), <String>[
|
||||
fs.path.absolute(fs.path.join('Users', 'foo', 'collection.dart')),
|
||||
fs.path.absolute(fs.path.join('Users', 'foo', 'canonicalized_map.dart')),
|
||||
]);
|
||||
expect(depfile.outputs.single.path, 'foo.dart.js');
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => MemoryFileSystem(style: FileSystemStyle.posix)
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -81,4 +81,15 @@ void main() {
|
||||
// Does not throw.
|
||||
fileCache.persist();
|
||||
}));
|
||||
|
||||
test('handles hashing missing files', () => testbed.run(() async {
|
||||
final FileHashStore fileCache = FileHashStore(environment);
|
||||
fileCache.initialize();
|
||||
|
||||
final List<File> results = await fileCache.hashFiles(<File>[fs.file('hello.dart')]);
|
||||
|
||||
expect(results, hasLength(1));
|
||||
expect(results.single.path, 'hello.dart');
|
||||
expect(fileCache.currentHashes, isNot(contains(fs.path.absolute('hello.dart'))));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ void main() {
|
||||
test('configures implicit vs explict correctly', () => testbed.run(() {
|
||||
expect(const Source.pattern('{PROJECT_DIR}/foo').implicit, false);
|
||||
expect(const Source.pattern('{PROJECT_DIR}/*foo').implicit, true);
|
||||
expect(Source.function((Environment environment) => <File>[]).implicit, true);
|
||||
expect(Source.behavior(TestBehavior()).implicit, true);
|
||||
}));
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/base/process_manager.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/dart.dart';
|
||||
import 'package:flutter_tools/src/build_system/targets/web.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
@@ -215,6 +216,25 @@ void main() {
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => MockProcessManager(),
|
||||
}));
|
||||
|
||||
test('Dart2JSTarget produces expected depfile', () => testbed.run(() async {
|
||||
environment.defines[kBuildMode] = 'release';
|
||||
when(processManager.run(any)).thenAnswer((Invocation invocation) async {
|
||||
environment.buildDir.childFile('main.dart.js.deps')
|
||||
..writeAsStringSync('file:///a.dart');
|
||||
return FakeProcessResult(exitCode: 0);
|
||||
});
|
||||
await const Dart2JSTarget().build(environment);
|
||||
|
||||
expect(environment.buildDir.childFile('dart2js.d').existsSync(), true);
|
||||
final Depfile depfile = Depfile.parse(environment.buildDir.childFile('dart2js.d'));
|
||||
|
||||
expect(depfile.inputs.single.path, fs.path.absolute('a.dart'));
|
||||
expect(depfile.outputs.single.path,
|
||||
environment.buildDir.childFile('main.dart.js').absolute.path);
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => MockProcessManager(),
|
||||
}));
|
||||
}
|
||||
|
||||
class MockProcessManager extends Mock implements ProcessManager {}
|
||||
|
||||
Reference in New Issue
Block a user