Re-Re-Re-land implement flutter build bundle with assemble (#41302)

This commit is contained in:
Jonah Williams
2019-09-25 13:55:29 -07:00
committed by GitHub
parent d2a95ee344
commit 9bd02a1787
16 changed files with 399 additions and 32 deletions

View File

@@ -235,6 +235,31 @@ void main() {
expect(environment.buildDir.childFile('foo.out').existsSync(), false);
}));
test('Does not crash when filesytem and cache are out of sync', () => testbed.run(() async {
final TestTarget testTarget = TestTarget((Environment environment) async {
environment.buildDir.childFile('foo.out').createSync();
})
..inputs = const <Source>[Source.pattern('{PROJECT_DIR}/foo.dart')]
..outputs = const <Source>[Source.pattern('{BUILD_DIR}/foo.out')];
fs.file('foo.dart').createSync();
await buildSystem.build(testTarget, environment);
expect(environment.buildDir.childFile('foo.out').existsSync(), true);
environment.buildDir.childFile('foo.out').deleteSync();
final TestTarget testTarget2 = TestTarget((Environment environment) async {
environment.buildDir.childFile('bar.out').createSync();
})
..inputs = const <Source>[Source.pattern('{PROJECT_DIR}/foo.dart')]
..outputs = const <Source>[Source.pattern('{BUILD_DIR}/bar.out')];
await buildSystem.build(testTarget2, environment);
expect(environment.buildDir.childFile('bar.out').existsSync(), true);
expect(environment.buildDir.childFile('foo.out').existsSync(), false);
}));
test('reruns build if stamp is corrupted', () => testbed.run(() async {
final TestTarget testTarget = TestTarget((Environment envionment) async {
environment.buildDir.childFile('foo.out').createSync();

View File

@@ -68,4 +68,17 @@ void main() {
expect(fileStorage.files.single.hash, currentHash);
expect(fileStorage.files.single.path, file.resolveSymbolicLinksSync());
}));
test('handles persisting with a missing build directory', () => testbed.run(() {
final File file = fs.file('foo.dart')
..createSync()
..writeAsStringSync('hello');
final FileHashStore fileCache = FileHashStore(environment);
fileCache.initialize();
environment.buildDir.deleteSync(recursive: true);
fileCache.hashFiles(<File>[file]);
// Does not throw.
fileCache.persist();
}));
}

View File

@@ -81,6 +81,7 @@ flutter_tools:lib/''');
fs.path.join('bin', 'cache', 'pkg', 'sky_engine', 'sdk_ext',
'vmservice_io.dart'),
fs.path.join('bin', 'cache', 'dart-sdk', 'bin', 'dart'),
fs.path.join('bin', 'cache', 'dart-sdk', 'bin', 'dart.exe'),
fs.path.join(engineArtifacts, getNameForHostPlatform(hostPlatform),
'frontend_server.dart.snapshot'),
fs.path.join(engineArtifacts, 'android-arm-profile',
@@ -116,6 +117,33 @@ flutter_tools:lib/''');
expect(result.exceptions.values.single.exception, isInstanceOf<MissingDefineException>());
}));
test('kernel_snapshot handles null result from kernel compilation', () => testbed.run(() async {
final FakeKernelCompilerFactory fakeKernelCompilerFactory = kernelCompilerFactory;
fakeKernelCompilerFactory.kernelCompiler = MockKernelCompiler();
when(fakeKernelCompilerFactory.kernelCompiler.compile(
sdkRoot: anyNamed('sdkRoot'),
mainPath: anyNamed('mainPath'),
outputFilePath: anyNamed('outputFilePath'),
depFilePath: anyNamed('depFilePath'),
targetModel: anyNamed('targetModel'),
linkPlatformKernelIn: anyNamed('linkPlatformKernelIn'),
aot: anyNamed('aot'),
trackWidgetCreation: anyNamed('trackWidgetCreation'),
extraFrontEndOptions: anyNamed('extraFrontEndOptions'),
packagesPath: anyNamed('packagesPath'),
fileSystemRoots: anyNamed('fileSystemRoots'),
fileSystemScheme: anyNamed('fileSystemScheme'),
targetProductVm: anyNamed('targetProductVm'),
platformDill: anyNamed('platformDill'),
initializeFromDill: anyNamed('initializeFromDill'),
)).thenAnswer((Invocation invocation) async {
return null;
});
final BuildResult result = await buildSystem.build(const KernelSnapshot(), androidEnvironment);
expect(result.exceptions.values.single.exception, isInstanceOf<Exception>());
}));
test('kernel_snapshot does not use track widget creation on profile builds', () => testbed.run(() async {
final MockKernelCompiler mockKernelCompiler = MockKernelCompiler();
when(kernelCompilerFactory.create(any)).thenAnswer((Invocation _) async {
@@ -342,7 +370,7 @@ class FakeGenSnapshot implements GenSnapshot {
}
class FakeKernelCompilerFactory implements KernelCompilerFactory {
FakeKernelCompiler kernelCompiler = FakeKernelCompiler();
KernelCompiler kernelCompiler = FakeKernelCompiler();
@override
Future<KernelCompiler> create(FlutterProject flutterProject) async {
@@ -362,7 +390,6 @@ class FakeKernelCompiler implements KernelCompiler {
bool aot = false,
bool trackWidgetCreation,
List<String> extraFrontEndOptions,
String incrementalCompilerByteStorePath,
String packagesPath,
List<String> fileSystemRoots,
String fileSystemScheme,

View File

@@ -0,0 +1,67 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/bundle.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:mockito/mockito.dart';
import '../src/common.dart';
import '../src/testbed.dart';
// Tests for the temporary flutter assemble/bundle shim.
void main() {
Testbed testbed;
setUp(() {
testbed = Testbed(overrides: <Type, Generator>{
BuildSystem: () => MockBuildSystem(),
});
});
test('Copies assets to expected directory after building', () => testbed.run(() async {
when(buildSystem.build(any, any)).thenAnswer((Invocation invocation) async {
final Environment environment = invocation.positionalArguments[1];
environment.outputDir.childFile('kernel_blob.bin').createSync(recursive: true);
environment.outputDir.childFile('isolate_snapshot_data').createSync();
environment.outputDir.childFile('vm_snapshot_data').createSync();
environment.outputDir.childFile('LICENSE').createSync(recursive: true);
return BuildResult(success: true);
});
await buildWithAssemble(
buildMode: BuildMode.debug,
flutterProject: FlutterProject.current(),
mainPath: fs.path.join('lib', 'main.dart'),
outputDir: 'example',
targetPlatform: TargetPlatform.ios,
depfilePath: 'example.d',
);
expect(fs.file(fs.path.join('example', 'kernel_blob.bin')).existsSync(), true);
expect(fs.file(fs.path.join('example', 'LICENSE')).existsSync(), true);
expect(fs.file(fs.path.join('example.d')).existsSync(), true);
}));
test('Handles build system failure', () => testbed.run(() {
when(buildSystem.build(any, any)).thenAnswer((Invocation _) async {
return BuildResult(
success: false,
exceptions: <String, ExceptionMeasurement>{},
);
});
expect(() => buildWithAssemble(
buildMode: BuildMode.debug,
flutterProject: FlutterProject.current(),
mainPath: 'lib/main.dart',
outputDir: 'example',
targetPlatform: TargetPlatform.linux_x64,
depfilePath: 'example.d',
), throwsA(isInstanceOf<ToolExit>()));
}));
}
class MockBuildSystem extends Mock implements BuildSystem {}