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

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=");
117 if (name != NULL) { 120 if (name != NULL) {
118 package_root = name; 121 package_root = name;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 Log::PrintErr("No vm isolate snapshot output file specified.\n\n"); 177 Log::PrintErr("No vm isolate snapshot output file specified.\n\n");
175 return -1; 178 return -1;
176 } 179 }
177 180
178 if (isolate_snapshot_filename == NULL) { 181 if (isolate_snapshot_filename == NULL) {
179 Log::PrintErr("No isolate snapshot output file specified.\n\n"); 182 Log::PrintErr("No isolate snapshot output file specified.\n\n");
180 return -1; 183 return -1;
181 } 184 }
182 185
183 if ((instructions_snapshot_filename != NULL) && 186 if ((instructions_snapshot_filename != NULL) &&
184 (embedder_entry_points_manifest == NULL)) { 187 (entry_points_files->count() == 0)) {
185 Log::PrintErr( 188 Log::PrintErr(
186 "Specifying an instructions snapshot filename indicates precompilation" 189 "Specifying an instructions snapshot filename indicates precompilation"
187 ". But no embedder entry points manifest was specified.\n\n"); 190 ". But no embedder entry points manifest was specified.\n\n");
188 return -1; 191 return -1;
189 } 192 }
190 193
191 if ((embedder_entry_points_manifest != NULL) && 194 if ((entry_points_files->count() > 0) &&
192 (instructions_snapshot_filename == NULL)) { 195 (instructions_snapshot_filename == NULL)) {
193 Log::PrintErr( 196 Log::PrintErr(
194 "Specifying the embedder entry points manifest indicates " 197 "Specifying the embedder entry points manifest indicates "
195 "precompilation. But no instuctions snapshot was specified.\n\n"); 198 "precompilation. But no instuctions snapshot was specified.\n\n");
196 return -1; 199 return -1;
197 } 200 }
198 201
199 return 0; 202 return 0;
200 } 203 }
201 204
202 205
203 static bool IsSnapshottingForPrecompilation(void) { 206 static bool IsSnapshottingForPrecompilation(void) {
204 return embedder_entry_points_manifest != NULL && 207 return (entry_points_files->count() > 0) &&
205 instructions_snapshot_filename != NULL; 208 (instructions_snapshot_filename != NULL);
206 } 209 }
207 210
208 211
209 static void WriteSnapshotFile(const char* filename, 212 static void WriteSnapshotFile(const char* filename,
210 const uint8_t* buffer, 213 const uint8_t* buffer,
211 const intptr_t size) { 214 const intptr_t size) {
212 File* file = File::Open(filename, File::kWriteTruncate); 215 File* file = File::Open(filename, File::kWriteTruncate);
213 ASSERT(file != NULL); 216 ASSERT(file != NULL);
214 if (!file->WriteFully(buffer, size)) { 217 if (!file->WriteFully(buffer, size)) {
215 Log::PrintErr("Error: Failed to write snapshot file.\n\n"); 218 Log::PrintErr("Error: Failed to write snapshot file.\n\n");
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 777
775 entries++; 778 entries++;
776 } 779 }
777 780
778 free(line); 781 free(line);
779 782
780 return entries; 783 return entries;
781 } 784 }
782 785
783 786
784 static Dart_QualifiedFunctionName* ParseEntryPointsManifestFile( 787 static Dart_QualifiedFunctionName* ParseEntryPointsManifestFiles() {
785 const char* path) { 788 // Total number of entries across all manifest files.
786 if (path == NULL) { 789 int64_t entry_count = 0;
Florian Schneider 2016/04/19 22:05:23 intptr_t
787 return NULL; 790
791 // Parse the files once but don't store the results. This is done to first
792 // determine the number of entries in the manifest
793 for (intptr_t i = 0; i < entry_points_files->count(); i++) {
794 const char* path = entry_points_files->GetArgument(i);
795
796 FILE* file = fopen(path, "r");
797
798 if (file == NULL) {
799 Log::PrintErr("Could not open entry points manifest file `%s`\n", path);
800 return NULL;
801 }
802
803 int64_t entries = ParseEntryPointsManifestLines(file, NULL);
Florian Schneider 2016/04/19 22:05:23 intptr_t
804 fclose(file);
805
806 if (entries <= 0) {
807 Log::PrintErr(
808 "Manifest file `%s` specified is invalid or contained no entries\n",
809 path);
810 return NULL;
811 }
812
813 entry_count += entries;
788 } 814 }
789 815
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 816 // Allocate enough storage for the entries in the file plus a termination
811 // sentinel and parse it again to populate the allocation 817 // sentinel and parse it again to populate the allocation
812 Dart_QualifiedFunctionName* entries = 818 Dart_QualifiedFunctionName* entries =
813 reinterpret_cast<Dart_QualifiedFunctionName*>( 819 reinterpret_cast<Dart_QualifiedFunctionName*>(
814 calloc(entry_count + 1, sizeof(Dart_QualifiedFunctionName))); 820 calloc(entry_count + 1, sizeof(Dart_QualifiedFunctionName)));
815 821
816 int64_t parsed_entry_count = ParseEntryPointsManifestLines(file, entries); 822 int64_t parsed_entry_count = 0;
Florian Schneider 2016/04/19 22:05:23 intptr_t
823 for (intptr_t i = 0; i < entry_points_files->count(); i++) {
824 const char* path = entry_points_files->GetArgument(i);
825 FILE* file = fopen(path, "r");
Florian Schneider 2016/04/19 22:05:23 Check return value of fopen.
826 parsed_entry_count +=
827 ParseEntryPointsManifestLines(file, &entries[parsed_entry_count]);
828 fclose(file);
829 }
830
817 ASSERT(parsed_entry_count == entry_count); 831 ASSERT(parsed_entry_count == entry_count);
818 832
819 fclose(file);
820
821 // The entries allocation must be explicitly cleaned up via 833 // The entries allocation must be explicitly cleaned up via
822 // |CleanupEntryPointsCollection| 834 // |CleanupEntryPointsCollection|
823 return entries; 835 return entries;
824 } 836 }
825 837
826 838
827 static Dart_QualifiedFunctionName* ParseEntryPointsManifestIfPresent() { 839 static Dart_QualifiedFunctionName* ParseEntryPointsManifestIfPresent() {
828 Dart_QualifiedFunctionName* entries = 840 Dart_QualifiedFunctionName* entries = ParseEntryPointsManifestFiles();
829 ParseEntryPointsManifestFile(embedder_entry_points_manifest);
830 if ((entries == NULL) && IsSnapshottingForPrecompilation()) { 841 if ((entries == NULL) && IsSnapshottingForPrecompilation()) {
831 Log::PrintErr( 842 Log::PrintErr(
832 "Could not find native embedder entry points during precompilation\n"); 843 "Could not find native embedder entry points during precompilation\n");
833 exit(255); 844 exit(255);
834 } 845 }
835 return entries; 846 return entries;
836 } 847 }
837 848
838 849
839 static void CreateAndWriteSnapshot() { 850 static void CreateAndWriteSnapshot() {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 1002
992 1003
993 int main(int argc, char** argv) { 1004 int main(int argc, char** argv) {
994 const int EXTRA_VM_ARGUMENTS = 2; 1005 const int EXTRA_VM_ARGUMENTS = 2;
995 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); 1006 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS);
996 1007
997 // Initialize the URL mapping array. 1008 // Initialize the URL mapping array.
998 CommandLineOptions url_mapping_array(argc); 1009 CommandLineOptions url_mapping_array(argc);
999 url_mapping = &url_mapping_array; 1010 url_mapping = &url_mapping_array;
1000 1011
1012 // Initialize the entrypoints array.
1013 CommandLineOptions entry_points_files_array(argc);
1014 entry_points_files = &entry_points_files_array;
1015
1001 // Parse command line arguments. 1016 // Parse command line arguments.
1002 if (ParseArguments(argc, 1017 if (ParseArguments(argc,
1003 argv, 1018 argv,
1004 &vm_options, 1019 &vm_options,
1005 &app_script_name) < 0) { 1020 &app_script_name) < 0) {
1006 PrintUsage(); 1021 PrintUsage();
1007 return 255; 1022 return 255;
1008 } 1023 }
1009 1024
1010 Thread::InitOnce(); 1025 Thread::InitOnce();
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 EventHandler::Stop(); 1167 EventHandler::Stop();
1153 return 0; 1168 return 0;
1154 } 1169 }
1155 1170
1156 } // namespace bin 1171 } // namespace bin
1157 } // namespace dart 1172 } // namespace dart
1158 1173
1159 int main(int argc, char** argv) { 1174 int main(int argc, char** argv) {
1160 return dart::bin::main(argc, argv); 1175 return dart::bin::main(argc, argv);
1161 } 1176 }
OLDNEW
« runtime/BUILD.gn ('K') | « runtime/bin/BUILD.gn ('k') | runtime/vm/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698