| 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> |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 private: | 549 private: |
| 550 Dart_Isolate snapshotted_isolate_; | 550 Dart_Isolate snapshotted_isolate_; |
| 551 | 551 |
| 552 DISALLOW_COPY_AND_ASSIGN(UriResolverIsolateScope); | 552 DISALLOW_COPY_AND_ASSIGN(UriResolverIsolateScope); |
| 553 }; | 553 }; |
| 554 | 554 |
| 555 | 555 |
| 556 Dart_Isolate UriResolverIsolateScope::isolate = NULL; | 556 Dart_Isolate UriResolverIsolateScope::isolate = NULL; |
| 557 | 557 |
| 558 | 558 |
| 559 static char* ResolveAsFilePath(const char* uri_string) { | |
| 560 UriResolverIsolateScope scope; | |
| 561 uint8_t* scoped_file_path = NULL; | |
| 562 intptr_t scoped_file_path_length = -1; | |
| 563 Dart_Handle uri = Dart_NewStringFromCString(uri_string); | |
| 564 ASSERT(!Dart_IsError(uri)); | |
| 565 Dart_Handle result = Loader::ResolveAsFilePath(uri, &scoped_file_path, | |
| 566 &scoped_file_path_length); | |
| 567 if (Dart_IsError(result)) { | |
| 568 Log::Print("Error resolving dependency: %s\n", Dart_GetError(result)); | |
| 569 exit(kErrorExitCode); | |
| 570 } | |
| 571 return StringUtils::StrNDup(reinterpret_cast<const char*>(scoped_file_path), | |
| 572 scoped_file_path_length); | |
| 573 } | |
| 574 | |
| 575 | |
| 576 static void AddDependency(const char* uri_string) { | 559 static void AddDependency(const char* uri_string) { |
| 577 IsolateData* isolate_data = | 560 IsolateData* isolate_data = |
| 578 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); | 561 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); |
| 579 MallocGrowableArray<char*>* dependencies = isolate_data->dependencies(); | 562 MallocGrowableArray<char*>* dependencies = isolate_data->dependencies(); |
| 580 if (dependencies != NULL) { | 563 if (dependencies != NULL) { |
| 581 dependencies->Add(ResolveAsFilePath(uri_string)); | 564 dependencies->Add(strdup(uri_string)); |
| 582 } | 565 } |
| 583 } | 566 } |
| 584 | 567 |
| 585 | 568 |
| 586 static Dart_Handle LoadUrlContents(const char* uri_string) { | 569 static Dart_Handle LoadUrlContents(const char* uri_string) { |
| 587 bool failed = false; | 570 bool failed = false; |
| 588 char* error_string = NULL; | 571 char* error_string = NULL; |
| 589 uint8_t* payload = NULL; | 572 uint8_t* payload = NULL; |
| 590 intptr_t payload_length = 0; | 573 intptr_t payload_length = 0; |
| 591 // Switch to the UriResolver Isolate and load the script. | 574 // Switch to the UriResolver Isolate and load the script. |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 | 658 |
| 676 | 659 |
| 677 static void CreateAndWriteDependenciesFile() { | 660 static void CreateAndWriteDependenciesFile() { |
| 678 IsolateData* isolate_data = | 661 IsolateData* isolate_data = |
| 679 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); | 662 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); |
| 680 MallocGrowableArray<char*>* dependencies = isolate_data->dependencies(); | 663 MallocGrowableArray<char*>* dependencies = isolate_data->dependencies(); |
| 681 if (dependencies == NULL) { | 664 if (dependencies == NULL) { |
| 682 return; | 665 return; |
| 683 } | 666 } |
| 684 | 667 |
| 668 Loader::ResolveDependenciesAsFilePaths(); |
| 669 |
| 685 ASSERT((dependencies_filename != NULL) || print_dependencies); | 670 ASSERT((dependencies_filename != NULL) || print_dependencies); |
| 686 bool success = true; | 671 bool success = true; |
| 687 File* file = NULL; | 672 File* file = NULL; |
| 688 if (dependencies_filename != NULL) { | 673 if (dependencies_filename != NULL) { |
| 689 file = File::Open(dependencies_filename, File::kWriteTruncate); | 674 file = File::Open(dependencies_filename, File::kWriteTruncate); |
| 690 if (file == NULL) { | 675 if (file == NULL) { |
| 691 Log::PrintErr("Error: Unable to open dependencies file: %s\n\n", | 676 Log::PrintErr("Error: Unable to open dependencies file: %s\n\n", |
| 692 dependencies_filename); | 677 dependencies_filename); |
| 693 exit(kErrorExitCode); | 678 exit(kErrorExitCode); |
| 694 } | 679 } |
| (...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1543 exit(kErrorExitCode); | 1528 exit(kErrorExitCode); |
| 1544 } | 1529 } |
| 1545 | 1530 |
| 1546 Dart_Handle result; | 1531 Dart_Handle result; |
| 1547 Dart_Handle library; | 1532 Dart_Handle library; |
| 1548 Dart_EnterScope(); | 1533 Dart_EnterScope(); |
| 1549 | 1534 |
| 1550 result = Dart_SetEnvironmentCallback(EnvironmentCallback); | 1535 result = Dart_SetEnvironmentCallback(EnvironmentCallback); |
| 1551 CHECK_RESULT(result); | 1536 CHECK_RESULT(result); |
| 1552 | 1537 |
| 1553 ASSERT(vm_snapshot_data_filename != NULL); | |
| 1554 ASSERT(isolate_snapshot_data_filename != NULL); | |
| 1555 // Load up the script before a snapshot is created. | 1538 // Load up the script before a snapshot is created. |
| 1556 if (app_script_name != NULL) { | 1539 if (app_script_name != NULL) { |
| 1557 // This is the case of a custom embedder (e.g: dartium) trying to | 1540 // This is the case of a custom embedder (e.g: dartium) trying to |
| 1558 // create a full snapshot. The current isolate is set up so that we can | 1541 // create a full snapshot. The current isolate is set up so that we can |
| 1559 // invoke the dart uri resolution code like _resolveURI. App script is | 1542 // invoke the dart uri resolution code like _resolveURI. App script is |
| 1560 // loaded into a separate isolate. | 1543 // loaded into a separate isolate. |
| 1561 SetupForUriResolution(); | 1544 SetupForUriResolution(); |
| 1562 | 1545 |
| 1563 // Prepare builtin and its dependent libraries for use to resolve URIs. | 1546 // Prepare builtin and its dependent libraries for use to resolve URIs. |
| 1564 // Set up various closures, e.g: printing, timers etc. | 1547 // Set up various closures, e.g: printing, timers etc. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1575 result = DartUtils::SetupPackageRoot(commandline_package_root, | 1558 result = DartUtils::SetupPackageRoot(commandline_package_root, |
| 1576 commandline_packages_file); | 1559 commandline_packages_file); |
| 1577 CHECK_RESULT(result); | 1560 CHECK_RESULT(result); |
| 1578 | 1561 |
| 1579 UriResolverIsolateScope::isolate = isolate; | 1562 UriResolverIsolateScope::isolate = isolate; |
| 1580 Dart_ExitScope(); | 1563 Dart_ExitScope(); |
| 1581 Dart_ExitIsolate(); | 1564 Dart_ExitIsolate(); |
| 1582 | 1565 |
| 1583 // Now we create an isolate into which we load all the code that needs to | 1566 // Now we create an isolate into which we load all the code that needs to |
| 1584 // be in the snapshot. | 1567 // be in the snapshot. |
| 1585 isolate_data = new IsolateData(NULL, NULL, NULL, NULL); | 1568 isolate_data = new IsolateData(app_script_name, commandline_package_root, |
| 1569 commandline_packages_file, NULL); |
| 1586 const uint8_t* kernel = NULL; | 1570 const uint8_t* kernel = NULL; |
| 1587 intptr_t kernel_length = 0; | 1571 intptr_t kernel_length = 0; |
| 1588 const bool is_kernel_file = | 1572 const bool is_kernel_file = |
| 1589 TryReadKernel(app_script_name, &kernel, &kernel_length); | 1573 TryReadKernel(app_script_name, &kernel, &kernel_length); |
| 1590 | 1574 |
| 1591 if ((dependencies_filename != NULL) || print_dependencies) { | 1575 if ((dependencies_filename != NULL) || print_dependencies) { |
| 1592 isolate_data->set_dependencies(new MallocGrowableArray<char*>()); | 1576 isolate_data->set_dependencies(new MallocGrowableArray<char*>()); |
| 1593 } | 1577 } |
| 1594 | 1578 |
| 1595 void* kernel_program = NULL; | 1579 void* kernel_program = NULL; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1694 delete mapped_isolate_snapshot_data; | 1678 delete mapped_isolate_snapshot_data; |
| 1695 return 0; | 1679 return 0; |
| 1696 } | 1680 } |
| 1697 | 1681 |
| 1698 } // namespace bin | 1682 } // namespace bin |
| 1699 } // namespace dart | 1683 } // namespace dart |
| 1700 | 1684 |
| 1701 int main(int argc, char** argv) { | 1685 int main(int argc, char** argv) { |
| 1702 return dart::bin::main(argc, argv); | 1686 return dart::bin::main(argc, argv); |
| 1703 } | 1687 } |
| OLD | NEW |