Index: runtime/bin/main.cc |
diff --git a/runtime/bin/main.cc b/runtime/bin/main.cc |
index c6a5c93cf6aa77ab5d6347da8ee75cb133fc9b48..1b58c822f6e57e1d384f0b262a36799377d5a653 100644 |
--- a/runtime/bin/main.cc |
+++ b/runtime/bin/main.cc |
@@ -34,6 +34,8 @@ |
#include "zlib/zlib.h" |
#endif |
+#include "vm/kernel.h" |
+ |
namespace dart { |
namespace bin { |
@@ -67,6 +69,11 @@ static bool use_dart_frontend = false; |
static const char* frontend_filename = NULL; |
+// True if the VM should boostrap the SDK from a binary (.dill) file. The |
+// filename points into an argv buffer and does not need to be freed. |
+static bool use_platform_binary = false; |
+static const char* platform_binary_filename = NULL; |
+ |
// Value of the --save-feedback flag. |
// (This pointer points into an argv buffer and does not need to be |
// free'd.) |
@@ -333,6 +340,18 @@ static bool ProcessFrontendOption(const char* filename, |
} |
+static bool ProcessPlatformOption(const char* filename, |
+ CommandLineOptions* vm_options) { |
+ ASSERT(filename != NULL); |
+ if (filename[0] == '\0') { |
+ return false; |
+ } |
+ use_platform_binary = true; |
Vyacheslav Egorov (Google)
2017/04/05 12:21:23
Should not this platform binary be also passed dow
Kevin Millikin (Google)
2017/04/25 18:20:29
Yes, let's add that in a separate change.
|
+ platform_binary_filename = filename; |
+ return true; |
+} |
+ |
+ |
static bool ProcessUseBlobsOption(const char* arg, |
CommandLineOptions* vm_options) { |
ASSERT(arg != NULL); |
@@ -557,6 +576,7 @@ static struct { |
{"--compile_all", ProcessCompileAllOption}, |
{"--parse_all", ProcessParseAllOption}, |
{"--dfe=", ProcessFrontendOption}, |
+ {"--platform=", ProcessPlatformOption}, |
{"--enable-vm-service", ProcessEnableVmServiceOption}, |
{"--disable-service-origin-check", ProcessDisableServiceOriginCheckOption}, |
{"--observe", ProcessObserveOption}, |
@@ -853,11 +873,31 @@ static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate, |
} |
#endif |
- const uint8_t* kernel_file = NULL; |
- intptr_t kernel_length = -1; |
- bool is_kernel = false; |
- |
+ IsolateData* isolate_data = |
Vyacheslav Egorov (Google)
2017/04/05 12:21:23
Was there any reason to move isolate_data creation
Kevin Millikin (Google)
2017/04/25 18:20:29
I used it earlier in an intermediate state, but yo
|
+ new IsolateData(script_uri, package_root, packages_config, app_snapshot); |
+ if (is_main_isolate && (snapshot_deps_filename != NULL)) { |
+ isolate_data->set_dependencies(new MallocGrowableArray<char*>()); |
+ } |
+ void* kernel_platform = NULL; |
+ void* kernel_program = NULL; |
if (!is_kernel_isolate && !is_service_isolate) { |
+ if (use_platform_binary) { |
+ const uint8_t* platform_file = NULL; |
+ intptr_t platform_length = -1; |
+ bool success = TryReadKernel(platform_binary_filename, &platform_file, |
+ &platform_length); |
+ if (!success) { |
+ *error = strdup("The platform binary is not a valid Dart Kernel file."); |
+ *exit_code = kErrorExitCode; |
+ return NULL; |
kustermann
2017/04/05 11:47:07
Maybe 'delete isolate_data' here.
Kevin Millikin (Google)
2017/04/25 18:20:29
Thank you. Well spotted.
|
+ } |
+ kernel_platform = Dart_ReadKernelBinary(platform_file, platform_length); |
+ free(const_cast<uint8_t*>(platform_file)); |
+ } |
+ |
+ bool is_kernel = false; |
+ const uint8_t* kernel_file = NULL; |
+ intptr_t kernel_length = -1; |
if (use_dart_frontend) { |
Dart_KernelCompilationResult result = Dart_CompileToKernel(script_uri); |
*error = result.error; // Copy error message (if any). |
@@ -880,27 +920,20 @@ static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate, |
} else if (!isolate_run_app_snapshot) { |
is_kernel = TryReadKernel(script_uri, &kernel_file, &kernel_length); |
} |
- } |
- void* kernel_program = NULL; |
- if (is_kernel) { |
- kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length); |
- free(const_cast<uint8_t*>(kernel_file)); |
+ if (is_kernel) { |
+ kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length); |
+ free(const_cast<uint8_t*>(kernel_file)); |
+ } |
} |
- IsolateData* isolate_data = |
- new IsolateData(script_uri, package_root, packages_config, app_snapshot); |
- if (is_main_isolate && (snapshot_deps_filename != NULL)) { |
- isolate_data->set_dependencies(new MallocGrowableArray<char*>()); |
- } |
- // If the script is a Kernel binary, then we will try to bootstrap from the |
- // script. |
Dart_Isolate isolate = |
- is_kernel ? Dart_CreateIsolateFromKernel(script_uri, main, kernel_program, |
- flags, isolate_data, error) |
- : Dart_CreateIsolate(script_uri, main, isolate_snapshot_data, |
- isolate_snapshot_instructions, flags, |
- isolate_data, error); |
+ kernel_platform != NULL |
kustermann
2017/04/05 11:47:07
Consider adding another case for 'kernel_program !
Kevin Millikin (Google)
2017/04/25 18:20:29
Good suggestion, left for a separate change.
|
+ ? Dart_CreateIsolateFromKernel(script_uri, main, kernel_platform, |
+ flags, isolate_data, error) |
+ : Dart_CreateIsolate(script_uri, main, isolate_snapshot_data, |
+ isolate_snapshot_instructions, flags, |
+ isolate_data, error); |
if (isolate == NULL) { |
delete isolate_data; |
return NULL; |
@@ -912,11 +945,11 @@ static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate, |
Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); |
CHECK_RESULT(result); |
- if (is_kernel) { |
+ if (kernel_program != NULL) { |
Dart_Handle result = Dart_LoadKernel(kernel_program); |
CHECK_RESULT(result); |
} |
- if (is_kernel || (isolate_snapshot_data != NULL)) { |
+ if ((kernel_platform != NULL) || (isolate_snapshot_data != NULL)) { |
// Setup the native resolver as the snapshot does not carry it. |
Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); |
Builtin::SetNativeResolver(Builtin::kIOLibrary); |
@@ -986,7 +1019,7 @@ static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate, |
Dart_Handle uri = |
DartUtils::ResolveScript(Dart_NewStringFromCString(script_uri)); |
CHECK_RESULT(uri); |
- if (!is_kernel) { |
+ if (kernel_platform == NULL) { |
result = Loader::LibraryTagHandler(Dart_kScriptTag, Dart_Null(), uri); |
CHECK_RESULT(result); |
} else { |