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

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

Issue 2730943003: Add --print-dependencies to gen_snapshot (Closed)
Patch Set: review comments Created 3 years, 9 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 | « no previous file | no next file » | 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>
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 kAppAOTAssembly, 73 kAppAOTAssembly,
74 }; 74 };
75 static SnapshotKind snapshot_kind = kCore; 75 static SnapshotKind snapshot_kind = kCore;
76 static const char* vm_snapshot_data_filename = NULL; 76 static const char* vm_snapshot_data_filename = NULL;
77 static const char* vm_snapshot_instructions_filename = NULL; 77 static const char* vm_snapshot_instructions_filename = NULL;
78 static const char* isolate_snapshot_data_filename = NULL; 78 static const char* isolate_snapshot_data_filename = NULL;
79 static const char* isolate_snapshot_instructions_filename = NULL; 79 static const char* isolate_snapshot_instructions_filename = NULL;
80 static const char* assembly_filename = NULL; 80 static const char* assembly_filename = NULL;
81 static const char* script_snapshot_filename = NULL; 81 static const char* script_snapshot_filename = NULL;
82 static bool dependencies_only = false; 82 static bool dependencies_only = false;
83 static bool print_dependencies = false;
83 static const char* dependencies_filename = NULL; 84 static const char* dependencies_filename = NULL;
84 85
85 86
86 // Value of the --package-root flag. 87 // Value of the --package-root flag.
87 // (This pointer points into an argv buffer and does not need to be 88 // (This pointer points into an argv buffer and does not need to be
88 // free'd.) 89 // free'd.)
89 static const char* commandline_package_root = NULL; 90 static const char* commandline_package_root = NULL;
90 91
91 // Value of the --packages flag. 92 // Value of the --packages flag.
92 // (This pointer points into an argv buffer and does not need to be 93 // (This pointer points into an argv buffer and does not need to be
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 if (name == NULL) { 325 if (name == NULL) {
325 name = ProcessOption(option, "--dependencies-only"); 326 name = ProcessOption(option, "--dependencies-only");
326 } 327 }
327 if (name != NULL) { 328 if (name != NULL) {
328 dependencies_only = true; 329 dependencies_only = true;
329 return true; 330 return true;
330 } 331 }
331 return false; 332 return false;
332 } 333 }
333 334
335 static bool ProcessPrintDependenciesOption(const char* option) {
336 const char* name = ProcessOption(option, "--print_dependencies");
337 if (name == NULL) {
338 name = ProcessOption(option, "--print-dependencies");
339 }
340 if (name != NULL) {
341 print_dependencies = true;
342 return true;
343 }
344 return false;
345 }
334 346
335 static bool ProcessEmbedderEntryPointsManifestOption(const char* option) { 347 static bool ProcessEmbedderEntryPointsManifestOption(const char* option) {
336 const char* name = ProcessOption(option, "--embedder_entry_points_manifest="); 348 const char* name = ProcessOption(option, "--embedder_entry_points_manifest=");
337 if (name != NULL) { 349 if (name != NULL) {
338 entry_points_files->AddArgument(name); 350 entry_points_files->AddArgument(name);
339 return true; 351 return true;
340 } 352 }
341 return false; 353 return false;
342 } 354 }
343 355
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 while ((i < argc) && IsValidFlag(argv[i], kPrefix, kPrefixLen)) { 411 while ((i < argc) && IsValidFlag(argv[i], kPrefix, kPrefixLen)) {
400 if (ProcessSnapshotKindOption(argv[i]) || 412 if (ProcessSnapshotKindOption(argv[i]) ||
401 ProcessVmSnapshotDataOption(argv[i]) || 413 ProcessVmSnapshotDataOption(argv[i]) ||
402 ProcessVmSnapshotInstructionsOption(argv[i]) || 414 ProcessVmSnapshotInstructionsOption(argv[i]) ||
403 ProcessIsolateSnapshotDataOption(argv[i]) || 415 ProcessIsolateSnapshotDataOption(argv[i]) ||
404 ProcessIsolateSnapshotInstructionsOption(argv[i]) || 416 ProcessIsolateSnapshotInstructionsOption(argv[i]) ||
405 ProcessAssemblyOption(argv[i]) || 417 ProcessAssemblyOption(argv[i]) ||
406 ProcessScriptSnapshotOption(argv[i]) || 418 ProcessScriptSnapshotOption(argv[i]) ||
407 ProcessDependenciesOption(argv[i]) || 419 ProcessDependenciesOption(argv[i]) ||
408 ProcessDependenciesOnlyOption(argv[i]) || 420 ProcessDependenciesOnlyOption(argv[i]) ||
421 ProcessPrintDependenciesOption(argv[i]) ||
409 ProcessEmbedderEntryPointsManifestOption(argv[i]) || 422 ProcessEmbedderEntryPointsManifestOption(argv[i]) ||
410 ProcessURLmappingOption(argv[i]) || ProcessPackageRootOption(argv[i]) || 423 ProcessURLmappingOption(argv[i]) || ProcessPackageRootOption(argv[i]) ||
411 ProcessPackagesOption(argv[i]) || ProcessEnvironmentOption(argv[i])) { 424 ProcessPackagesOption(argv[i]) || ProcessEnvironmentOption(argv[i])) {
412 i += 1; 425 i += 1;
413 continue; 426 continue;
414 } 427 }
415 vm_options->AddArgument(argv[i]); 428 vm_options->AddArgument(argv[i]);
416 i += 1; 429 i += 1;
417 } 430 }
418 431
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 679
667 680
668 static void CreateAndWriteDependenciesFile() { 681 static void CreateAndWriteDependenciesFile() {
669 IsolateData* isolate_data = 682 IsolateData* isolate_data =
670 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); 683 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData());
671 MallocGrowableArray<char*>* dependencies = isolate_data->dependencies(); 684 MallocGrowableArray<char*>* dependencies = isolate_data->dependencies();
672 if (dependencies == NULL) { 685 if (dependencies == NULL) {
673 return; 686 return;
674 } 687 }
675 688
676 ASSERT(dependencies_filename != NULL); 689 ASSERT((dependencies_filename != NULL) || print_dependencies);
677 File* file = File::Open(dependencies_filename, File::kWriteTruncate); 690 bool success = true;
678 if (file == NULL) { 691 File* file = NULL;
679 Log::PrintErr("Error: Unable to open dependencies file: %s\n\n", 692 if (dependencies_filename != NULL) {
680 dependencies_filename); 693 file = File::Open(dependencies_filename, File::kWriteTruncate);
681 exit(kErrorExitCode); 694 if (file == NULL) {
695 Log::PrintErr("Error: Unable to open dependencies file: %s\n\n",
696 dependencies_filename);
697 exit(kErrorExitCode);
698 }
699
700 // Targets:
701 switch (snapshot_kind) {
702 case kCore:
703 success &= file->Print("%s ", vm_snapshot_data_filename);
704 success &= file->Print("%s ", isolate_snapshot_data_filename);
705 break;
706 case kScript:
707 success &= file->Print("%s ", script_snapshot_filename);
708 break;
709 case kAppAOTAssembly:
710 success &= file->Print("%s ", assembly_filename);
711 break;
712 case kAppAOTBlobs:
713 success &= file->Print("%s ", vm_snapshot_data_filename);
714 success &= file->Print("%s ", vm_snapshot_instructions_filename);
715 success &= file->Print("%s ", isolate_snapshot_data_filename);
716 success &= file->Print("%s ", isolate_snapshot_instructions_filename);
717 break;
718 }
719
720 success &= file->Print(": ");
682 } 721 }
683 bool success = true;
684
685 // Targets:
686 switch (snapshot_kind) {
687 case kCore:
688 success &= file->Print("%s ", vm_snapshot_data_filename);
689 success &= file->Print("%s ", isolate_snapshot_data_filename);
690 break;
691 case kScript:
692 success &= file->Print("%s ", script_snapshot_filename);
693 break;
694 case kAppAOTAssembly:
695 success &= file->Print("%s ", assembly_filename);
696 break;
697 case kAppAOTBlobs:
698 success &= file->Print("%s ", vm_snapshot_data_filename);
699 success &= file->Print("%s ", vm_snapshot_instructions_filename);
700 success &= file->Print("%s ", isolate_snapshot_data_filename);
701 success &= file->Print("%s ", isolate_snapshot_instructions_filename);
702 break;
703 }
704
705 success &= file->Print(": ");
706 722
707 // Sources: 723 // Sources:
708 if (snapshot_kind == kScript) { 724 if (snapshot_kind == kScript) {
709 success &= file->Print("%s ", vm_snapshot_data_filename); 725 if (dependencies_filename != NULL) {
710 success &= file->Print("%s ", isolate_snapshot_data_filename); 726 success &= file->Print("%s ", vm_snapshot_data_filename);
727 success &= file->Print("%s ", isolate_snapshot_data_filename);
728 }
729 if (print_dependencies) {
730 Log::Print("%s\n", vm_snapshot_data_filename);
731 Log::Print("%s\n", isolate_snapshot_data_filename);
732 }
711 } 733 }
712 for (intptr_t i = 0; i < dependencies->length(); i++) { 734 for (intptr_t i = 0; i < dependencies->length(); i++) {
713 char* dep = dependencies->At(i); 735 char* dep = dependencies->At(i);
714 success &= file->Print("%s ", dep); 736 if (dependencies_filename != NULL) {
737 success &= file->Print("%s ", dep);
738 }
739 if (print_dependencies) {
740 Log::Print("%s\n", dep);
741 }
715 free(dep); 742 free(dep);
716 } 743 }
717 success &= file->Print("\n");
718 744
719 if (!success) { 745 if (dependencies_filename != NULL) {
720 Log::PrintErr("Error: Unable to write dependencies file: %s\n\n", 746 success &= file->Print("\n");
721 dependencies_filename); 747
722 exit(kErrorExitCode); 748 if (!success) {
749 Log::PrintErr("Error: Unable to write dependencies file: %s\n\n",
750 dependencies_filename);
751 exit(kErrorExitCode);
752 }
753 file->Release();
723 } 754 }
724 file->Release();
725 delete dependencies; 755 delete dependencies;
726 isolate_data->set_dependencies(NULL); 756 isolate_data->set_dependencies(NULL);
727 } 757 }
728 758
729 759
730 static Dart_Handle CreateSnapshotLibraryTagHandler(Dart_LibraryTag tag, 760 static Dart_Handle CreateSnapshotLibraryTagHandler(Dart_LibraryTag tag,
731 Dart_Handle library, 761 Dart_Handle library,
732 Dart_Handle url) { 762 Dart_Handle url) {
733 if (!Dart_IsLibrary(library)) { 763 if (!Dart_IsLibrary(library)) {
734 return Dart_NewApiError("not a library"); 764 return Dart_NewApiError("not a library");
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 " package:... imports. \n" 862 " package:... imports. \n"
833 " \n" 863 " \n"
834 " --packages=<packages_file> Where to find a package spec file \n" 864 " --packages=<packages_file> Where to find a package spec file \n"
835 " \n" 865 " \n"
836 " --url_mapping=<mapping> Uses the URL mapping(s) specified on \n" 866 " --url_mapping=<mapping> Uses the URL mapping(s) specified on \n"
837 " the command line to load the \n" 867 " the command line to load the \n"
838 " libraries. \n" 868 " libraries. \n"
839 " --dependencies=<output-file> Generates a Makefile with snapshot output \n" 869 " --dependencies=<output-file> Generates a Makefile with snapshot output \n"
840 " files as targets and all transitive imports\n" 870 " files as targets and all transitive imports\n"
841 " as sources. \n" 871 " as sources. \n"
872 " --print_dependencies Prints all transitive imports to stdout. \n"
842 " --dependencies_only Don't create and output the snapshot. \n" 873 " --dependencies_only Don't create and output the snapshot. \n"
843 " \n" 874 " \n"
844 " To create a core snapshot: \n" 875 " To create a core snapshot: \n"
845 " --snapshot_kind=core \n" 876 " --snapshot_kind=core \n"
846 " --vm_snapshot_data=<output-file> \n" 877 " --vm_snapshot_data=<output-file> \n"
847 " --isolate_snapshot_data=<output-file> \n" 878 " --isolate_snapshot_data=<output-file> \n"
848 " [<dart-script-file>] \n" 879 " [<dart-script-file>] \n"
849 " \n" 880 " \n"
850 " Writes a snapshot of <dart-script-file> to the specified snapshot files. \n" 881 " Writes a snapshot of <dart-script-file> to the specified snapshot files. \n"
851 " If no <dart-script-file> is passed, a generic snapshot of all the corelibs \n" 882 " If no <dart-script-file> is passed, a generic snapshot of all the corelibs \n"
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
1558 Dart_ExitIsolate(); 1589 Dart_ExitIsolate();
1559 1590
1560 // Now we create an isolate into which we load all the code that needs to 1591 // Now we create an isolate into which we load all the code that needs to
1561 // be in the snapshot. 1592 // be in the snapshot.
1562 isolate_data = new IsolateData(NULL, NULL, NULL, NULL); 1593 isolate_data = new IsolateData(NULL, NULL, NULL, NULL);
1563 const uint8_t* kernel = NULL; 1594 const uint8_t* kernel = NULL;
1564 intptr_t kernel_length = 0; 1595 intptr_t kernel_length = 0;
1565 const bool is_kernel_file = 1596 const bool is_kernel_file =
1566 TryReadKernel(app_script_name, &kernel, &kernel_length); 1597 TryReadKernel(app_script_name, &kernel, &kernel_length);
1567 1598
1568 if (dependencies_filename != NULL) { 1599 if ((dependencies_filename != NULL) || print_dependencies) {
1569 isolate_data->set_dependencies(new MallocGrowableArray<char*>()); 1600 isolate_data->set_dependencies(new MallocGrowableArray<char*>());
1570 } 1601 }
1571 1602
1572 void* kernel_program = NULL; 1603 void* kernel_program = NULL;
1573 if (is_kernel_file) { 1604 if (is_kernel_file) {
1574 kernel_program = Dart_ReadKernelBinary(kernel, kernel_length); 1605 kernel_program = Dart_ReadKernelBinary(kernel, kernel_length);
1575 free(const_cast<uint8_t*>(kernel)); 1606 free(const_cast<uint8_t*>(kernel));
1576 } 1607 }
1577 1608
1578 Dart_Isolate isolate = 1609 Dart_Isolate isolate =
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1671 delete mapped_isolate_snapshot_data; 1702 delete mapped_isolate_snapshot_data;
1672 return 0; 1703 return 0;
1673 } 1704 }
1674 1705
1675 } // namespace bin 1706 } // namespace bin
1676 } // namespace dart 1707 } // namespace dart
1677 1708
1678 int main(int argc, char** argv) { 1709 int main(int argc, char** argv) {
1679 return dart::bin::main(argc, argv); 1710 return dart::bin::main(argc, argv);
1680 } 1711 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698