Pass path to platform kernel binary to kernel-service.

Currently kernel-service derives path to platform binary from path to dart executable. It doesn't always work, so dartk tests fail.

R=asiva@google.com, sigmund@google.com

BUG:http://dartbug.com/30456
Review-Url: https://codereview.chromium.org/3001013002 .
This commit is contained in:
Alexander Aprelev 2017-08-17 09:49:45 -07:00
parent 6f96d88e1e
commit ba543167ec
7 changed files with 65 additions and 38 deletions

View file

@ -63,7 +63,10 @@ Dart_Handle DFE::ReloadScript(Dart_Isolate isolate, const char* url_string) {
// TODO(asiva): We will have to change this API to pass in a list of files
// that have changed. For now just pass in the main url_string and have it
// recompile the script.
Dart_KernelCompilationResult kresult = Dart_CompileToKernel(url_string);
// TODO(aam): When Frontend is ready, VM should be passing outline.dill
// instead of platform.dill to Frontend for compilation.
Dart_KernelCompilationResult kresult =
Dart_CompileToKernel(url_string, platform_binary_filename_);
if (kresult.status != Dart_KernelCompilationStatus_Ok) {
return Dart_NewApiError(kresult.error);
}
@ -88,7 +91,10 @@ Dart_Handle DFE::ReloadScript(Dart_Isolate isolate, const char* url_string) {
void* DFE::CompileAndReadScript(const char* script_uri,
char** error,
int* exit_code) {
Dart_KernelCompilationResult result = Dart_CompileToKernel(script_uri);
// TODO(aam): When Frontend is ready, VM should be passing outline.dill
// instead of platform.dill to Frontend for compilation.
Dart_KernelCompilationResult result =
Dart_CompileToKernel(script_uri, platform_binary_filename_);
switch (result.status) {
case Dart_KernelCompilationStatus_Ok:
return Dart_ReadKernelBinary(result.kernel, result.kernel_size);

View file

@ -3130,7 +3130,7 @@ DART_EXPORT bool Dart_IsKernelIsolate(Dart_Isolate isolate);
DART_EXPORT bool Dart_KernelIsolateIsRunning();
DART_EXPORT Dart_Port Dart_KernelPort();
DART_EXPORT Dart_KernelCompilationResult
Dart_CompileToKernel(const char* script_uri);
Dart_CompileToKernel(const char* script_uri, const char* platform_kernel);
typedef struct {
const char* uri;
@ -3138,6 +3138,7 @@ typedef struct {
} Dart_SourceFile;
DART_EXPORT Dart_KernelCompilationResult
Dart_CompileSourcesToKernel(const char* script_uri,
const char* platform_kernel,
int source_files_count,
Dart_SourceFile source_files[],
bool incremental_compile);

View file

@ -5875,19 +5875,20 @@ DART_EXPORT Dart_Port Dart_KernelPort() {
}
DART_EXPORT Dart_KernelCompilationResult
Dart_CompileToKernel(const char* script_uri) {
Dart_CompileToKernel(const char* script_uri, const char* platform_kernel) {
#ifdef DART_PRECOMPILED_RUNTIME
Dart_KernelCompilationResult result;
result.status = Dart_KernelCompilationStatus_Unknown;
result.error = strdup("Dart_CompileToKernel is unsupported.");
return result;
#else
return KernelIsolate::CompileToKernel(script_uri);
return KernelIsolate::CompileToKernel(script_uri, platform_kernel);
#endif
}
DART_EXPORT Dart_KernelCompilationResult
Dart_CompileSourcesToKernel(const char* script_uri,
const char* platform_kernel,
int source_files_count,
Dart_SourceFile sources[],
bool incremental_compile) {
@ -5897,7 +5898,8 @@ Dart_CompileSourcesToKernel(const char* script_uri,
result.error = strdup("Dart_CompileSourcesToKernel is unsupported.");
return result;
#else
return KernelIsolate::CompileToKernel(script_uri, source_files_count, sources,
return KernelIsolate::CompileToKernel(script_uri, platform_kernel,
source_files_count, sources,
incremental_compile);
#endif
}

View file

@ -299,13 +299,14 @@ class KernelCompilationRequest : public ValueObject {
Dart_KernelCompilationResult SendAndWaitForResponse(
Dart_Port kernel_port,
const char* script_uri,
const char* platform_kernel,
int source_files_count,
Dart_SourceFile source_files[],
bool incremental_compile) {
// Build the [null, send_port, script_uri, incremental_compile, isolate_id,
// [files]] message for the Kernel isolate: null tag tells it that request
// came from this code, instead of Loader so that it can given a more
// informative response.
// Build the [null, send_port, script_uri, platform_kernel,
// incremental_compile, isolate_id, [files]] message for the Kernel isolate.
// null tag tells it that request came from this code, instead of Loader
// so that it can given a more informative response.
Dart_CObject tag;
tag.type = Dart_CObject_kNull;
@ -318,6 +319,14 @@ class KernelCompilationRequest : public ValueObject {
uri.type = Dart_CObject_kString;
uri.value.as_string = const_cast<char*>(script_uri);
Dart_CObject dart_platform_kernel;
if (platform_kernel != NULL) {
dart_platform_kernel.type = Dart_CObject_kString;
dart_platform_kernel.value.as_string = const_cast<char*>(platform_kernel);
} else {
dart_platform_kernel.type = Dart_CObject_kNull;
}
Dart_CObject dart_incremental;
dart_incremental.type = Dart_CObject_kBool;
dart_incremental.value.as_bool = incremental_compile;
@ -338,14 +347,15 @@ class KernelCompilationRequest : public ValueObject {
Dart_CObject message;
message.type = Dart_CObject_kArray;
intptr_t message_len = 5;
intptr_t message_len = 6;
Dart_CObject files;
if (source_files_count != 0) {
files = BuildFilesPairs(source_files_count, source_files);
message_len++;
}
Dart_CObject* message_arr[] = {
&tag, &send_port, &uri, &dart_incremental, &isolate_id, &files};
&tag, &send_port, &uri, &dart_platform_kernel, &dart_incremental,
&isolate_id, &files};
message.value.as_array.values = message_arr;
message.value.as_array.length = message_len;
// Send the message.
@ -459,6 +469,7 @@ KernelCompilationRequest* KernelCompilationRequest::requests_ = NULL;
Dart_KernelCompilationResult KernelIsolate::CompileToKernel(
const char* script_uri,
const char* platform_kernel,
int source_file_count,
Dart_SourceFile source_files[],
bool incremental_compile) {
@ -474,8 +485,8 @@ Dart_KernelCompilationResult KernelIsolate::CompileToKernel(
KernelCompilationRequest request;
return request.SendAndWaitForResponse(kernel_port, script_uri,
source_file_count, source_files,
incremental_compile);
platform_kernel, source_file_count,
source_files, incremental_compile);
}
#endif // DART_PRECOMPILED_RUNTIME

View file

@ -29,6 +29,7 @@ class KernelIsolate : public AllStatic {
static Dart_KernelCompilationResult CompileToKernel(
const char* script_uri,
const char* platform_kernel = NULL,
int source_files_count = 0,
Dart_SourceFile source_files[] = NULL,
bool incremental_compile = false);

View file

@ -191,7 +191,8 @@ char* TestCase::CompileTestScriptWithDFE(const char* url,
bool incrementally) {
Zone* zone = Thread::Current()->zone();
Dart_KernelCompilationResult compilation_result = Dart_CompileSourcesToKernel(
url, sourcefiles_count, sourcefiles, incrementally);
url, NULL /* platform binary can be found at the default location */,
sourcefiles_count, sourcefiles, incrementally);
if (compilation_result.status != Dart_KernelCompilationStatus_Ok) {
return OS::SCreate(zone, "Compilation failed %s", compilation_result.error);

View file

@ -45,23 +45,16 @@ abstract class Compiler {
CompilerOptions options;
Compiler(this.fileSystem) {
Compiler(this.fileSystem, Uri platformKernel) {
Uri packagesUri = (Platform.packageConfig != null)
? Uri.parse(Platform.packageConfig)
: null;
Uri sdkSummary = Uri.base
.resolveUri(new Uri.file(Platform.resolvedExecutable))
.resolveUri(new Uri.directory("patched_sdk"))
// TODO(sigmund): use outline.dill when the mixin transformer is
// modular.
.resolve('platform.dill');
if (verbose) {
print("DFE: Platform.packageConfig: ${Platform.packageConfig}");
print("DFE: packagesUri: ${packagesUri}");
print("DFE: Platform.resolvedExecutable: ${Platform.resolvedExecutable}");
print("DFE: sdkSummary: ${sdkSummary}");
print("DFE: platformKernel: ${platformKernel}");
}
options = new CompilerOptions()
@ -69,7 +62,7 @@ abstract class Compiler {
..fileSystem = fileSystem
..target = new VmFastaTarget(new TargetFlags(strongMode: strongMode))
..packagesFileUri = packagesUri
..sdkSummary = sdkSummary
..sdkSummary = platformKernel
..verbose = verbose
..throwOnErrors = false
..reportMessages = true
@ -88,7 +81,8 @@ abstract class Compiler {
class IncrementalCompiler extends Compiler {
IncrementalKernelGenerator generator;
IncrementalCompiler(FileSystem fileSystem) : super(fileSystem);
IncrementalCompiler(FileSystem fileSystem, Uri platformKernel)
: super(fileSystem, platformKernel);
@override
Future<Program> compile(Uri script) async {
@ -109,8 +103,9 @@ class IncrementalCompiler extends Compiler {
class SingleShotCompiler extends Compiler {
final bool requireMain;
SingleShotCompiler(FileSystem fileSystem, this.requireMain)
: super(fileSystem);
SingleShotCompiler(
FileSystem fileSystem, Uri platformKernel, this.requireMain)
: super(fileSystem, platformKernel);
@override
Future<Program> compile(Uri script) async {
@ -123,7 +118,7 @@ class SingleShotCompiler extends Compiler {
final Map<int, Compiler> isolateCompilers = new Map<int, Compiler>();
Future<Compiler> lookupOrBuildNewIncrementalCompiler(
int isolateId, List sourceFiles) async {
int isolateId, List sourceFiles, Uri platformKernel) async {
IncrementalCompiler compiler;
if (isolateCompilers.containsKey(isolateId)) {
compiler = isolateCompilers[isolateId];
@ -146,7 +141,7 @@ Future<Compiler> lookupOrBuildNewIncrementalCompiler(
// destroyed when corresponding isolate is shut down. To achieve that kernel
// isolate needs to receive a message indicating that particular
// isolate was shut down. Message should be handled here in this script.
compiler = new IncrementalCompiler(fileSystem);
compiler = new IncrementalCompiler(fileSystem, platformKernel);
isolateCompilers[isolateId] = compiler;
}
return compiler;
@ -161,9 +156,18 @@ Future _processLoadRequest(request) async {
final SendPort port = request[1];
final String inputFileUri = request[2];
final Uri script = Uri.base.resolve(inputFileUri);
final bool incremental = request[3];
final Uri platformKernel = request[3] != null
? Uri.base.resolveUri(new Uri.file(request[3]))
: Uri.base
.resolveUri(new Uri.file(Platform.resolvedExecutable))
.resolveUri(new Uri.directory("patched_sdk"))
// TODO(sigmund): use outline.dill when the mixin transformer is
// modular.
.resolve('platform.dill');
final List sourceFiles = request.length > 5 ? request[5] : null;
final bool incremental = request[4];
final List sourceFiles = request.length > 6 ? request[6] : null;
Compiler compiler;
// TODO(aam): There should be no need to have an option to choose
@ -171,15 +175,15 @@ Future _processLoadRequest(request) async {
// compiler as its functionality is a super set of the other one. We need to
// watch the performance though.
if (incremental) {
final int isolateId = request[4];
compiler =
await lookupOrBuildNewIncrementalCompiler(isolateId, sourceFiles);
final int isolateId = request[5];
compiler = await lookupOrBuildNewIncrementalCompiler(
isolateId, sourceFiles, platformKernel);
} else {
final FileSystem fileSystem = sourceFiles == null
? PhysicalFileSystem.instance
: _buildFileSystem(sourceFiles);
compiler = new SingleShotCompiler(
fileSystem, sourceFiles == null /* requireMain */);
fileSystem, platformKernel, sourceFiles == null /* requireMain */);
}
CompilationResult result;
@ -262,8 +266,9 @@ train(String scriptUri) {
tag,
responsePort.sendPort,
scriptUri,
1 /* isolateId chosen randomly */,
false /* incremental */
null /* platformKernel */,
false /* incremental */,
1 /* isolateId chosen randomly */
];
_processLoadRequest(request);
}