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

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

Issue 1903583002: GN Build fixes for Flutter + gen_snapshot fix (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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
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 23 matching lines...) Expand all
34 Dart_ShutdownIsolate(); \ 34 Dart_ShutdownIsolate(); \
35 exit(255); \ 35 exit(255); \
36 } \ 36 } \
37 37
38 38
39 // Global state that indicates whether a snapshot is to be created and 39 // Global state that indicates whether a snapshot is to be created and
40 // if so which file to write the snapshot into. 40 // if so which file to write the snapshot into.
41 static const char* vm_isolate_snapshot_filename = NULL; 41 static const char* vm_isolate_snapshot_filename = NULL;
42 static const char* isolate_snapshot_filename = NULL; 42 static const char* isolate_snapshot_filename = NULL;
43 static const char* instructions_snapshot_filename = NULL; 43 static const char* instructions_snapshot_filename = NULL;
44 static const char* embedder_entry_points_manifest = NULL;
45 static const char* package_root = NULL; 44 static const char* package_root = NULL;
46 45
47 46
48 // Global state which contains a pointer to the script name for which 47 // Global state which contains a pointer to the script name for which
49 // a snapshot needs to be created (NULL would result in the creation 48 // a snapshot needs to be created (NULL would result in the creation
50 // of a generic snapshot that contains only the corelibs). 49 // of a generic snapshot that contains only the corelibs).
51 static char* app_script_name = NULL; 50 static char* app_script_name = NULL;
52 51
53 52
54 // Global state that captures the URL mappings specified on the command line. 53 // Global state that captures the URL mappings specified on the command line.
55 static CommandLineOptions* url_mapping = NULL; 54 static CommandLineOptions* url_mapping = NULL;
56 55
56 // Global state that captures the entry point manifest files specified on the
57 // command line.
58 static CommandLineOptions* entry_points_files = NULL;
59
57 static bool IsValidFlag(const char* name, 60 static bool IsValidFlag(const char* name,
58 const char* prefix, 61 const char* prefix,
59 intptr_t prefix_length) { 62 intptr_t prefix_length) {
60 intptr_t name_length = strlen(name); 63 intptr_t name_length = strlen(name);
61 return ((name_length > prefix_length) && 64 return ((name_length > prefix_length) &&
62 (strncmp(name, prefix, prefix_length) == 0)); 65 (strncmp(name, prefix, prefix_length) == 0));
63 } 66 }
64 67
65 68
66 static const char* ProcessOption(const char* option, const char* name) { 69 static const char* ProcessOption(const char* option, const char* name) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 instructions_snapshot_filename = name; 101 instructions_snapshot_filename = name;
99 return true; 102 return true;
100 } 103 }
101 return false; 104 return false;
102 } 105 }
103 106
104 107
105 static bool ProcessEmbedderEntryPointsManifestOption(const char* option) { 108 static bool ProcessEmbedderEntryPointsManifestOption(const char* option) {
106 const char* name = ProcessOption(option, "--embedder_entry_points_manifest="); 109 const char* name = ProcessOption(option, "--embedder_entry_points_manifest=");
107 if (name != NULL) { 110 if (name != NULL) {
108 embedder_entry_points_manifest = name; 111 entry_points_files->AddArgument(name);
109 return true; 112 return true;
110 } 113 }
111 return false; 114 return false;
112 } 115 }
113 116
114 117
115 static bool ProcessPackageRootOption(const char* option) { 118 static bool ProcessPackageRootOption(const char* option) {
116 const char* name = ProcessOption(option, "--package_root="); 119 const char* name = ProcessOption(option, "--package_root=");
120 if (name == NULL) {
121 name = ProcessOption(option, "--package-root=");
122 }
117 if (name != NULL) { 123 if (name != NULL) {
118 package_root = name; 124 package_root = name;
119 return true; 125 return true;
120 } 126 }
121 return false; 127 return false;
122 } 128 }
123 129
124 130
125 static bool ProcessURLmappingOption(const char* option) { 131 static bool ProcessURLmappingOption(const char* option) {
126 const char* mapping = ProcessOption(option, "--url_mapping="); 132 const char* mapping = ProcessOption(option, "--url_mapping=");
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 Log::PrintErr("No vm isolate snapshot output file specified.\n\n"); 180 Log::PrintErr("No vm isolate snapshot output file specified.\n\n");
175 return -1; 181 return -1;
176 } 182 }
177 183
178 if (isolate_snapshot_filename == NULL) { 184 if (isolate_snapshot_filename == NULL) {
179 Log::PrintErr("No isolate snapshot output file specified.\n\n"); 185 Log::PrintErr("No isolate snapshot output file specified.\n\n");
180 return -1; 186 return -1;
181 } 187 }
182 188
183 if ((instructions_snapshot_filename != NULL) && 189 if ((instructions_snapshot_filename != NULL) &&
184 (embedder_entry_points_manifest == NULL)) { 190 (entry_points_files->count() == 0)) {
185 Log::PrintErr( 191 Log::PrintErr(
186 "Specifying an instructions snapshot filename indicates precompilation" 192 "Specifying an instructions snapshot filename indicates precompilation"
187 ". But no embedder entry points manifest was specified.\n\n"); 193 ". But no embedder entry points manifest was specified.\n\n");
188 return -1; 194 return -1;
189 } 195 }
190 196
191 if ((embedder_entry_points_manifest != NULL) && 197 if ((entry_points_files->count() > 0) &&
192 (instructions_snapshot_filename == NULL)) { 198 (instructions_snapshot_filename == NULL)) {
193 Log::PrintErr( 199 Log::PrintErr(
194 "Specifying the embedder entry points manifest indicates " 200 "Specifying the embedder entry points manifest indicates "
195 "precompilation. But no instuctions snapshot was specified.\n\n"); 201 "precompilation. But no instuctions snapshot was specified.\n\n");
196 return -1; 202 return -1;
197 } 203 }
198 204
199 return 0; 205 return 0;
200 } 206 }
201 207
202 208
203 static bool IsSnapshottingForPrecompilation(void) { 209 static bool IsSnapshottingForPrecompilation(void) {
204 return embedder_entry_points_manifest != NULL && 210 return (entry_points_files->count() > 0) &&
205 instructions_snapshot_filename != NULL; 211 (instructions_snapshot_filename != NULL);
206 } 212 }
207 213
208 214
209 static void WriteSnapshotFile(const char* filename, 215 static void WriteSnapshotFile(const char* filename,
210 const uint8_t* buffer, 216 const uint8_t* buffer,
211 const intptr_t size) { 217 const intptr_t size) {
212 File* file = File::Open(filename, File::kWriteTruncate); 218 File* file = File::Open(filename, File::kWriteTruncate);
213 ASSERT(file != NULL); 219 ASSERT(file != NULL);
214 if (!file->WriteFully(buffer, size)) { 220 if (!file->WriteFully(buffer, size)) {
215 Log::PrintErr("Error: Failed to write snapshot file.\n\n"); 221 Log::PrintErr("Error: Failed to write snapshot file.\n\n");
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 780
775 entries++; 781 entries++;
776 } 782 }
777 783
778 free(line); 784 free(line);
779 785
780 return entries; 786 return entries;
781 } 787 }
782 788
783 789
784 static Dart_QualifiedFunctionName* ParseEntryPointsManifestFile( 790 static Dart_QualifiedFunctionName* ParseEntryPointsManifestFiles() {
785 const char* path) { 791 // Total number of entries across all manifest files.
786 if (path == NULL) { 792 int64_t entry_count = 0;
787 return NULL; 793
794 // Parse the files once but don't store the results. This is done to first
795 // determine the number of entries in the manifest
796 for (intptr_t i = 0; i < entry_points_files->count(); i++) {
797 const char* path = entry_points_files->GetArgument(i);
798
799 FILE* file = fopen(path, "r");
800
801 if (file == NULL) {
802 Log::PrintErr("Could not open entry points manifest file `%s`\n", path);
803 return NULL;
804 }
805
806 int64_t entries = ParseEntryPointsManifestLines(file, NULL);
807 fclose(file);
808
809 if (entries <= 0) {
810 Log::PrintErr(
811 "Manifest file `%s` specified is invalid or contained no entries\n",
812 path);
813 return NULL;
814 }
815
816 entry_count += entries;
788 } 817 }
789 818
790 FILE* file = fopen(path, "r");
791
792 if (file == NULL) {
793 Log::PrintErr("Could not open entry points manifest file\n");
794 return NULL;
795 }
796
797 // Parse the file once but don't store the results. This is done to first
798 // determine the number of entries in the manifest
799 int64_t entry_count = ParseEntryPointsManifestLines(file, NULL);
800
801 if (entry_count <= 0) {
802 Log::PrintErr(
803 "Manifest file specified is invalid or contained no entries\n");
804 fclose(file);
805 return NULL;
806 }
807
808 rewind(file);
809
810 // Allocate enough storage for the entries in the file plus a termination 819 // Allocate enough storage for the entries in the file plus a termination
811 // sentinel and parse it again to populate the allocation 820 // sentinel and parse it again to populate the allocation
812 Dart_QualifiedFunctionName* entries = 821 Dart_QualifiedFunctionName* entries =
813 reinterpret_cast<Dart_QualifiedFunctionName*>( 822 reinterpret_cast<Dart_QualifiedFunctionName*>(
814 calloc(entry_count + 1, sizeof(Dart_QualifiedFunctionName))); 823 calloc(entry_count + 1, sizeof(Dart_QualifiedFunctionName)));
815 824
816 int64_t parsed_entry_count = ParseEntryPointsManifestLines(file, entries); 825 int64_t parsed_entry_count = 0;
826 for (intptr_t i = 0; i < entry_points_files->count(); i++) {
827 const char* path = entry_points_files->GetArgument(i);
828 FILE* file = fopen(path, "r");
829 parsed_entry_count +=
830 ParseEntryPointsManifestLines(file, &entries[parsed_entry_count]);
831 fclose(file);
832 }
833
817 ASSERT(parsed_entry_count == entry_count); 834 ASSERT(parsed_entry_count == entry_count);
818 835
819 fclose(file);
820
821 // The entries allocation must be explicitly cleaned up via 836 // The entries allocation must be explicitly cleaned up via
822 // |CleanupEntryPointsCollection| 837 // |CleanupEntryPointsCollection|
823 return entries; 838 return entries;
824 } 839 }
825 840
826 841
827 static Dart_QualifiedFunctionName* ParseEntryPointsManifestIfPresent() { 842 static Dart_QualifiedFunctionName* ParseEntryPointsManifestIfPresent() {
828 Dart_QualifiedFunctionName* entries = 843 Dart_QualifiedFunctionName* entries = ParseEntryPointsManifestFiles();
829 ParseEntryPointsManifestFile(embedder_entry_points_manifest);
830 if ((entries == NULL) && IsSnapshottingForPrecompilation()) { 844 if ((entries == NULL) && IsSnapshottingForPrecompilation()) {
831 Log::PrintErr( 845 Log::PrintErr(
832 "Could not find native embedder entry points during precompilation\n"); 846 "Could not find native embedder entry points during precompilation\n");
833 exit(255); 847 exit(255);
834 } 848 }
835 return entries; 849 return entries;
836 } 850 }
837 851
838 852
839 static void CreateAndWriteSnapshot() { 853 static void CreateAndWriteSnapshot() {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 1005
992 1006
993 int main(int argc, char** argv) { 1007 int main(int argc, char** argv) {
994 const int EXTRA_VM_ARGUMENTS = 2; 1008 const int EXTRA_VM_ARGUMENTS = 2;
995 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); 1009 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS);
996 1010
997 // Initialize the URL mapping array. 1011 // Initialize the URL mapping array.
998 CommandLineOptions url_mapping_array(argc); 1012 CommandLineOptions url_mapping_array(argc);
999 url_mapping = &url_mapping_array; 1013 url_mapping = &url_mapping_array;
1000 1014
1015 // Initialize the entrypoints array.
1016 CommandLineOptions entry_points_files_array(argc);
1017 entry_points_files = &entry_points_files_array;
1018
1001 // Parse command line arguments. 1019 // Parse command line arguments.
1002 if (ParseArguments(argc, 1020 if (ParseArguments(argc,
1003 argv, 1021 argv,
1004 &vm_options, 1022 &vm_options,
1005 &app_script_name) < 0) { 1023 &app_script_name) < 0) {
1006 PrintUsage(); 1024 PrintUsage();
1007 return 255; 1025 return 255;
1008 } 1026 }
1009 1027
1010 Thread::InitOnce(); 1028 Thread::InitOnce();
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 EventHandler::Stop(); 1170 EventHandler::Stop();
1153 return 0; 1171 return 0;
1154 } 1172 }
1155 1173
1156 } // namespace bin 1174 } // namespace bin
1157 } // namespace dart 1175 } // namespace dart
1158 1176
1159 int main(int argc, char** argv) { 1177 int main(int argc, char** argv) {
1160 return dart::bin::main(argc, argv); 1178 return dart::bin::main(argc, argv);
1161 } 1179 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698