Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/loader.h" |
| 19 #include "bin/log.h" | 19 #include "bin/log.h" |
| 20 #include "bin/thread.h" | 20 #include "bin/thread.h" |
| 21 #include "bin/utils.h" | 21 #include "bin/utils.h" |
| 22 #include "bin/vmservice_impl.h" | 22 #include "bin/vmservice_impl.h" |
| 23 | 23 |
| 24 #include "include/dart_api.h" | 24 #include "include/dart_api.h" |
| 25 #include "include/dart_tools_api.h" | 25 #include "include/dart_tools_api.h" |
| 26 | 26 |
| 27 #include "platform/hashmap.h" | 27 #include "platform/hashmap.h" |
| 28 #include "platform/globals.h" | 28 #include "platform/globals.h" |
| 29 #include "platform/growable_array.h" | |
| 29 | 30 |
| 30 namespace dart { | 31 namespace dart { |
| 31 namespace bin { | 32 namespace bin { |
| 32 | 33 |
| 33 // Exit code indicating an API error. | 34 // Exit code indicating an API error. |
| 34 static const int kApiErrorExitCode = 253; | 35 static const int kApiErrorExitCode = 253; |
| 35 // Exit code indicating a compilation error. | 36 // Exit code indicating a compilation error. |
| 36 static const int kCompilationErrorExitCode = 254; | 37 static const int kCompilationErrorExitCode = 254; |
| 37 // Exit code indicating an unhandled error that is not a compilation error. | 38 // Exit code indicating an unhandled error that is not a compilation error. |
| 38 static const int kErrorExitCode = 255; | 39 static const int kErrorExitCode = 255; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 59 | 60 |
| 60 | 61 |
| 61 // The core snapshot to use when creating isolates. Normally NULL, but loaded | 62 // The core snapshot to use when creating isolates. Normally NULL, but loaded |
| 62 // from a file when creating script snapshots. | 63 // from a file when creating script snapshots. |
| 63 const uint8_t* isolate_snapshot_data = NULL; | 64 const uint8_t* isolate_snapshot_data = NULL; |
| 64 | 65 |
| 65 | 66 |
| 66 // Global state that indicates whether a snapshot is to be created and | 67 // Global state that indicates whether a snapshot is to be created and |
| 67 // if so which file to write the snapshot into. | 68 // if so which file to write the snapshot into. |
| 68 enum SnapshotKind { | 69 enum SnapshotKind { |
| 70 kNone, | |
| 69 kCore, | 71 kCore, |
| 70 kScript, | 72 kScript, |
| 71 kAppAOTBlobs, | 73 kAppAOTBlobs, |
| 72 kAppAOTAssembly, | 74 kAppAOTAssembly, |
| 73 }; | 75 }; |
| 74 static SnapshotKind snapshot_kind = kCore; | 76 static SnapshotKind snapshot_kind = kCore; |
| 75 static const char* vm_snapshot_data_filename = NULL; | 77 static const char* vm_snapshot_data_filename = NULL; |
| 76 static const char* vm_snapshot_instructions_filename = NULL; | 78 static const char* vm_snapshot_instructions_filename = NULL; |
| 77 static const char* isolate_snapshot_data_filename = NULL; | 79 static const char* isolate_snapshot_data_filename = NULL; |
| 78 static const char* isolate_snapshot_instructions_filename = NULL; | 80 static const char* isolate_snapshot_instructions_filename = NULL; |
| 79 static const char* assembly_filename = NULL; | 81 static const char* assembly_filename = NULL; |
| 80 static const char* script_snapshot_filename = NULL; | 82 static const char* script_snapshot_filename = NULL; |
| 83 static const char* dependencies_filename = NULL; | |
| 81 | 84 |
| 82 | 85 |
| 83 // Value of the --package-root flag. | 86 // Value of the --package-root flag. |
| 84 // (This pointer points into an argv buffer and does not need to be | 87 // (This pointer points into an argv buffer and does not need to be |
| 85 // free'd.) | 88 // free'd.) |
| 86 static const char* commandline_package_root = NULL; | 89 static const char* commandline_package_root = NULL; |
| 87 | 90 |
| 88 // Value of the --packages flag. | 91 // Value of the --packages flag. |
| 89 // (This pointer points into an argv buffer and does not need to be | 92 // (This pointer points into an argv buffer and does not need to be |
| 90 // free'd.) | 93 // free'd.) |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 } | 203 } |
| 201 return NULL; | 204 return NULL; |
| 202 } | 205 } |
| 203 | 206 |
| 204 | 207 |
| 205 static bool ProcessSnapshotKindOption(const char* option) { | 208 static bool ProcessSnapshotKindOption(const char* option) { |
| 206 const char* kind = ProcessOption(option, "--snapshot_kind="); | 209 const char* kind = ProcessOption(option, "--snapshot_kind="); |
| 207 if (kind == NULL) { | 210 if (kind == NULL) { |
| 208 return false; | 211 return false; |
| 209 } | 212 } |
| 210 if (strcmp(kind, "core") == 0) { | 213 if (strcmp(kind, "none") == 0) { |
| 214 snapshot_kind = kNone; | |
| 215 return true; | |
| 216 } else if (strcmp(kind, "core") == 0) { | |
| 211 snapshot_kind = kCore; | 217 snapshot_kind = kCore; |
| 212 return true; | 218 return true; |
| 213 } else if (strcmp(kind, "script") == 0) { | 219 } else if (strcmp(kind, "script") == 0) { |
| 214 snapshot_kind = kScript; | 220 snapshot_kind = kScript; |
| 215 return true; | 221 return true; |
| 216 } else if (strcmp(kind, "app-aot-blobs") == 0) { | 222 } else if (strcmp(kind, "app-aot-blobs") == 0) { |
| 217 snapshot_kind = kAppAOTBlobs; | 223 snapshot_kind = kAppAOTBlobs; |
| 218 return true; | 224 return true; |
| 219 } else if (strcmp(kind, "app-aot-assembly") == 0) { | 225 } else if (strcmp(kind, "app-aot-assembly") == 0) { |
| 220 snapshot_kind = kAppAOTAssembly; | 226 snapshot_kind = kAppAOTAssembly; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 static bool ProcessScriptSnapshotOption(const char* option) { | 287 static bool ProcessScriptSnapshotOption(const char* option) { |
| 282 const char* name = ProcessOption(option, "--script_snapshot="); | 288 const char* name = ProcessOption(option, "--script_snapshot="); |
| 283 if (name != NULL) { | 289 if (name != NULL) { |
| 284 script_snapshot_filename = name; | 290 script_snapshot_filename = name; |
| 285 return true; | 291 return true; |
| 286 } | 292 } |
| 287 return false; | 293 return false; |
| 288 } | 294 } |
| 289 | 295 |
| 290 | 296 |
| 297 static bool ProcessDependenciesOption(const char* option) { | |
| 298 const char* name = ProcessOption(option, "--dependencies="); | |
| 299 if (name != NULL) { | |
| 300 dependencies_filename = name; | |
| 301 return true; | |
| 302 } | |
| 303 return false; | |
| 304 } | |
| 305 | |
| 306 | |
| 291 static bool ProcessEmbedderEntryPointsManifestOption(const char* option) { | 307 static bool ProcessEmbedderEntryPointsManifestOption(const char* option) { |
| 292 const char* name = ProcessOption(option, "--embedder_entry_points_manifest="); | 308 const char* name = ProcessOption(option, "--embedder_entry_points_manifest="); |
| 293 if (name != NULL) { | 309 if (name != NULL) { |
| 294 entry_points_files->AddArgument(name); | 310 entry_points_files->AddArgument(name); |
| 295 return true; | 311 return true; |
| 296 } | 312 } |
| 297 return false; | 313 return false; |
| 298 } | 314 } |
| 299 | 315 |
| 300 | 316 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 | 369 |
| 354 // Parse out the vm options. | 370 // Parse out the vm options. |
| 355 while ((i < argc) && IsValidFlag(argv[i], kPrefix, kPrefixLen)) { | 371 while ((i < argc) && IsValidFlag(argv[i], kPrefix, kPrefixLen)) { |
| 356 if (ProcessSnapshotKindOption(argv[i]) || | 372 if (ProcessSnapshotKindOption(argv[i]) || |
| 357 ProcessVmSnapshotDataOption(argv[i]) || | 373 ProcessVmSnapshotDataOption(argv[i]) || |
| 358 ProcessVmSnapshotInstructionsOption(argv[i]) || | 374 ProcessVmSnapshotInstructionsOption(argv[i]) || |
| 359 ProcessIsolateSnapshotDataOption(argv[i]) || | 375 ProcessIsolateSnapshotDataOption(argv[i]) || |
| 360 ProcessIsolateSnapshotInstructionsOption(argv[i]) || | 376 ProcessIsolateSnapshotInstructionsOption(argv[i]) || |
| 361 ProcessAssemblyOption(argv[i]) || | 377 ProcessAssemblyOption(argv[i]) || |
| 362 ProcessScriptSnapshotOption(argv[i]) || | 378 ProcessScriptSnapshotOption(argv[i]) || |
| 379 ProcessDependenciesOption(argv[i]) || | |
| 363 ProcessEmbedderEntryPointsManifestOption(argv[i]) || | 380 ProcessEmbedderEntryPointsManifestOption(argv[i]) || |
| 364 ProcessURLmappingOption(argv[i]) || ProcessPackageRootOption(argv[i]) || | 381 ProcessURLmappingOption(argv[i]) || ProcessPackageRootOption(argv[i]) || |
| 365 ProcessPackagesOption(argv[i]) || ProcessEnvironmentOption(argv[i])) { | 382 ProcessPackagesOption(argv[i]) || ProcessEnvironmentOption(argv[i])) { |
| 366 i += 1; | 383 i += 1; |
| 367 continue; | 384 continue; |
| 368 } | 385 } |
| 369 vm_options->AddArgument(argv[i]); | 386 vm_options->AddArgument(argv[i]); |
| 370 i += 1; | 387 i += 1; |
| 371 } | 388 } |
| 372 | 389 |
| 373 // Get the script name. | 390 // Get the script name. |
| 374 if (i < argc) { | 391 if (i < argc) { |
| 375 *script_name = argv[i]; | 392 *script_name = argv[i]; |
| 376 i += 1; | 393 i += 1; |
| 377 } else { | 394 } else { |
| 378 *script_name = NULL; | 395 *script_name = NULL; |
| 379 } | 396 } |
| 380 | 397 |
| 381 // Verify consistency of arguments. | 398 // Verify consistency of arguments. |
| 382 if ((commandline_package_root != NULL) && | 399 if ((commandline_package_root != NULL) && |
| 383 (commandline_packages_file != NULL)) { | 400 (commandline_packages_file != NULL)) { |
| 384 Log::PrintErr( | 401 Log::PrintErr( |
| 385 "Specifying both a packages directory and a packages " | 402 "Specifying both a packages directory and a packages " |
| 386 "file is invalid.\n\n"); | 403 "file is invalid.\n\n"); |
| 387 return -1; | 404 return -1; |
| 388 } | 405 } |
| 389 | 406 |
| 390 switch (snapshot_kind) { | 407 switch (snapshot_kind) { |
| 408 case kNone: { | |
| 409 break; | |
| 410 } | |
| 391 case kCore: { | 411 case kCore: { |
| 392 if ((vm_snapshot_data_filename == NULL) || | 412 if ((vm_snapshot_data_filename == NULL) || |
| 393 (isolate_snapshot_data_filename == NULL)) { | 413 (isolate_snapshot_data_filename == NULL)) { |
| 394 Log::PrintErr( | 414 Log::PrintErr( |
| 395 "Building a core snapshot requires specifying output files for " | 415 "Building a core snapshot requires specifying output files for " |
| 396 "--vm_snapshot_data and --isolate_snapshot_data.\n\n"); | 416 "--vm_snapshot_data and --isolate_snapshot_data.\n\n"); |
| 397 return -1; | 417 return -1; |
| 398 } | 418 } |
| 399 break; | 419 break; |
| 400 } | 420 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 private: | 514 private: |
| 495 Dart_Isolate snapshotted_isolate_; | 515 Dart_Isolate snapshotted_isolate_; |
| 496 | 516 |
| 497 DISALLOW_COPY_AND_ASSIGN(UriResolverIsolateScope); | 517 DISALLOW_COPY_AND_ASSIGN(UriResolverIsolateScope); |
| 498 }; | 518 }; |
| 499 | 519 |
| 500 | 520 |
| 501 Dart_Isolate UriResolverIsolateScope::isolate = NULL; | 521 Dart_Isolate UriResolverIsolateScope::isolate = NULL; |
| 502 | 522 |
| 503 | 523 |
| 524 static char* ResolveAsFilePath(const char* uri_string) { | |
| 525 UriResolverIsolateScope scope; | |
| 526 uint8_t* scoped_file_path = NULL; | |
| 527 intptr_t scoped_file_path_length = -1; | |
| 528 Dart_Handle uri = Dart_NewStringFromCString(uri_string); | |
|
siva
2017/02/22 23:37:16
ASSERT(!Dart_IsError(uri));
rmacnak
2017/02/23 19:00:17
Done.
| |
| 529 Dart_Handle result = Loader::ResolveAsFilePath(uri, &scoped_file_path, | |
| 530 &scoped_file_path_length); | |
| 531 if (Dart_IsError(result)) { | |
| 532 Log::Print("Error resolving dependency: %s\n", Dart_GetError(result)); | |
| 533 exit(kErrorExitCode); | |
| 534 } | |
| 535 return StringUtils::StrNDup(reinterpret_cast<const char*>(scoped_file_path), | |
| 536 scoped_file_path_length); | |
| 537 } | |
| 538 | |
| 539 | |
| 540 static void AddDependency(const char* uri_string) { | |
| 541 IsolateData* isolate_data = | |
| 542 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); | |
| 543 MallocGrowableArray<char*>* dependencies = isolate_data->dependencies(); | |
| 544 if (dependencies != NULL) { | |
| 545 dependencies->Add(ResolveAsFilePath(uri_string)); | |
| 546 } | |
| 547 } | |
| 548 | |
| 549 | |
| 504 static Dart_Handle LoadUrlContents(const char* uri_string) { | 550 static Dart_Handle LoadUrlContents(const char* uri_string) { |
| 505 bool failed = false; | 551 bool failed = false; |
| 506 char* result_string = NULL; | 552 char* error_string = NULL; |
| 507 uint8_t* payload = NULL; | 553 uint8_t* payload = NULL; |
| 508 intptr_t payload_length = 0; | 554 intptr_t payload_length = 0; |
| 509 // Switch to the UriResolver Isolate and load the script. | 555 // Switch to the UriResolver Isolate and load the script. |
| 510 { | 556 { |
| 511 UriResolverIsolateScope scope; | 557 UriResolverIsolateScope scope; |
| 512 | 558 |
| 513 Dart_Handle resolved_uri = Dart_NewStringFromCString(uri_string); | 559 Dart_Handle resolved_uri = Dart_NewStringFromCString(uri_string); |
| 514 Dart_Handle result = | 560 Dart_Handle result = |
| 515 Loader::LoadUrlContents(resolved_uri, &payload, &payload_length); | 561 Loader::LoadUrlContents(resolved_uri, &payload, &payload_length); |
| 516 if (Dart_IsError(result)) { | 562 if (Dart_IsError(result)) { |
| 517 failed = true; | 563 failed = true; |
| 518 result_string = strdup(Dart_GetError(result)); | 564 error_string = strdup(Dart_GetError(result)); |
| 519 } | 565 } |
| 520 } | 566 } |
| 567 AddDependency(uri_string); | |
| 521 // Switch back to the isolate from which we generate the snapshot and | 568 // Switch back to the isolate from which we generate the snapshot and |
| 522 // create the source string for the specified uri. | 569 // create the source string for the specified uri. |
| 523 Dart_Handle result; | 570 Dart_Handle result; |
| 524 if (!failed) { | 571 if (!failed) { |
| 525 result = Dart_NewStringFromUTF8(payload, payload_length); | 572 result = Dart_NewStringFromUTF8(payload, payload_length); |
| 526 free(payload); | 573 free(payload); |
| 527 } else { | 574 } else { |
| 528 result = Dart_NewApiError(result_string); | 575 result = Dart_NewApiError(error_string); |
| 529 free(result_string); | 576 free(error_string); |
| 530 } | 577 } |
| 531 return result; | 578 return result; |
| 532 } | 579 } |
| 533 | 580 |
| 534 | 581 |
| 535 static Dart_Handle ResolveUriInWorkingDirectory(const char* script_uri) { | 582 static Dart_Handle ResolveUriInWorkingDirectory(const char* script_uri) { |
| 536 bool failed = false; | 583 bool failed = false; |
| 537 char* result_string = NULL; | 584 char* result_string = NULL; |
| 538 | 585 |
| 539 { | 586 { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 584 if (DartUtils::IsDartBuiltinLibURL(url)) { | 631 if (DartUtils::IsDartBuiltinLibURL(url)) { |
| 585 return Builtin::kBuiltinLibrary; | 632 return Builtin::kBuiltinLibrary; |
| 586 } | 633 } |
| 587 if (DartUtils::IsDartIOLibURL(url)) { | 634 if (DartUtils::IsDartIOLibURL(url)) { |
| 588 return Builtin::kIOLibrary; | 635 return Builtin::kIOLibrary; |
| 589 } | 636 } |
| 590 return Builtin::kInvalidLibrary; | 637 return Builtin::kInvalidLibrary; |
| 591 } | 638 } |
| 592 | 639 |
| 593 | 640 |
| 641 static void CreateAndWriteDependenciesFile() { | |
| 642 IsolateData* isolate_data = | |
| 643 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); | |
| 644 MallocGrowableArray<char*>* dependencies = isolate_data->dependencies(); | |
| 645 if (dependencies == NULL) { | |
| 646 return; | |
| 647 } | |
| 648 | |
| 649 ASSERT(dependencies_filename != NULL); | |
| 650 File* file = File::Open(dependencies_filename, File::kWriteTruncate); | |
| 651 if (file == NULL) { | |
| 652 Log::PrintErr("Error: Unable to open dependencies file: %s\n\n", | |
| 653 dependencies_filename); | |
| 654 exit(kErrorExitCode); | |
| 655 } | |
| 656 bool success = true; | |
| 657 | |
| 658 // Targets: | |
| 659 if (vm_snapshot_data_filename != NULL) { | |
| 660 success &= | |
| 661 file->Print("%s ", File::GetCanonicalPath(vm_snapshot_data_filename)); | |
| 662 } | |
| 663 if (vm_snapshot_instructions_filename != NULL) { | |
| 664 success &= file->Print( | |
| 665 "%s ", File::GetCanonicalPath(vm_snapshot_instructions_filename)); | |
| 666 } | |
| 667 if (isolate_snapshot_data_filename != NULL) { | |
| 668 success &= file->Print( | |
| 669 "%s ", File::GetCanonicalPath(isolate_snapshot_data_filename)); | |
| 670 } | |
| 671 if (isolate_snapshot_instructions_filename != NULL) { | |
| 672 success &= file->Print( | |
| 673 "%s ", File::GetCanonicalPath(isolate_snapshot_instructions_filename)); | |
| 674 } | |
| 675 if (assembly_filename != NULL) { | |
| 676 success &= file->Print("%s ", File::GetCanonicalPath(assembly_filename)); | |
| 677 } | |
| 678 if (script_snapshot_filename != NULL) { | |
| 679 success &= | |
| 680 file->Print("%s ", File::GetCanonicalPath(script_snapshot_filename)); | |
| 681 } | |
| 682 | |
| 683 success &= file->Print(": "); | |
| 684 | |
| 685 // Sources: | |
| 686 for (intptr_t i = 0; i < dependencies->length(); i++) { | |
| 687 char* dep = dependencies->At(i); | |
| 688 success &= file->Print("%s ", dep); | |
| 689 free(dep); | |
| 690 } | |
| 691 success &= file->Print("\n"); | |
| 692 | |
| 693 if (!success) { | |
| 694 Log::PrintErr("Error: Unable to write dependencies file: %s\n\n", | |
| 695 dependencies_filename); | |
| 696 exit(kErrorExitCode); | |
| 697 } | |
| 698 file->Release(); | |
| 699 delete dependencies; | |
| 700 isolate_data->set_dependencies(NULL); | |
| 701 } | |
| 702 | |
| 703 | |
| 594 static Dart_Handle CreateSnapshotLibraryTagHandler(Dart_LibraryTag tag, | 704 static Dart_Handle CreateSnapshotLibraryTagHandler(Dart_LibraryTag tag, |
| 595 Dart_Handle library, | 705 Dart_Handle library, |
| 596 Dart_Handle url) { | 706 Dart_Handle url) { |
| 597 if (!Dart_IsLibrary(library)) { | 707 if (!Dart_IsLibrary(library)) { |
| 598 return Dart_NewApiError("not a library"); | 708 return Dart_NewApiError("not a library"); |
| 599 } | 709 } |
| 600 Dart_Handle library_url = Dart_LibraryUrl(library); | 710 Dart_Handle library_url = Dart_LibraryUrl(library); |
| 601 if (Dart_IsError(library_url)) { | 711 if (Dart_IsError(library_url)) { |
| 602 return Dart_NewApiError("accessing library url failed"); | 712 return Dart_NewApiError("accessing library url failed"); |
| 603 } | 713 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 685 } | 795 } |
| 686 | 796 |
| 687 | 797 |
| 688 // clang-format off | 798 // clang-format off |
| 689 static void PrintUsage() { | 799 static void PrintUsage() { |
| 690 Log::PrintErr( | 800 Log::PrintErr( |
| 691 "Usage: \n" | 801 "Usage: \n" |
| 692 " gen_snapshot [<vm-flags>] [<options>] [<dart-script-file>] \n" | 802 " gen_snapshot [<vm-flags>] [<options>] [<dart-script-file>] \n" |
| 693 " \n" | 803 " \n" |
| 694 " Global options: \n" | 804 " Global options: \n" |
| 695 " --package_root=<path> Where to find packages, that is, \n" | 805 " --package_root=<path> Where to find packages, that is, \n" |
| 696 " package:... imports. \n" | 806 " package:... imports. \n" |
| 697 " \n" | 807 " \n" |
| 698 " --packages=<packages_file> Where to find a package spec file \n" | 808 " --packages=<packages_file> Where to find a package spec file \n" |
| 699 " \n" | 809 " \n" |
| 700 " --url_mapping=<mapping> Uses the URL mapping(s) specified on \n" | 810 " --url_mapping=<mapping> Uses the URL mapping(s) specified on \n" |
| 701 " the command line to load the \n" | 811 " the command line to load the \n" |
| 702 " libraries. \n" | 812 " libraries. \n" |
| 813 " --dependencies=<output-file> Generates a Makefile with snapshot output \n" | |
| 814 " files as targets and all transitive imports\n" | |
| 815 " as sources. \n" | |
| 816 " \n" | |
| 817 " To discover dependencies without generating a snapshot: \n" | |
| 818 " --snapshot_kind=none \n" | |
| 819 " <dart-script-file> \n" | |
| 703 " \n" | 820 " \n" |
| 704 " To create a core snapshot: \n" | 821 " To create a core snapshot: \n" |
| 705 " --snapshot_kind=core \n" | 822 " --snapshot_kind=core \n" |
| 706 " --vm_snapshot_data=<output-file> \n" | 823 " --vm_snapshot_data=<output-file> \n" |
| 707 " --isolate_snapshot_data=<output-file> \n" | 824 " --isolate_snapshot_data=<output-file> \n" |
| 708 " [<dart-script-file>] \n" | 825 " [<dart-script-file>] \n" |
| 709 " \n" | 826 " \n" |
| 710 " Writes a snapshot of <dart-script-file> to the specified snapshot files. \n" | 827 " Writes a snapshot of <dart-script-file> to the specified snapshot files. \n" |
| 711 " If no <dart-script-file> is passed, a generic snapshot of all the corelibs \n" | 828 " If no <dart-script-file> is passed, a generic snapshot of all the corelibs \n" |
| 712 " is created. \n" | 829 " is created. \n" |
| (...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1336 File* file = File::Open(vm_snapshot_data_filename, File::kRead); | 1453 File* file = File::Open(vm_snapshot_data_filename, File::kRead); |
| 1337 if (file == NULL) { | 1454 if (file == NULL) { |
| 1338 Log::PrintErr("Failed to open: %s\n", vm_snapshot_data_filename); | 1455 Log::PrintErr("Failed to open: %s\n", vm_snapshot_data_filename); |
| 1339 return kErrorExitCode; | 1456 return kErrorExitCode; |
| 1340 } | 1457 } |
| 1341 mapped_vm_snapshot_data = file->Map(File::kReadOnly, 0, file->Length()); | 1458 mapped_vm_snapshot_data = file->Map(File::kReadOnly, 0, file->Length()); |
| 1342 if (mapped_vm_snapshot_data == NULL) { | 1459 if (mapped_vm_snapshot_data == NULL) { |
| 1343 Log::PrintErr("Failed to read: %s\n", vm_snapshot_data_filename); | 1460 Log::PrintErr("Failed to read: %s\n", vm_snapshot_data_filename); |
| 1344 return kErrorExitCode; | 1461 return kErrorExitCode; |
| 1345 } | 1462 } |
| 1346 file->Close(); | 1463 file->Release(); |
| 1347 init_params.vm_snapshot_data = | 1464 init_params.vm_snapshot_data = |
| 1348 reinterpret_cast<const uint8_t*>(mapped_vm_snapshot_data->address()); | 1465 reinterpret_cast<const uint8_t*>(mapped_vm_snapshot_data->address()); |
| 1349 | 1466 |
| 1350 file = File::Open(isolate_snapshot_data_filename, File::kRead); | 1467 file = File::Open(isolate_snapshot_data_filename, File::kRead); |
| 1351 if (file == NULL) { | 1468 if (file == NULL) { |
| 1352 Log::PrintErr("Failed to open: %s\n", isolate_snapshot_data_filename); | 1469 Log::PrintErr("Failed to open: %s\n", isolate_snapshot_data_filename); |
| 1353 return kErrorExitCode; | 1470 return kErrorExitCode; |
| 1354 } | 1471 } |
| 1355 mapped_isolate_snapshot_data = | 1472 mapped_isolate_snapshot_data = |
| 1356 file->Map(File::kReadOnly, 0, file->Length()); | 1473 file->Map(File::kReadOnly, 0, file->Length()); |
| 1357 if (mapped_isolate_snapshot_data == NULL) { | 1474 if (mapped_isolate_snapshot_data == NULL) { |
| 1358 Log::PrintErr("Failed to read: %s\n", isolate_snapshot_data_filename); | 1475 Log::PrintErr("Failed to read: %s\n", isolate_snapshot_data_filename); |
| 1359 return kErrorExitCode; | 1476 return kErrorExitCode; |
| 1360 } | 1477 } |
| 1361 file->Close(); | 1478 file->Release(); |
| 1362 isolate_snapshot_data = reinterpret_cast<const uint8_t*>( | 1479 isolate_snapshot_data = reinterpret_cast<const uint8_t*>( |
| 1363 mapped_isolate_snapshot_data->address()); | 1480 mapped_isolate_snapshot_data->address()); |
| 1364 } | 1481 } |
| 1365 | 1482 |
| 1366 char* error = Dart_Initialize(&init_params); | 1483 char* error = Dart_Initialize(&init_params); |
| 1367 if (error != NULL) { | 1484 if (error != NULL) { |
| 1368 Log::PrintErr("VM initialization failed: %s\n", error); | 1485 Log::PrintErr("VM initialization failed: %s\n", error); |
| 1369 free(error); | 1486 free(error); |
| 1370 return kErrorExitCode; | 1487 return kErrorExitCode; |
| 1371 } | 1488 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1418 Dart_ExitIsolate(); | 1535 Dart_ExitIsolate(); |
| 1419 | 1536 |
| 1420 // Now we create an isolate into which we load all the code that needs to | 1537 // Now we create an isolate into which we load all the code that needs to |
| 1421 // be in the snapshot. | 1538 // be in the snapshot. |
| 1422 isolate_data = new IsolateData(NULL, NULL, NULL, NULL); | 1539 isolate_data = new IsolateData(NULL, NULL, NULL, NULL); |
| 1423 const uint8_t* kernel = NULL; | 1540 const uint8_t* kernel = NULL; |
| 1424 intptr_t kernel_length = 0; | 1541 intptr_t kernel_length = 0; |
| 1425 const bool is_kernel_file = | 1542 const bool is_kernel_file = |
| 1426 TryReadKernel(app_script_name, &kernel, &kernel_length); | 1543 TryReadKernel(app_script_name, &kernel, &kernel_length); |
| 1427 | 1544 |
| 1545 if (dependencies_filename != NULL) { | |
| 1546 isolate_data->set_dependencies(new MallocGrowableArray<char*>()); | |
| 1547 } | |
| 1548 | |
| 1428 void* kernel_program = NULL; | 1549 void* kernel_program = NULL; |
| 1429 if (is_kernel_file) { | 1550 if (is_kernel_file) { |
| 1430 kernel_program = Dart_ReadKernelBinary(kernel, kernel_length); | 1551 kernel_program = Dart_ReadKernelBinary(kernel, kernel_length); |
| 1431 free(const_cast<uint8_t*>(kernel)); | 1552 free(const_cast<uint8_t*>(kernel)); |
| 1432 } | 1553 } |
| 1433 | 1554 |
| 1434 Dart_Isolate isolate = | 1555 Dart_Isolate isolate = |
| 1435 is_kernel_file | 1556 is_kernel_file |
| 1436 ? Dart_CreateIsolateFromKernel(NULL, NULL, kernel_program, NULL, | 1557 ? Dart_CreateIsolateFromKernel(NULL, NULL, kernel_program, NULL, |
| 1437 isolate_data, &error) | 1558 isolate_data, &error) |
| 1438 : Dart_CreateIsolate(NULL, NULL, isolate_snapshot_data, NULL, NULL, | 1559 : Dart_CreateIsolate(NULL, NULL, isolate_snapshot_data, NULL, NULL, |
| 1439 isolate_data, &error); | 1560 isolate_data, &error); |
| 1440 if (isolate == NULL) { | 1561 if (isolate == NULL) { |
| 1441 Log::PrintErr("%s\n", error); | 1562 Log::PrintErr("%s\n", error); |
| 1442 free(error); | 1563 free(error); |
| 1443 exit(kErrorExitCode); | 1564 exit(kErrorExitCode); |
| 1444 } | 1565 } |
| 1445 Dart_EnterScope(); | 1566 Dart_EnterScope(); |
| 1446 result = Dart_SetEnvironmentCallback(EnvironmentCallback); | 1567 result = Dart_SetEnvironmentCallback(EnvironmentCallback); |
| 1447 CHECK_RESULT(result); | 1568 CHECK_RESULT(result); |
| 1448 | 1569 |
| 1449 // Set up the library tag handler in such a manner that it will use the | 1570 // Set up the library tag handler in such a manner that it will use the |
| 1450 // URL mapping specified on the command line to load the libraries. | 1571 // URL mapping specified on the command line to load the libraries. |
| 1451 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler); | 1572 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler); |
| 1452 CHECK_RESULT(result); | 1573 CHECK_RESULT(result); |
| 1453 | 1574 |
| 1575 if (commandline_packages_file != NULL) { | |
| 1576 AddDependency(commandline_packages_file); | |
| 1577 } | |
| 1578 | |
| 1454 Dart_QualifiedFunctionName* entry_points = | 1579 Dart_QualifiedFunctionName* entry_points = |
| 1455 ParseEntryPointsManifestIfPresent(); | 1580 ParseEntryPointsManifestIfPresent(); |
| 1456 | 1581 |
| 1457 if (is_kernel_file) { | 1582 if (is_kernel_file) { |
| 1458 Dart_Handle library = Dart_LoadKernel(kernel_program); | 1583 Dart_Handle library = Dart_LoadKernel(kernel_program); |
| 1459 if (Dart_IsError(library)) FATAL("Failed to load app from Kernel IR"); | 1584 if (Dart_IsError(library)) FATAL("Failed to load app from Kernel IR"); |
| 1460 } else { | 1585 } else { |
| 1461 // Set up the library tag handler in such a manner that it will use the | 1586 // Set up the library tag handler in such a manner that it will use the |
| 1462 // URL mapping specified on the command line to load the libraries. | 1587 // URL mapping specified on the command line to load the libraries. |
| 1463 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler); | 1588 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1474 CHECK_RESULT(library); | 1599 CHECK_RESULT(library); |
| 1475 | 1600 |
| 1476 ImportNativeEntryPointLibrariesIntoRoot(entry_points); | 1601 ImportNativeEntryPointLibrariesIntoRoot(entry_points); |
| 1477 } | 1602 } |
| 1478 | 1603 |
| 1479 // Ensure that we mark all libraries as loaded. | 1604 // Ensure that we mark all libraries as loaded. |
| 1480 result = Dart_FinalizeLoading(false); | 1605 result = Dart_FinalizeLoading(false); |
| 1481 CHECK_RESULT(result); | 1606 CHECK_RESULT(result); |
| 1482 | 1607 |
| 1483 switch (snapshot_kind) { | 1608 switch (snapshot_kind) { |
| 1609 case kNone: | |
| 1610 break; | |
| 1484 case kCore: | 1611 case kCore: |
| 1485 CreateAndWriteCoreSnapshot(); | 1612 CreateAndWriteCoreSnapshot(); |
| 1486 break; | 1613 break; |
| 1487 case kScript: | 1614 case kScript: |
| 1488 CreateAndWriteScriptSnapshot(); | 1615 CreateAndWriteScriptSnapshot(); |
| 1489 break; | 1616 break; |
| 1490 case kAppAOTBlobs: | 1617 case kAppAOTBlobs: |
| 1491 case kAppAOTAssembly: | 1618 case kAppAOTAssembly: |
| 1492 CreateAndWritePrecompiledSnapshot(entry_points); | 1619 CreateAndWritePrecompiledSnapshot(entry_points); |
| 1493 break; | 1620 break; |
| 1494 default: | 1621 default: |
| 1495 UNREACHABLE(); | 1622 UNREACHABLE(); |
| 1496 } | 1623 } |
| 1497 | 1624 |
| 1625 CreateAndWriteDependenciesFile(); | |
| 1626 | |
| 1498 Dart_ExitScope(); | 1627 Dart_ExitScope(); |
| 1499 Dart_ShutdownIsolate(); | 1628 Dart_ShutdownIsolate(); |
| 1500 | 1629 |
| 1501 CleanupEntryPointsCollection(entry_points); | 1630 CleanupEntryPointsCollection(entry_points); |
| 1502 | 1631 |
| 1503 Dart_EnterIsolate(UriResolverIsolateScope::isolate); | 1632 Dart_EnterIsolate(UriResolverIsolateScope::isolate); |
| 1504 Dart_ShutdownIsolate(); | 1633 Dart_ShutdownIsolate(); |
| 1505 } else { | 1634 } else { |
| 1506 SetupForGenericSnapshotCreation(); | 1635 SetupForGenericSnapshotCreation(); |
| 1507 CreateAndWriteCoreSnapshot(); | 1636 CreateAndWriteCoreSnapshot(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1519 delete mapped_isolate_snapshot_data; | 1648 delete mapped_isolate_snapshot_data; |
| 1520 return 0; | 1649 return 0; |
| 1521 } | 1650 } |
| 1522 | 1651 |
| 1523 } // namespace bin | 1652 } // namespace bin |
| 1524 } // namespace dart | 1653 } // namespace dart |
| 1525 | 1654 |
| 1526 int main(int argc, char** argv) { | 1655 int main(int argc, char** argv) { |
| 1527 return dart::bin::main(argc, argv); | 1656 return dart::bin::main(argc, argv); |
| 1528 } | 1657 } |
| OLD | NEW |