Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: runtime/bin/gen_snapshot.cc

Issue 2073173002: Use the new loader mechanism to resolve URIs and load script files in gen_snapshot. This should all… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address issues that were found while testing with the flutter engine. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/bin/dartutils.cc ('k') | runtime/bin/loader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // Generate a snapshot file after loading all the scripts specified on the 5 // Generate a snapshot file after loading all the scripts specified on the
6 // command line. 6 // command line.
7 7
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
11 11
12 #include <cstdarg> 12 #include <cstdarg>
13 13
14 #include "bin/builtin.h" 14 #include "bin/builtin.h"
15 #include "bin/dartutils.h" 15 #include "bin/dartutils.h"
16 #include "bin/eventhandler.h" 16 #include "bin/eventhandler.h"
17 #include "bin/file.h" 17 #include "bin/file.h"
18 #include "bin/loader.h"
18 #include "bin/log.h" 19 #include "bin/log.h"
19 #include "bin/thread.h" 20 #include "bin/thread.h"
20 #include "bin/utils.h" 21 #include "bin/utils.h"
21 #include "bin/vmservice_impl.h" 22 #include "bin/vmservice_impl.h"
22 23
23 #include "include/dart_api.h" 24 #include "include/dart_api.h"
24 25
25 #include "platform/hashmap.h" 26 #include "platform/hashmap.h"
26 #include "platform/globals.h" 27 #include "platform/globals.h"
27 28
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // (This pointer points into an argv buffer and does not need to be 75 // (This pointer points into an argv buffer and does not need to be
75 // free'd.) 76 // free'd.)
76 static const char* commandline_packages_file = NULL; 77 static const char* commandline_packages_file = NULL;
77 78
78 79
79 // Global state which contains a pointer to the script name for which 80 // Global state which contains a pointer to the script name for which
80 // a snapshot needs to be created (NULL would result in the creation 81 // a snapshot needs to be created (NULL would result in the creation
81 // of a generic snapshot that contains only the corelibs). 82 // of a generic snapshot that contains only the corelibs).
82 static char* app_script_name = NULL; 83 static char* app_script_name = NULL;
83 84
84
85 // Global state that captures the URL mappings specified on the command line.
86 static CommandLineOptions* url_mapping = NULL;
87
88 // Global state that captures the entry point manifest files specified on the 85 // Global state that captures the entry point manifest files specified on the
89 // command line. 86 // command line.
90 static CommandLineOptions* entry_points_files = NULL; 87 static CommandLineOptions* entry_points_files = NULL;
91 88
92 static bool IsValidFlag(const char* name, 89 static bool IsValidFlag(const char* name,
93 const char* prefix, 90 const char* prefix,
94 intptr_t prefix_length) { 91 intptr_t prefix_length) {
95 intptr_t name_length = strlen(name); 92 intptr_t name_length = strlen(name);
96 return ((name_length > prefix_length) && 93 return ((name_length > prefix_length) &&
97 (strncmp(name, prefix, prefix_length) == 0)); 94 (strncmp(name, prefix, prefix_length) == 0));
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 return false; 272 return false;
276 } 273 }
277 274
278 275
279 static bool ProcessURLmappingOption(const char* option) { 276 static bool ProcessURLmappingOption(const char* option) {
280 const char* mapping = ProcessOption(option, "--url_mapping="); 277 const char* mapping = ProcessOption(option, "--url_mapping=");
281 if (mapping == NULL) { 278 if (mapping == NULL) {
282 mapping = ProcessOption(option, "--url-mapping="); 279 mapping = ProcessOption(option, "--url-mapping=");
283 } 280 }
284 if (mapping != NULL) { 281 if (mapping != NULL) {
285 url_mapping->AddArgument(mapping); 282 DartUtils::url_mapping->AddArgument(mapping);
286 return true; 283 return true;
287 } 284 }
288 return false; 285 return false;
289 } 286 }
290 287
291 288
292 static bool IsSnapshottingForPrecompilation() { 289 static bool IsSnapshottingForPrecompilation() {
293 return (assembly_filename != NULL) || (instructions_blob_filename != NULL); 290 return (assembly_filename != NULL) || (instructions_blob_filename != NULL);
294 } 291 }
295 292
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 } 408 }
412 409
413 static Dart_Isolate isolate; 410 static Dart_Isolate isolate;
414 411
415 private: 412 private:
416 Dart_Isolate snapshotted_isolate_; 413 Dart_Isolate snapshotted_isolate_;
417 414
418 DISALLOW_COPY_AND_ASSIGN(UriResolverIsolateScope); 415 DISALLOW_COPY_AND_ASSIGN(UriResolverIsolateScope);
419 }; 416 };
420 417
418
421 Dart_Isolate UriResolverIsolateScope::isolate = NULL; 419 Dart_Isolate UriResolverIsolateScope::isolate = NULL;
422 420
423 421
424 static Dart_Handle ResolveUriInWorkingDirectory(const char* script_uri) { 422 static Dart_Handle LoadUrlContents(const char* uri_string) {
425 bool failed = false; 423 bool failed = false;
426 char* result_string = NULL; 424 char* result_string = NULL;
427 425 uint8_t* payload = NULL;
426 intptr_t payload_length = 0;
427 // Switch to the UriResolver Isolate and load the script.
428 { 428 {
429 UriResolverIsolateScope scope; 429 UriResolverIsolateScope scope;
430 430
431 // Run DartUtils::ResolveUriInWorkingDirectory in context of uri resolver 431 Dart_Handle resolved_uri = Dart_NewStringFromCString(uri_string);
432 // isolate. 432 Dart_Handle result = Loader::LoadUrlContents(resolved_uri,
433 Dart_Handle result = DartUtils::ResolveUriInWorkingDirectory( 433 &payload,
434 DartUtils::NewString(script_uri)); 434 &payload_length);
435 if (Dart_IsError(result)) { 435 if (Dart_IsError(result)) {
436 failed = true; 436 failed = true;
437 result_string = strdup(Dart_GetError(result)); 437 result_string = strdup(Dart_GetError(result));
438 } else {
439 result_string = strdup(DartUtils::GetStringValue(result));
440 } 438 }
441 } 439 }
442 440 // Switch back to the isolate from which we generate the snapshot and
443 Dart_Handle result = failed ? Dart_NewApiError(result_string) : 441 // create the source string for the specified uri.
444 DartUtils::NewString(result_string); 442 Dart_Handle result;
445 free(result_string); 443 if (!failed) {
444 result = Dart_NewStringFromUTF8(payload, payload_length);
445 free(payload);
446 } else {
447 result = DartUtils::NewString(result_string);
448 free(result_string);
449 }
446 return result; 450 return result;
447 } 451 }
448 452
449 453
450 static Dart_Handle FilePathFromUri(const char* script_uri) { 454 static Dart_Handle LoadSnapshotCreationScript(const char* script_name) {
451 bool failed = false; 455 // First resolve the specified script uri with respect to the original
452 char* result_string = NULL; 456 // working directory.
453 457 Dart_Handle resolved_uri = Dart_DefaultCanonicalizeUrl(
454 { 458 Dart_NewStringFromCString(DartUtils::original_working_directory),
455 UriResolverIsolateScope scope; 459 Dart_NewStringFromCString(script_name));
456 460 if (Dart_IsError(resolved_uri)) {
457 // Run DartUtils::FilePathFromUri in context of uri resolver isolate. 461 return resolved_uri;
458 Dart_Handle result = DartUtils::FilePathFromUri(
459 DartUtils::NewString(script_uri));
460 if (Dart_IsError(result)) {
461 failed = true;
462 result_string = strdup(Dart_GetError(result));
463 } else {
464 result_string = strdup(DartUtils::GetStringValue(result));
465 }
466 } 462 }
467 463 // Now load the contents of the specified uri.
468 Dart_Handle result = failed ? Dart_NewApiError(result_string) : 464 const char* resolved_uri_string = DartUtils::GetStringValue(resolved_uri);
469 DartUtils::NewString(result_string); 465 Dart_Handle source = LoadUrlContents(resolved_uri_string);
470 free(result_string); 466 if (Dart_IsError(source)) {
471 return result; 467 return source;
468 }
469 if (IsSnapshottingForPrecompilation()) {
470 return Dart_LoadScript(resolved_uri, source, 0, 0);
471 } else {
472 return Dart_LoadLibrary(resolved_uri, source, 0, 0);
473 }
472 } 474 }
473 475
474 476
475 static Dart_Handle ResolveUri(const char* library_uri, const char* uri) {
476 bool failed = false;
477 char* result_string = NULL;
478
479 {
480 UriResolverIsolateScope scope;
481
482 // Run DartUtils::ResolveUri in context of uri resolver isolate.
483 Dart_Handle result = DartUtils::ResolveUri(
484 DartUtils::NewString(library_uri), DartUtils::NewString(uri));
485 if (Dart_IsError(result)) {
486 failed = true;
487 result_string = strdup(Dart_GetError(result));
488 } else {
489 result_string = strdup(DartUtils::GetStringValue(result));
490 }
491 }
492
493 Dart_Handle result = failed ? Dart_NewApiError(result_string) :
494 DartUtils::NewString(result_string);
495 free(result_string);
496 return result;
497 }
498
499
500
501 static Builtin::BuiltinLibraryId BuiltinId(const char* url) { 477 static Builtin::BuiltinLibraryId BuiltinId(const char* url) {
502 if (DartUtils::IsDartBuiltinLibURL(url)) { 478 if (DartUtils::IsDartBuiltinLibURL(url)) {
503 return Builtin::kBuiltinLibrary; 479 return Builtin::kBuiltinLibrary;
504 } 480 }
505 if (DartUtils::IsDartIOLibURL(url)) { 481 if (DartUtils::IsDartIOLibURL(url)) {
506 return Builtin::kIOLibrary; 482 return Builtin::kIOLibrary;
507 } 483 }
508 return Builtin::kInvalidLibrary; 484 return Builtin::kInvalidLibrary;
509 } 485 }
510 486
511 487
512 static Dart_Handle CreateSnapshotLibraryTagHandler(Dart_LibraryTag tag, 488 static Dart_Handle CreateSnapshotLibraryTagHandler(Dart_LibraryTag tag,
513 Dart_Handle library, 489 Dart_Handle library,
514 Dart_Handle url) { 490 Dart_Handle url) {
515 if (!Dart_IsLibrary(library)) { 491 if (!Dart_IsLibrary(library)) {
516 return Dart_NewApiError("not a library"); 492 return Dart_NewApiError("not a library");
517 } 493 }
518 Dart_Handle library_url = Dart_LibraryUrl(library); 494 Dart_Handle library_url = Dart_LibraryUrl(library);
519 if (Dart_IsError(library_url)) { 495 if (Dart_IsError(library_url)) {
520 return Dart_NewApiError("accessing library url failed"); 496 return Dart_NewApiError("accessing library url failed");
521 } 497 }
522 const char* library_url_string = DartUtils::GetStringValue(library_url); 498 const char* library_url_string = DartUtils::GetStringValue(library_url);
523 const char* mapped_library_url_string = DartUtils::MapLibraryUrl( 499 const char* mapped_library_url_string = DartUtils::MapLibraryUrl(
524 url_mapping, library_url_string); 500 library_url_string);
525 if (mapped_library_url_string != NULL) { 501 if (mapped_library_url_string != NULL) {
526 library_url = ResolveUriInWorkingDirectory(mapped_library_url_string); 502 library_url = Dart_DefaultCanonicalizeUrl(
503 Dart_NewStringFromCString(DartUtils::original_working_directory),
504 Dart_NewStringFromCString(mapped_library_url_string));
527 library_url_string = DartUtils::GetStringValue(library_url); 505 library_url_string = DartUtils::GetStringValue(library_url);
528 } 506 }
529 507
530 if (!Dart_IsString(url)) { 508 if (!Dart_IsString(url)) {
531 return Dart_NewApiError("url is not a string"); 509 return Dart_NewApiError("url is not a string");
532 } 510 }
533 const char* url_string = DartUtils::GetStringValue(url); 511 const char* url_string = DartUtils::GetStringValue(url);
534 const char* mapped_url_string = DartUtils::MapLibraryUrl(url_mapping, 512 const char* mapped_url_string = DartUtils::MapLibraryUrl(url_string);
535 url_string);
536 513
537 Builtin::BuiltinLibraryId libraryBuiltinId = BuiltinId(library_url_string); 514 Builtin::BuiltinLibraryId libraryBuiltinId = BuiltinId(library_url_string);
538 if (tag == Dart_kCanonicalizeUrl) { 515 if (tag == Dart_kCanonicalizeUrl) {
539 if (mapped_url_string) { 516 if (mapped_url_string) {
540 return url; 517 return url;
541 } 518 }
542 // Parts of internal libraries are handled internally. 519 // Parts of internal libraries are handled internally.
543 if (libraryBuiltinId != Builtin::kInvalidLibrary) { 520 if (libraryBuiltinId != Builtin::kInvalidLibrary) {
544 return url; 521 return url;
545 } 522 }
546 return ResolveUri(library_url_string, url_string); 523 return Dart_DefaultCanonicalizeUrl(library_url, url);
547 } 524 }
548 525
549 Builtin::BuiltinLibraryId builtinId = BuiltinId(url_string); 526 Builtin::BuiltinLibraryId builtinId = BuiltinId(url_string);
550 if ((builtinId != Builtin::kInvalidLibrary) && (mapped_url_string == NULL)) { 527 if ((builtinId != Builtin::kInvalidLibrary) && (mapped_url_string == NULL)) {
551 // Special case for importing a builtin library that isn't remapped. 528 // Special case for importing a builtin library that isn't remapped.
552 if (tag == Dart_kImportTag) { 529 if (tag == Dart_kImportTag) {
553 return Builtin::LoadLibrary(url, builtinId); 530 return Builtin::LoadLibrary(url, builtinId);
554 } 531 }
555 ASSERT(tag == Dart_kSourceTag); 532 ASSERT(tag == Dart_kSourceTag);
556 return DartUtils::NewError("Unable to part '%s' ", url_string); 533 return DartUtils::NewError("Unable to part '%s' ", url_string);
557 } 534 }
558 535
559 if (libraryBuiltinId != Builtin::kInvalidLibrary) { 536 if (libraryBuiltinId != Builtin::kInvalidLibrary) {
560 // Special case for parting sources of a builtin library. 537 // Special case for parting sources of a builtin library.
561 if (tag == Dart_kSourceTag) { 538 if (tag == Dart_kSourceTag) {
562 return Dart_LoadSource(library, url, 539 return Dart_LoadSource(library, url,
563 Builtin::PartSource(libraryBuiltinId, url_string), 0, 0); 540 Builtin::PartSource(libraryBuiltinId, url_string), 0, 0);
564 } 541 }
565 ASSERT(tag == Dart_kImportTag); 542 ASSERT(tag == Dart_kImportTag);
566 return DartUtils::NewError("Unable to import '%s' ", url_string); 543 return DartUtils::NewError("Unable to import '%s' ", url_string);
567 } 544 }
568 545
569 Dart_Handle resolved_url = url; 546 Dart_Handle resolved_url = url;
570 if (mapped_url_string != NULL) { 547 if (mapped_url_string != NULL) {
571 // Mapped urls are relative to working directory. 548 // Mapped urls are relative to working directory.
572 resolved_url = ResolveUriInWorkingDirectory(mapped_url_string); 549 resolved_url = Dart_DefaultCanonicalizeUrl(
550 Dart_NewStringFromCString(DartUtils::original_working_directory),
551 Dart_NewStringFromCString(mapped_url_string));
573 if (Dart_IsError(resolved_url)) { 552 if (Dart_IsError(resolved_url)) {
574 return resolved_url; 553 return resolved_url;
575 } 554 }
576 } 555 }
577 556 const char* resolved_uri_string = DartUtils::GetStringValue(resolved_url);
578 // Get the file path out of the url. 557 Dart_Handle source = LoadUrlContents(resolved_uri_string);
579 Dart_Handle file_path = FilePathFromUri(
580 DartUtils::GetStringValue(resolved_url));
581 if (Dart_IsError(file_path)) {
582 return file_path;
583 }
584 const char* raw_path = DartUtils::GetStringValue(file_path);
585 Dart_Handle source = DartUtils::ReadStringFromFile(raw_path);
586 if (Dart_IsError(source)) { 558 if (Dart_IsError(source)) {
587 return source; 559 return source;
588 } 560 }
589 if (tag == Dart_kImportTag) { 561 if (tag == Dart_kImportTag) {
590 return Dart_LoadLibrary(url, source, 0, 0); 562 return Dart_LoadLibrary(url, source, 0, 0);
591 } else { 563 } else {
592 ASSERT(tag == Dart_kSourceTag); 564 ASSERT(tag == Dart_kSourceTag);
593 return Dart_LoadSource(library, url, source, 0, 0); 565 return Dart_LoadSource(library, url, source, 0, 0);
594 } 566 }
595 } 567 }
596 568
597 569
598 static Dart_Handle LoadSnapshotCreationScript(const char* script_name) {
599 Dart_Handle resolved_script_uri = ResolveUriInWorkingDirectory(script_name);
600 if (Dart_IsError(resolved_script_uri)) {
601 return resolved_script_uri;
602 }
603 Dart_Handle script_path = FilePathFromUri(
604 DartUtils::GetStringValue(resolved_script_uri));
605 if (Dart_IsError(script_path)) {
606 return script_path;
607 }
608 Dart_Handle source = DartUtils::ReadStringFromFile(
609 DartUtils::GetStringValue(script_path));
610 if (Dart_IsError(source)) {
611 return source;
612 }
613 if (IsSnapshottingForPrecompilation()) {
614 return Dart_LoadScript(resolved_script_uri, source, 0, 0);
615 } else {
616 return Dart_LoadLibrary(resolved_script_uri, source, 0, 0);
617 }
618 }
619
620
621 static Dart_Handle LoadGenericSnapshotCreationScript( 570 static Dart_Handle LoadGenericSnapshotCreationScript(
622 Builtin::BuiltinLibraryId id) { 571 Builtin::BuiltinLibraryId id) {
623 Dart_Handle source = Builtin::Source(id); 572 Dart_Handle source = Builtin::Source(id);
624 if (Dart_IsError(source)) { 573 if (Dart_IsError(source)) {
625 return source; // source contains the error string. 574 return source; // source contains the error string.
626 } 575 }
627 Dart_Handle lib; 576 Dart_Handle lib;
628 // Load the builtin library to make it available in the snapshot 577 // Load the builtin library to make it available in the snapshot
629 // for importing. 578 // for importing.
630 lib = Builtin::LoadAndCheckLibrary(id); 579 lib = Builtin::LoadAndCheckLibrary(id);
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 } 1073 }
1125 Dart_ExitScope(); 1074 Dart_ExitScope();
1126 1075
1127 // Shutdown the isolate. 1076 // Shutdown the isolate.
1128 Dart_ShutdownIsolate(); 1077 Dart_ShutdownIsolate();
1129 } 1078 }
1130 1079
1131 1080
1132 static void SetupForUriResolution() { 1081 static void SetupForUriResolution() {
1133 // Set up the library tag handler for this isolate. 1082 // Set up the library tag handler for this isolate.
1134 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); 1083 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler);
1135 if (Dart_IsError(result)) { 1084 if (Dart_IsError(result)) {
1136 Log::PrintErr("%s", Dart_GetError(result)); 1085 Log::PrintErr("%s", Dart_GetError(result));
1137 Dart_ExitScope(); 1086 Dart_ExitScope();
1138 Dart_ShutdownIsolate(); 1087 Dart_ShutdownIsolate();
1139 exit(255); 1088 exit(255);
1140 } 1089 }
1141 // This is a generic dart snapshot which needs builtin library setup. 1090 // This is a generic dart snapshot which needs builtin library setup.
1142 Dart_Handle library = 1091 Dart_Handle library =
1143 LoadGenericSnapshotCreationScript(Builtin::kBuiltinLibrary); 1092 LoadGenericSnapshotCreationScript(Builtin::kBuiltinLibrary);
1144 VerifyLoaded(library); 1093 VerifyLoaded(library);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 if (isolate == NULL) { 1131 if (isolate == NULL) {
1183 Log::PrintErr("Error: Could not create service isolate"); 1132 Log::PrintErr("Error: Could not create service isolate");
1184 return NULL; 1133 return NULL;
1185 } 1134 }
1186 1135
1187 Dart_EnterScope(); 1136 Dart_EnterScope();
1188 if (!Dart_IsServiceIsolate(isolate)) { 1137 if (!Dart_IsServiceIsolate(isolate)) {
1189 Log::PrintErr("Error: We only expect to create the service isolate"); 1138 Log::PrintErr("Error: We only expect to create the service isolate");
1190 return NULL; 1139 return NULL;
1191 } 1140 }
1192 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); 1141 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler);
1193 // Setup the native resolver. 1142 // Setup the native resolver.
1194 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); 1143 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary);
1195 Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); 1144 Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary);
1196 if (Dart_IsError(result)) { 1145 if (Dart_IsError(result)) {
1197 Log::PrintErr("Error: Could not set tag handler for service isolate"); 1146 Log::PrintErr("Error: Could not set tag handler for service isolate");
1198 return NULL; 1147 return NULL;
1199 } 1148 }
1200 CHECK_RESULT(result); 1149 CHECK_RESULT(result);
1201 ASSERT(Dart_IsServiceIsolate(isolate)); 1150 ASSERT(Dart_IsServiceIsolate(isolate));
1202 // Load embedder specific bits and return. Will not start http server. 1151 // Load embedder specific bits and return. Will not start http server.
1203 if (!VmService::Setup("127.0.0.1", -1, false /* running_precompiled */)) { 1152 if (!VmService::Setup("127.0.0.1", -1, false /* running_precompiled */)) {
1204 *error = strdup(VmService::GetErrorMessage()); 1153 *error = strdup(VmService::GetErrorMessage());
1205 return NULL; 1154 return NULL;
1206 } 1155 }
1207 Dart_ExitScope(); 1156 Dart_ExitScope();
1208 Dart_ExitIsolate(); 1157 Dart_ExitIsolate();
1209 return isolate; 1158 return isolate;
1210 } 1159 }
1211 1160
1212 1161
1213 int main(int argc, char** argv) { 1162 int main(int argc, char** argv) {
1214 const int EXTRA_VM_ARGUMENTS = 2; 1163 const int EXTRA_VM_ARGUMENTS = 2;
1215 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); 1164 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS);
1216 1165
1217 // Initialize the URL mapping array. 1166 // Initialize the URL mapping array.
1218 CommandLineOptions url_mapping_array(argc); 1167 CommandLineOptions cmdline_url_mapping(argc);
1219 url_mapping = &url_mapping_array; 1168 DartUtils::url_mapping = &cmdline_url_mapping;
1220 1169
1221 // Initialize the entrypoints array. 1170 // Initialize the entrypoints array.
1222 CommandLineOptions entry_points_files_array(argc); 1171 CommandLineOptions entry_points_files_array(argc);
1223 entry_points_files = &entry_points_files_array; 1172 entry_points_files = &entry_points_files_array;
1224 1173
1225 // Parse command line arguments. 1174 // Parse command line arguments.
1226 if (ParseArguments(argc, 1175 if (ParseArguments(argc,
1227 argv, 1176 argv,
1228 &vm_options, 1177 &vm_options,
1229 &app_script_name) < 0) { 1178 &app_script_name) < 0) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 DartUtils::WriteFile, 1220 DartUtils::WriteFile,
1272 DartUtils::CloseFile, 1221 DartUtils::CloseFile,
1273 DartUtils::EntropySource, 1222 DartUtils::EntropySource,
1274 NULL); 1223 NULL);
1275 if (error != NULL) { 1224 if (error != NULL) {
1276 Log::PrintErr("VM initialization failed: %s\n", error); 1225 Log::PrintErr("VM initialization failed: %s\n", error);
1277 free(error); 1226 free(error);
1278 return 255; 1227 return 255;
1279 } 1228 }
1280 1229
1281 IsolateData* isolate_data = new IsolateData(NULL, NULL, NULL); 1230 IsolateData* isolate_data = new IsolateData(NULL,
1231 commandline_package_root,
1232 commandline_packages_file);
1282 Dart_Isolate isolate = Dart_CreateIsolate( 1233 Dart_Isolate isolate = Dart_CreateIsolate(
1283 NULL, NULL, NULL, NULL, isolate_data, &error); 1234 NULL, NULL, NULL, NULL, isolate_data, &error);
1284 if (isolate == NULL) { 1235 if (isolate == NULL) {
1285 Log::PrintErr("Error: %s", error); 1236 Log::PrintErr("Error: %s", error);
1286 free(error); 1237 free(error);
1287 exit(255); 1238 exit(255);
1288 } 1239 }
1289 1240
1290 Dart_Handle result; 1241 Dart_Handle result;
1291 Dart_Handle library; 1242 Dart_Handle library;
1292 Dart_EnterScope(); 1243 Dart_EnterScope();
1293 1244
1294 result = Dart_SetEnvironmentCallback(EnvironmentCallback); 1245 result = Dart_SetEnvironmentCallback(EnvironmentCallback);
1295 CHECK_RESULT(result); 1246 CHECK_RESULT(result);
1296 1247
1297 ASSERT(vm_isolate_snapshot_filename != NULL); 1248 ASSERT(vm_isolate_snapshot_filename != NULL);
1298 ASSERT(isolate_snapshot_filename != NULL); 1249 ASSERT(isolate_snapshot_filename != NULL);
1299 // Load up the script before a snapshot is created. 1250 // Load up the script before a snapshot is created.
1300 if (app_script_name != NULL) { 1251 if (app_script_name != NULL) {
1301 // This is the case of a custom embedder (e.g: dartium) trying to 1252 // This is the case of a custom embedder (e.g: dartium) trying to
1302 // create a full snapshot. The current isolate is set up so that we can 1253 // create a full snapshot. The current isolate is set up so that we can
1303 // invoke the dart uri resolution code like _resolveURI. App script is 1254 // invoke the dart uri resolution code like _resolveURI. App script is
1304 // loaded into a separate isolate. 1255 // loaded into a separate isolate.
1305
1306 SetupForUriResolution(); 1256 SetupForUriResolution();
1307 1257
1308 // Prepare builtin and its dependent libraries for use to resolve URIs. 1258 // Prepare builtin and its dependent libraries for use to resolve URIs.
1309 // Set up various closures, e.g: printing, timers etc. 1259 // Set up various closures, e.g: printing, timers etc.
1310 // Set up 'package root' for URI resolution. 1260 // Set up 'package root' for URI resolution.
1311 result = DartUtils::PrepareForScriptLoading(false, false); 1261 result = DartUtils::PrepareForScriptLoading(false, false);
1312 CHECK_RESULT(result); 1262 CHECK_RESULT(result);
1313 1263
1314 // Set up the load port provided by the service isolate so that we can 1264 // Set up the load port provided by the service isolate so that we can
1315 // load scripts. 1265 // load scripts.
1316 result = DartUtils::SetupServiceLoadPort(); 1266 result = DartUtils::SetupServiceLoadPort();
1317 CHECK_RESULT(result); 1267 CHECK_RESULT(result);
1318 1268
1319 // Setup package root if specified. 1269 // Setup package root if specified.
1320 result = DartUtils::SetupPackageRoot(commandline_package_root, 1270 result = DartUtils::SetupPackageRoot(commandline_package_root,
1321 commandline_packages_file); 1271 commandline_packages_file);
1322 CHECK_RESULT(result); 1272 CHECK_RESULT(result);
1323 1273
1274 UriResolverIsolateScope::isolate = isolate;
1324 Dart_ExitScope(); 1275 Dart_ExitScope();
1325 Dart_ExitIsolate(); 1276 Dart_ExitIsolate();
1326 1277
1327 UriResolverIsolateScope::isolate = isolate;
1328
1329 // Now we create an isolate into which we load all the code that needs to 1278 // Now we create an isolate into which we load all the code that needs to
1330 // be in the snapshot. 1279 // be in the snapshot.
1331 isolate_data = new IsolateData(NULL, NULL, NULL); 1280 isolate_data = new IsolateData(NULL, NULL, NULL);
1332 if (Dart_CreateIsolate( 1281 if (Dart_CreateIsolate(
1333 NULL, NULL, NULL, NULL, isolate_data, &error) == NULL) { 1282 NULL, NULL, NULL, NULL, isolate_data, &error) == NULL) {
1334 fprintf(stderr, "%s", error); 1283 fprintf(stderr, "%s", error);
1335 free(error); 1284 free(error);
1336 exit(255); 1285 exit(255);
1337 } 1286 }
1338 Dart_EnterScope(); 1287 Dart_EnterScope();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1381 EventHandler::Stop(); 1330 EventHandler::Stop();
1382 return 0; 1331 return 0;
1383 } 1332 }
1384 1333
1385 } // namespace bin 1334 } // namespace bin
1386 } // namespace dart 1335 } // namespace dart
1387 1336
1388 int main(int argc, char** argv) { 1337 int main(int argc, char** argv) {
1389 return dart::bin::main(argc, argv); 1338 return dart::bin::main(argc, argv);
1390 } 1339 }
OLDNEW
« no previous file with comments | « runtime/bin/dartutils.cc ('k') | runtime/bin/loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698