Unverified Commit 51d2d351 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Expose functionality to compile dart to kernel for the VM (#36598)

parent de2a8592
...@@ -99,7 +99,6 @@ class CodeGeneratingKernelCompiler implements KernelCompiler { ...@@ -99,7 +99,6 @@ class CodeGeneratingKernelCompiler implements KernelCompiler {
bool aot = false, bool aot = false,
bool trackWidgetCreation, bool trackWidgetCreation,
List<String> extraFrontEndOptions, List<String> extraFrontEndOptions,
String incrementalCompilerByteStorePath,
bool targetProductVm = false, bool targetProductVm = false,
// These arguments are currently unused. // These arguments are currently unused.
String sdkRoot, String sdkRoot,
...@@ -109,6 +108,7 @@ class CodeGeneratingKernelCompiler implements KernelCompiler { ...@@ -109,6 +108,7 @@ class CodeGeneratingKernelCompiler implements KernelCompiler {
String depFilePath, String depFilePath,
TargetModel targetModel = TargetModel.flutter, TargetModel targetModel = TargetModel.flutter,
String initializeFromDill, String initializeFromDill,
String platformDill,
}) async { }) async {
if (fileSystemRoots != null || fileSystemScheme != null || depFilePath != null || targetModel != null || sdkRoot != null || packagesPath != null) { if (fileSystemRoots != null || fileSystemScheme != null || depFilePath != null || targetModel != null || sdkRoot != null || packagesPath != null) {
printTrace('fileSystemRoots, fileSystemScheme, depFilePath, targetModel,' printTrace('fileSystemRoots, fileSystemScheme, depFilePath, targetModel,'
...@@ -135,7 +135,6 @@ class CodeGeneratingKernelCompiler implements KernelCompiler { ...@@ -135,7 +135,6 @@ class CodeGeneratingKernelCompiler implements KernelCompiler {
aot: aot, aot: aot,
trackWidgetCreation: trackWidgetCreation, trackWidgetCreation: trackWidgetCreation,
extraFrontEndOptions: extraFrontEndOptions, extraFrontEndOptions: extraFrontEndOptions,
incrementalCompilerByteStorePath: incrementalCompilerByteStorePath,
targetProductVm: targetProductVm, targetProductVm: targetProductVm,
sdkRoot: sdkRoot, sdkRoot: sdkRoot,
packagesPath: PackageMap.globalGeneratedPackagesPath, packagesPath: PackageMap.globalGeneratedPackagesPath,
......
...@@ -11,12 +11,10 @@ import 'artifacts.dart'; ...@@ -11,12 +11,10 @@ import 'artifacts.dart';
import 'base/common.dart'; import 'base/common.dart';
import 'base/context.dart'; import 'base/context.dart';
import 'base/file_system.dart'; import 'base/file_system.dart';
import 'base/fingerprint.dart';
import 'base/io.dart'; import 'base/io.dart';
import 'base/platform.dart'; import 'base/platform.dart';
import 'base/process_manager.dart'; import 'base/process_manager.dart';
import 'base/terminal.dart'; import 'base/terminal.dart';
import 'cache.dart';
import 'codegen.dart'; import 'codegen.dart';
import 'convert.dart'; import 'convert.dart';
import 'dart/package_map.dart'; import 'dart/package_map.dart';
...@@ -51,6 +49,8 @@ class TargetModel { ...@@ -51,6 +49,8 @@ class TargetModel {
return flutter; return flutter;
case 'flutter_runner': case 'flutter_runner':
return flutterRunner; return flutterRunner;
case 'vm':
return vm;
} }
assert(false); assert(false);
return null; return null;
...@@ -64,6 +64,9 @@ class TargetModel { ...@@ -64,6 +64,9 @@ class TargetModel {
/// The fuchsia patched SDK. /// The fuchsia patched SDK.
static const TargetModel flutterRunner = TargetModel._('flutter_runner'); static const TargetModel flutterRunner = TargetModel._('flutter_runner');
/// The Dart vm.
static const TargetModel vm = TargetModel._('vm');
final String _value; final String _value;
@override @override
...@@ -218,49 +221,20 @@ class KernelCompiler { ...@@ -218,49 +221,20 @@ class KernelCompiler {
bool aot = false, bool aot = false,
@required bool trackWidgetCreation, @required bool trackWidgetCreation,
List<String> extraFrontEndOptions, List<String> extraFrontEndOptions,
String incrementalCompilerByteStorePath,
String packagesPath, String packagesPath,
List<String> fileSystemRoots, List<String> fileSystemRoots,
String fileSystemScheme, String fileSystemScheme,
bool targetProductVm = false, bool targetProductVm = false,
String initializeFromDill, String initializeFromDill,
String platformDill,
}) async { }) async {
final String frontendServer = artifacts.getArtifactPath( final String frontendServer = artifacts.getArtifactPath(
Artifact.frontendServerSnapshotForEngineDartSdk Artifact.frontendServerSnapshotForEngineDartSdk
); );
FlutterProject flutterProject;
if (fs.file('pubspec.yaml').existsSync()) {
flutterProject = FlutterProject.current();
}
// TODO(cbracken): eliminate pathFilter.
// Currently the compiler emits buildbot paths for the core libs in the
// depfile. None of these are available on the local host.
Fingerprinter fingerprinter;
if (depFilePath != null) {
fingerprinter = Fingerprinter(
fingerprintPath: '$depFilePath.fingerprint',
paths: <String>[mainPath],
properties: <String, String>{
'entryPoint': mainPath,
'trackWidgetCreation': trackWidgetCreation.toString(),
'linkPlatformKernelIn': linkPlatformKernelIn.toString(),
'engineHash': Cache.instance.engineRevision,
'buildersUsed': '${flutterProject != null && flutterProject.hasBuilders}',
},
depfilePaths: <String>[depFilePath],
pathFilter: (String path) => !path.startsWith('/b/build/slave/'),
);
if (await fingerprinter.doesFingerprintMatch()) {
printTrace('Skipping kernel compilation. Fingerprint match.');
return CompilerOutput(outputFilePath, 0, /* sources */ null);
}
}
// This is a URI, not a file path, so the forward slash is correct even on Windows. // This is a URI, not a file path, so the forward slash is correct even on Windows.
if (!sdkRoot.endsWith('/')) if (!sdkRoot.endsWith('/')) {
sdkRoot = '$sdkRoot/'; sdkRoot = '$sdkRoot/';
}
final String engineDartPath = artifacts.getArtifactPath(Artifact.engineDartBinary); final String engineDartPath = artifacts.getArtifactPath(Artifact.engineDartBinary);
if (!processManager.canRun(engineDartPath)) { if (!processManager.canRun(engineDartPath)) {
throwToolExit('Unable to find Dart binary at $engineDartPath'); throwToolExit('Unable to find Dart binary at $engineDartPath');
...@@ -288,9 +262,6 @@ class KernelCompiler { ...@@ -288,9 +262,6 @@ class KernelCompiler {
} else if (aot) { } else if (aot) {
command.add('-Ddart.vm.profile=true'); command.add('-Ddart.vm.profile=true');
} }
if (incrementalCompilerByteStorePath != null) {
command.add('--incremental');
}
Uri mainUri; Uri mainUri;
if (packagesPath != null) { if (packagesPath != null) {
command.addAll(<String>['--packages', packagesPath]); command.addAll(<String>['--packages', packagesPath]);
...@@ -313,6 +284,9 @@ class KernelCompiler { ...@@ -313,6 +284,9 @@ class KernelCompiler {
if (initializeFromDill != null) { if (initializeFromDill != null) {
command.addAll(<String>['--initialize-from-dill', initializeFromDill]); command.addAll(<String>['--initialize-from-dill', initializeFromDill]);
} }
if (platformDill != null) {
command.addAll(<String>[ '--platform', platformDill]);
}
if (extraFrontEndOptions != null) if (extraFrontEndOptions != null)
command.addAll(extraFrontEndOptions); command.addAll(extraFrontEndOptions);
...@@ -337,9 +311,6 @@ class KernelCompiler { ...@@ -337,9 +311,6 @@ class KernelCompiler {
.listen(_stdoutHandler.handler); .listen(_stdoutHandler.handler);
final int exitCode = await server.exitCode; final int exitCode = await server.exitCode;
if (exitCode == 0) { if (exitCode == 0) {
if (fingerprinter != null) {
await fingerprinter.writeFingerprint();
}
return _stdoutHandler.compilerOutput.future; return _stdoutHandler.compilerOutput.future;
} }
return null; return null;
......
...@@ -305,6 +305,7 @@ class FakeKernelCompiler implements KernelCompiler { ...@@ -305,6 +305,7 @@ class FakeKernelCompiler implements KernelCompiler {
List<String> fileSystemRoots, List<String> fileSystemRoots,
String fileSystemScheme, String fileSystemScheme,
bool targetProductVm = false, bool targetProductVm = false,
String platformDill,
String initializeFromDill}) async { String initializeFromDill}) async {
fs.file(outputFilePath).createSync(recursive: true); fs.file(outputFilePath).createSync(recursive: true);
return CompilerOutput(outputFilePath, 0, null); return CompilerOutput(outputFilePath, 0, null);
......
...@@ -505,6 +505,18 @@ example:org-dartlang-app:/ ...@@ -505,6 +505,18 @@ example:org-dartlang-app:/
Platform: _kNoColorTerminalPlatform, Platform: _kNoColorTerminalPlatform,
}); });
}); });
test('TargetModel values', () {
expect(TargetModel('vm'), TargetModel.vm);
expect(TargetModel.vm.toString(), 'vm');
expect(TargetModel('flutter'), TargetModel.flutter);
expect(TargetModel.flutter.toString(), 'flutter');
expect(TargetModel('flutter_runner'), TargetModel.flutterRunner);
expect(TargetModel.flutterRunner.toString(), 'flutter_runner');
expect(() => TargetModel('foobar'), throwsA(isInstanceOf<AssertionError>()));
});
} }
Future<void> _recompile( Future<void> _recompile(
......
...@@ -167,7 +167,6 @@ Hello! ...@@ -167,7 +167,6 @@ Hello!
when(mockKernelCompiler.compile( when(mockKernelCompiler.compile(
sdkRoot: anyNamed('sdkRoot'), sdkRoot: anyNamed('sdkRoot'),
incrementalCompilerByteStorePath: anyNamed('incrementalCompilerByteStorePath'),
mainPath: anyNamed('mainPath'), mainPath: anyNamed('mainPath'),
outputFilePath: anyNamed('outputFilePath'), outputFilePath: anyNamed('outputFilePath'),
depFilePath: anyNamed('depFilePath'), depFilePath: anyNamed('depFilePath'),
......
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