Expose functionality to compile dart to kernel for the VM (#36598)
This commit is contained in:
@@ -99,7 +99,6 @@ class CodeGeneratingKernelCompiler implements KernelCompiler {
|
||||
bool aot = false,
|
||||
bool trackWidgetCreation,
|
||||
List<String> extraFrontEndOptions,
|
||||
String incrementalCompilerByteStorePath,
|
||||
bool targetProductVm = false,
|
||||
// These arguments are currently unused.
|
||||
String sdkRoot,
|
||||
@@ -109,6 +108,7 @@ class CodeGeneratingKernelCompiler implements KernelCompiler {
|
||||
String depFilePath,
|
||||
TargetModel targetModel = TargetModel.flutter,
|
||||
String initializeFromDill,
|
||||
String platformDill,
|
||||
}) async {
|
||||
if (fileSystemRoots != null || fileSystemScheme != null || depFilePath != null || targetModel != null || sdkRoot != null || packagesPath != null) {
|
||||
printTrace('fileSystemRoots, fileSystemScheme, depFilePath, targetModel,'
|
||||
@@ -135,7 +135,6 @@ class CodeGeneratingKernelCompiler implements KernelCompiler {
|
||||
aot: aot,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
extraFrontEndOptions: extraFrontEndOptions,
|
||||
incrementalCompilerByteStorePath: incrementalCompilerByteStorePath,
|
||||
targetProductVm: targetProductVm,
|
||||
sdkRoot: sdkRoot,
|
||||
packagesPath: PackageMap.globalGeneratedPackagesPath,
|
||||
|
||||
@@ -11,12 +11,10 @@ import 'artifacts.dart';
|
||||
import 'base/common.dart';
|
||||
import 'base/context.dart';
|
||||
import 'base/file_system.dart';
|
||||
import 'base/fingerprint.dart';
|
||||
import 'base/io.dart';
|
||||
import 'base/platform.dart';
|
||||
import 'base/process_manager.dart';
|
||||
import 'base/terminal.dart';
|
||||
import 'cache.dart';
|
||||
import 'codegen.dart';
|
||||
import 'convert.dart';
|
||||
import 'dart/package_map.dart';
|
||||
@@ -51,6 +49,8 @@ class TargetModel {
|
||||
return flutter;
|
||||
case 'flutter_runner':
|
||||
return flutterRunner;
|
||||
case 'vm':
|
||||
return vm;
|
||||
}
|
||||
assert(false);
|
||||
return null;
|
||||
@@ -64,6 +64,9 @@ class TargetModel {
|
||||
/// The fuchsia patched SDK.
|
||||
static const TargetModel flutterRunner = TargetModel._('flutter_runner');
|
||||
|
||||
/// The Dart vm.
|
||||
static const TargetModel vm = TargetModel._('vm');
|
||||
|
||||
final String _value;
|
||||
|
||||
@override
|
||||
@@ -218,49 +221,20 @@ class KernelCompiler {
|
||||
bool aot = false,
|
||||
@required bool trackWidgetCreation,
|
||||
List<String> extraFrontEndOptions,
|
||||
String incrementalCompilerByteStorePath,
|
||||
String packagesPath,
|
||||
List<String> fileSystemRoots,
|
||||
String fileSystemScheme,
|
||||
bool targetProductVm = false,
|
||||
String initializeFromDill,
|
||||
String platformDill,
|
||||
}) async {
|
||||
final String frontendServer = artifacts.getArtifactPath(
|
||||
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.
|
||||
if (!sdkRoot.endsWith('/'))
|
||||
if (!sdkRoot.endsWith('/')) {
|
||||
sdkRoot = '$sdkRoot/';
|
||||
}
|
||||
final String engineDartPath = artifacts.getArtifactPath(Artifact.engineDartBinary);
|
||||
if (!processManager.canRun(engineDartPath)) {
|
||||
throwToolExit('Unable to find Dart binary at $engineDartPath');
|
||||
@@ -288,9 +262,6 @@ class KernelCompiler {
|
||||
} else if (aot) {
|
||||
command.add('-Ddart.vm.profile=true');
|
||||
}
|
||||
if (incrementalCompilerByteStorePath != null) {
|
||||
command.add('--incremental');
|
||||
}
|
||||
Uri mainUri;
|
||||
if (packagesPath != null) {
|
||||
command.addAll(<String>['--packages', packagesPath]);
|
||||
@@ -313,6 +284,9 @@ class KernelCompiler {
|
||||
if (initializeFromDill != null) {
|
||||
command.addAll(<String>['--initialize-from-dill', initializeFromDill]);
|
||||
}
|
||||
if (platformDill != null) {
|
||||
command.addAll(<String>[ '--platform', platformDill]);
|
||||
}
|
||||
|
||||
if (extraFrontEndOptions != null)
|
||||
command.addAll(extraFrontEndOptions);
|
||||
@@ -337,9 +311,6 @@ class KernelCompiler {
|
||||
.listen(_stdoutHandler.handler);
|
||||
final int exitCode = await server.exitCode;
|
||||
if (exitCode == 0) {
|
||||
if (fingerprinter != null) {
|
||||
await fingerprinter.writeFingerprint();
|
||||
}
|
||||
return _stdoutHandler.compilerOutput.future;
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -305,6 +305,7 @@ class FakeKernelCompiler implements KernelCompiler {
|
||||
List<String> fileSystemRoots,
|
||||
String fileSystemScheme,
|
||||
bool targetProductVm = false,
|
||||
String platformDill,
|
||||
String initializeFromDill}) async {
|
||||
fs.file(outputFilePath).createSync(recursive: true);
|
||||
return CompilerOutput(outputFilePath, 0, null);
|
||||
|
||||
@@ -505,6 +505,18 @@ example:org-dartlang-app:/
|
||||
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(
|
||||
|
||||
@@ -167,7 +167,6 @@ Hello!
|
||||
|
||||
when(mockKernelCompiler.compile(
|
||||
sdkRoot: anyNamed('sdkRoot'),
|
||||
incrementalCompilerByteStorePath: anyNamed('incrementalCompilerByteStorePath'),
|
||||
mainPath: anyNamed('mainPath'),
|
||||
outputFilePath: anyNamed('outputFilePath'),
|
||||
depFilePath: anyNamed('depFilePath'),
|
||||
|
||||
Reference in New Issue
Block a user