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

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
« no previous file with comments | « runtime/bin/dart_product_entries.txt ('k') | runtime/platform/globals.h » ('j') | 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>
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/log.h" 18 #include "bin/log.h"
19 #include "bin/thread.h" 19 #include "bin/thread.h"
20 #include "bin/utils.h" 20 #include "bin/utils.h"
21 #include "bin/vmservice_impl.h" 21 #include "bin/vmservice_impl.h"
22 22
23 #include "include/dart_api.h" 23 #include "include/dart_api.h"
24 24
25 #include "platform/hashmap.h"
25 #include "platform/globals.h" 26 #include "platform/globals.h"
26 27
27 namespace dart { 28 namespace dart {
28 namespace bin { 29 namespace bin {
29 30
31 // Exit code indicating an API error.
32 static const int kApiErrorExitCode = 253;
33 // Exit code indicating a compilation error.
34 static const int kCompilationErrorExitCode = 254;
35 // Exit code indicating an unhandled error that is not a compilation error.
36 static const int kErrorExitCode = 255;
37 // Exit code indicating a vm restart request. Never returned to the user.
38 static const int kRestartRequestExitCode = 1000;
39
30 #define CHECK_RESULT(result) \ 40 #define CHECK_RESULT(result) \
31 if (Dart_IsError(result)) { \ 41 if (Dart_IsError(result)) { \
42 intptr_t exit_code = 0; \
32 Log::PrintErr("Error: %s", Dart_GetError(result)); \ 43 Log::PrintErr("Error: %s", Dart_GetError(result)); \
44 if (Dart_IsCompilationError(result)) { \
45 exit_code = kCompilationErrorExitCode; \
46 } else if (Dart_IsApiError(result)) { \
47 exit_code = kApiErrorExitCode; \
48 } else if (Dart_IsVMRestartRequest(result)) { \
49 exit_code = kRestartRequestExitCode; \
50 } else { \
51 exit_code = kErrorExitCode; \
52 } \
33 Dart_ExitScope(); \ 53 Dart_ExitScope(); \
34 Dart_ShutdownIsolate(); \ 54 Dart_ShutdownIsolate(); \
35 exit(255); \ 55 exit(exit_code); \
36 } \ 56 }
37 57
38 58
39 // Global state that indicates whether a snapshot is to be created and 59 // Global state that indicates whether a snapshot is to be created and
40 // if so which file to write the snapshot into. 60 // if so which file to write the snapshot into.
41 static const char* vm_isolate_snapshot_filename = NULL; 61 static const char* vm_isolate_snapshot_filename = NULL;
42 static const char* isolate_snapshot_filename = NULL; 62 static const char* isolate_snapshot_filename = NULL;
43 static const char* instructions_snapshot_filename = NULL; 63 static const char* instructions_snapshot_filename = NULL;
44 static const char* embedder_entry_points_manifest = NULL;
45 static const char* package_root = NULL; 64 static const char* package_root = NULL;
46 65
47 66
48 // Global state which contains a pointer to the script name for which 67 // 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 68 // a snapshot needs to be created (NULL would result in the creation
50 // of a generic snapshot that contains only the corelibs). 69 // of a generic snapshot that contains only the corelibs).
51 static char* app_script_name = NULL; 70 static char* app_script_name = NULL;
52 71
53 72
54 // Global state that captures the URL mappings specified on the command line. 73 // Global state that captures the URL mappings specified on the command line.
55 static CommandLineOptions* url_mapping = NULL; 74 static CommandLineOptions* url_mapping = NULL;
56 75
76 // Global state that captures the entry point manifest files specified on the
77 // command line.
78 static CommandLineOptions* entry_points_files = NULL;
79
57 static bool IsValidFlag(const char* name, 80 static bool IsValidFlag(const char* name,
58 const char* prefix, 81 const char* prefix,
59 intptr_t prefix_length) { 82 intptr_t prefix_length) {
60 intptr_t name_length = strlen(name); 83 intptr_t name_length = strlen(name);
61 return ((name_length > prefix_length) && 84 return ((name_length > prefix_length) &&
62 (strncmp(name, prefix, prefix_length) == 0)); 85 (strncmp(name, prefix, prefix_length) == 0));
63 } 86 }
64 87
65 88
89 // The environment provided through the command line using -D options.
90 static dart::HashMap* environment = NULL;
91
92 static void* GetHashmapKeyFromString(char* key) {
93 return reinterpret_cast<void*>(key);
94 }
95
96 static bool ProcessEnvironmentOption(const char* arg) {
97 ASSERT(arg != NULL);
98 if (*arg == '\0') {
99 return false;
100 }
101 if (*arg != '-') {
102 return false;
103 }
104 if (*(arg + 1) != 'D') {
105 return false;
106 }
107 arg = arg + 2;
108 if (*arg == '\0') {
109 return true;
110 }
111 if (environment == NULL) {
112 environment = new HashMap(&HashMap::SameStringValue, 4);
113 }
114 // Split the name=value part of the -Dname=value argument.
115 char* name;
116 char* value = NULL;
117 const char* equals_pos = strchr(arg, '=');
118 if (equals_pos == NULL) {
119 // No equal sign (name without value) currently not supported.
120 Log::PrintErr("No value given to -D option\n");
121 return false;
122 } else {
123 int name_len = equals_pos - arg;
124 if (name_len == 0) {
125 Log::PrintErr("No name given to -D option\n");
126 return false;
127 }
128 // Split name=value into name and value.
129 name = reinterpret_cast<char*>(malloc(name_len + 1));
130 strncpy(name, arg, name_len);
131 name[name_len] = '\0';
132 value = strdup(equals_pos + 1);
133 }
134 HashMap::Entry* entry = environment->Lookup(
135 GetHashmapKeyFromString(name), HashMap::StringHash(name), true);
136 ASSERT(entry != NULL); // Lookup adds an entry if key not found.
137 entry->value = value;
138 return true;
139 }
140
141
142 static Dart_Handle EnvironmentCallback(Dart_Handle name) {
143 uint8_t* utf8_array;
144 intptr_t utf8_len;
145 Dart_Handle result = Dart_Null();
146 Dart_Handle handle = Dart_StringToUTF8(name, &utf8_array, &utf8_len);
147 if (Dart_IsError(handle)) {
148 handle = Dart_ThrowException(
149 DartUtils::NewDartArgumentError(Dart_GetError(handle)));
150 } else {
151 char* name_chars = reinterpret_cast<char*>(malloc(utf8_len + 1));
152 memmove(name_chars, utf8_array, utf8_len);
153 name_chars[utf8_len] = '\0';
154 const char* value = NULL;
155 printf("Looking for %s\n", name_chars);
156 if (environment != NULL) {
157 HashMap::Entry* entry = environment->Lookup(
158 GetHashmapKeyFromString(name_chars),
159 HashMap::StringHash(name_chars),
160 false);
161 if (entry != NULL) {
162 value = reinterpret_cast<char*>(entry->value);
163 }
164 }
165 if (value != NULL) {
166 result = Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(value),
167 strlen(value));
168 }
169 free(name_chars);
170 }
171 return result;
172 }
173
174
175
66 static const char* ProcessOption(const char* option, const char* name) { 176 static const char* ProcessOption(const char* option, const char* name) {
67 const intptr_t length = strlen(name); 177 const intptr_t length = strlen(name);
68 if (strncmp(option, name, length) == 0) { 178 if (strncmp(option, name, length) == 0) {
69 return (option + length); 179 return (option + length);
70 } 180 }
71 return NULL; 181 return NULL;
72 } 182 }
73 183
74 184
75 static bool ProcessVmIsolateSnapshotOption(const char* option) { 185 static bool ProcessVmIsolateSnapshotOption(const char* option) {
(...skipping 22 matching lines...) Expand all
98 instructions_snapshot_filename = name; 208 instructions_snapshot_filename = name;
99 return true; 209 return true;
100 } 210 }
101 return false; 211 return false;
102 } 212 }
103 213
104 214
105 static bool ProcessEmbedderEntryPointsManifestOption(const char* option) { 215 static bool ProcessEmbedderEntryPointsManifestOption(const char* option) {
106 const char* name = ProcessOption(option, "--embedder_entry_points_manifest="); 216 const char* name = ProcessOption(option, "--embedder_entry_points_manifest=");
107 if (name != NULL) { 217 if (name != NULL) {
108 embedder_entry_points_manifest = name; 218 entry_points_files->AddArgument(name);
109 return true; 219 return true;
110 } 220 }
111 return false; 221 return false;
112 } 222 }
113 223
114 224
115 static bool ProcessPackageRootOption(const char* option) { 225 static bool ProcessPackageRootOption(const char* option) {
116 const char* name = ProcessOption(option, "--package_root="); 226 const char* name = ProcessOption(option, "--package_root=");
227 if (name == NULL) {
228 name = ProcessOption(option, "--package-root=");
229 }
117 if (name != NULL) { 230 if (name != NULL) {
118 package_root = name; 231 package_root = name;
119 return true; 232 return true;
120 } 233 }
121 return false; 234 return false;
122 } 235 }
123 236
124 237
125 static bool ProcessURLmappingOption(const char* option) { 238 static bool ProcessURLmappingOption(const char* option) {
126 const char* mapping = ProcessOption(option, "--url_mapping="); 239 const char* mapping = ProcessOption(option, "--url_mapping=");
127 if (mapping == NULL) { 240 if (mapping == NULL) {
128 mapping = ProcessOption(option, "--url-mapping="); 241 mapping = ProcessOption(option, "--url-mapping=");
129 } 242 }
130 if (mapping != NULL) { 243 if (mapping != NULL) {
131 url_mapping->AddArgument(mapping); 244 url_mapping->AddArgument(mapping);
132 return true; 245 return true;
133 } 246 }
134 return false; 247 return false;
135 } 248 }
136 249
137 250
138 // Parse out the command line arguments. Returns -1 if the arguments 251 // Parse out the command line arguments. Returns -1 if the arguments
139 // are incorrect, 0 otherwise. 252 // are incorrect, 0 otherwise.
140 static int ParseArguments(int argc, 253 static int ParseArguments(int argc,
141 char** argv, 254 char** argv,
142 CommandLineOptions* vm_options, 255 CommandLineOptions* vm_options,
143 char** script_name) { 256 char** script_name) {
144 const char* kPrefix = "--"; 257 const char* kPrefix = "-";
145 const intptr_t kPrefixLen = strlen(kPrefix); 258 const intptr_t kPrefixLen = strlen(kPrefix);
146 259
147 // Skip the binary name. 260 // Skip the binary name.
148 int i = 1; 261 int i = 1;
149 262
150 // Parse out the vm options. 263 // Parse out the vm options.
151 while ((i < argc) && IsValidFlag(argv[i], kPrefix, kPrefixLen)) { 264 while ((i < argc) && IsValidFlag(argv[i], kPrefix, kPrefixLen)) {
152 if (ProcessVmIsolateSnapshotOption(argv[i]) || 265 if (ProcessVmIsolateSnapshotOption(argv[i]) ||
153 ProcessIsolateSnapshotOption(argv[i]) || 266 ProcessIsolateSnapshotOption(argv[i]) ||
154 ProcessInstructionsSnapshotOption(argv[i]) || 267 ProcessInstructionsSnapshotOption(argv[i]) ||
155 ProcessEmbedderEntryPointsManifestOption(argv[i]) || 268 ProcessEmbedderEntryPointsManifestOption(argv[i]) ||
156 ProcessURLmappingOption(argv[i]) || 269 ProcessURLmappingOption(argv[i]) ||
157 ProcessPackageRootOption(argv[i])) { 270 ProcessPackageRootOption(argv[i]) ||
271 ProcessEnvironmentOption(argv[i])) {
158 i += 1; 272 i += 1;
159 continue; 273 continue;
160 } 274 }
161 vm_options->AddArgument(argv[i]); 275 vm_options->AddArgument(argv[i]);
162 i += 1; 276 i += 1;
163 } 277 }
164 278
165 // Get the script name. 279 // Get the script name.
166 if (i < argc) { 280 if (i < argc) {
167 *script_name = argv[i]; 281 *script_name = argv[i];
168 i += 1; 282 i += 1;
169 } else { 283 } else {
170 *script_name = NULL; 284 *script_name = NULL;
171 } 285 }
172 286
173 if (vm_isolate_snapshot_filename == NULL) { 287 if (vm_isolate_snapshot_filename == NULL) {
174 Log::PrintErr("No vm isolate snapshot output file specified.\n\n"); 288 Log::PrintErr("No vm isolate snapshot output file specified.\n\n");
175 return -1; 289 return -1;
176 } 290 }
177 291
178 if (isolate_snapshot_filename == NULL) { 292 if (isolate_snapshot_filename == NULL) {
179 Log::PrintErr("No isolate snapshot output file specified.\n\n"); 293 Log::PrintErr("No isolate snapshot output file specified.\n\n");
180 return -1; 294 return -1;
181 } 295 }
182 296
183 if ((instructions_snapshot_filename != NULL) && 297 if ((instructions_snapshot_filename != NULL) &&
184 (embedder_entry_points_manifest == NULL)) { 298 (entry_points_files->count() == 0)) {
185 Log::PrintErr( 299 Log::PrintErr(
186 "Specifying an instructions snapshot filename indicates precompilation" 300 "Specifying an instructions snapshot filename indicates precompilation"
187 ". But no embedder entry points manifest was specified.\n\n"); 301 ". But no embedder entry points manifest was specified.\n\n");
188 return -1; 302 return -1;
189 } 303 }
190 304
191 if ((embedder_entry_points_manifest != NULL) && 305 if ((entry_points_files->count() > 0) &&
192 (instructions_snapshot_filename == NULL)) { 306 (instructions_snapshot_filename == NULL)) {
193 Log::PrintErr( 307 Log::PrintErr(
194 "Specifying the embedder entry points manifest indicates " 308 "Specifying the embedder entry points manifest indicates "
195 "precompilation. But no instuctions snapshot was specified.\n\n"); 309 "precompilation. But no instuctions snapshot was specified.\n\n");
196 return -1; 310 return -1;
197 } 311 }
198 312
199 return 0; 313 return 0;
200 } 314 }
201 315
202 316
203 static bool IsSnapshottingForPrecompilation(void) { 317 static bool IsSnapshottingForPrecompilation(void) {
204 return embedder_entry_points_manifest != NULL && 318 return (entry_points_files->count() > 0) &&
205 instructions_snapshot_filename != NULL; 319 (instructions_snapshot_filename != NULL);
206 } 320 }
207 321
208 322
209 static void WriteSnapshotFile(const char* filename, 323 static void WriteSnapshotFile(const char* filename,
210 const uint8_t* buffer, 324 const uint8_t* buffer,
211 const intptr_t size) { 325 const intptr_t size) {
212 File* file = File::Open(filename, File::kWriteTruncate); 326 File* file = File::Open(filename, File::kWriteTruncate);
213 ASSERT(file != NULL); 327 ASSERT(file != NULL);
214 if (!file->WriteFully(buffer, size)) { 328 if (!file->WriteFully(buffer, size)) {
215 Log::PrintErr("Error: Failed to write snapshot file.\n\n"); 329 Log::PrintErr("Error: Failed to write snapshot file.\n\n");
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 " \n" 617 " \n"
504 " --embedder_entry_points_manifest=<file> (Precompilation only) Contains \n" 618 " --embedder_entry_points_manifest=<file> (Precompilation only) Contains \n"
505 " the stanalone embedder entry points\n"); 619 " the stanalone embedder entry points\n");
506 } 620 }
507 621
508 622
509 static void VerifyLoaded(Dart_Handle library) { 623 static void VerifyLoaded(Dart_Handle library) {
510 if (Dart_IsError(library)) { 624 if (Dart_IsError(library)) {
511 const char* err_msg = Dart_GetError(library); 625 const char* err_msg = Dart_GetError(library);
512 Log::PrintErr("Errors encountered while loading: %s\n", err_msg); 626 Log::PrintErr("Errors encountered while loading: %s\n", err_msg);
513 Dart_ExitScope(); 627 CHECK_RESULT(library);
514 Dart_ShutdownIsolate();
515 exit(255);
516 } 628 }
517 ASSERT(Dart_IsLibrary(library)); 629 ASSERT(Dart_IsLibrary(library));
518 } 630 }
519 631
520 632
521 static const char StubNativeFunctionName[] = "StubNativeFunction"; 633 static const char StubNativeFunctionName[] = "StubNativeFunction";
522 634
523 635
524 void StubNativeFunction(Dart_NativeArguments arguments) { 636 void StubNativeFunction(Dart_NativeArguments arguments) {
525 // This is a stub function for the resolver 637 // This is a stub function for the resolver
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 886
775 entries++; 887 entries++;
776 } 888 }
777 889
778 free(line); 890 free(line);
779 891
780 return entries; 892 return entries;
781 } 893 }
782 894
783 895
784 static Dart_QualifiedFunctionName* ParseEntryPointsManifestFile( 896 static Dart_QualifiedFunctionName* ParseEntryPointsManifestFiles() {
785 const char* path) { 897 // Total number of entries across all manifest files.
786 if (path == NULL) { 898 int64_t entry_count = 0;
787 return NULL; 899
900 // Parse the files once but don't store the results. This is done to first
901 // determine the number of entries in the manifest
902 for (intptr_t i = 0; i < entry_points_files->count(); i++) {
903 const char* path = entry_points_files->GetArgument(i);
904
905 FILE* file = fopen(path, "r");
906
907 if (file == NULL) {
908 Log::PrintErr("Could not open entry points manifest file `%s`\n", path);
909 return NULL;
910 }
911
912 int64_t entries = ParseEntryPointsManifestLines(file, NULL);
913 fclose(file);
914
915 if (entries <= 0) {
916 Log::PrintErr(
917 "Manifest file `%s` specified is invalid or contained no entries\n",
918 path);
919 return NULL;
920 }
921
922 entry_count += entries;
788 } 923 }
789 924
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 925 // Allocate enough storage for the entries in the file plus a termination
811 // sentinel and parse it again to populate the allocation 926 // sentinel and parse it again to populate the allocation
812 Dart_QualifiedFunctionName* entries = 927 Dart_QualifiedFunctionName* entries =
813 reinterpret_cast<Dart_QualifiedFunctionName*>( 928 reinterpret_cast<Dart_QualifiedFunctionName*>(
814 calloc(entry_count + 1, sizeof(Dart_QualifiedFunctionName))); 929 calloc(entry_count + 1, sizeof(Dart_QualifiedFunctionName)));
815 930
816 int64_t parsed_entry_count = ParseEntryPointsManifestLines(file, entries); 931 int64_t parsed_entry_count = 0;
932 for (intptr_t i = 0; i < entry_points_files->count(); i++) {
933 const char* path = entry_points_files->GetArgument(i);
934 FILE* file = fopen(path, "r");
935 parsed_entry_count +=
936 ParseEntryPointsManifestLines(file, &entries[parsed_entry_count]);
937 fclose(file);
938 }
939
817 ASSERT(parsed_entry_count == entry_count); 940 ASSERT(parsed_entry_count == entry_count);
818 941
819 fclose(file);
820
821 // The entries allocation must be explicitly cleaned up via 942 // The entries allocation must be explicitly cleaned up via
822 // |CleanupEntryPointsCollection| 943 // |CleanupEntryPointsCollection|
823 return entries; 944 return entries;
824 } 945 }
825 946
826 947
827 static Dart_QualifiedFunctionName* ParseEntryPointsManifestIfPresent() { 948 static Dart_QualifiedFunctionName* ParseEntryPointsManifestIfPresent() {
828 Dart_QualifiedFunctionName* entries = 949 Dart_QualifiedFunctionName* entries = ParseEntryPointsManifestFiles();
829 ParseEntryPointsManifestFile(embedder_entry_points_manifest);
830 if ((entries == NULL) && IsSnapshottingForPrecompilation()) { 950 if ((entries == NULL) && IsSnapshottingForPrecompilation()) {
831 Log::PrintErr( 951 Log::PrintErr(
832 "Could not find native embedder entry points during precompilation\n"); 952 "Could not find native embedder entry points during precompilation\n");
833 exit(255); 953 exit(255);
834 } 954 }
835 return entries; 955 return entries;
836 } 956 }
837 957
838 958
839 static void CreateAndWriteSnapshot() { 959 static void CreateAndWriteSnapshot() {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 1111
992 1112
993 int main(int argc, char** argv) { 1113 int main(int argc, char** argv) {
994 const int EXTRA_VM_ARGUMENTS = 2; 1114 const int EXTRA_VM_ARGUMENTS = 2;
995 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); 1115 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS);
996 1116
997 // Initialize the URL mapping array. 1117 // Initialize the URL mapping array.
998 CommandLineOptions url_mapping_array(argc); 1118 CommandLineOptions url_mapping_array(argc);
999 url_mapping = &url_mapping_array; 1119 url_mapping = &url_mapping_array;
1000 1120
1121 // Initialize the entrypoints array.
1122 CommandLineOptions entry_points_files_array(argc);
1123 entry_points_files = &entry_points_files_array;
1124
1001 // Parse command line arguments. 1125 // Parse command line arguments.
1002 if (ParseArguments(argc, 1126 if (ParseArguments(argc,
1003 argv, 1127 argv,
1004 &vm_options, 1128 &vm_options,
1005 &app_script_name) < 0) { 1129 &app_script_name) < 0) {
1006 PrintUsage(); 1130 PrintUsage();
1007 return 255; 1131 return 255;
1008 } 1132 }
1009 1133
1010 Thread::InitOnce(); 1134 Thread::InitOnce();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 if (isolate == NULL) { 1184 if (isolate == NULL) {
1061 Log::PrintErr("Error: %s", error); 1185 Log::PrintErr("Error: %s", error);
1062 free(error); 1186 free(error);
1063 exit(255); 1187 exit(255);
1064 } 1188 }
1065 1189
1066 Dart_Handle result; 1190 Dart_Handle result;
1067 Dart_Handle library; 1191 Dart_Handle library;
1068 Dart_EnterScope(); 1192 Dart_EnterScope();
1069 1193
1194 result = Dart_SetEnvironmentCallback(EnvironmentCallback);
1195 CHECK_RESULT(result);
1196
1070 ASSERT(vm_isolate_snapshot_filename != NULL); 1197 ASSERT(vm_isolate_snapshot_filename != NULL);
1071 ASSERT(isolate_snapshot_filename != NULL); 1198 ASSERT(isolate_snapshot_filename != NULL);
1072 // Load up the script before a snapshot is created. 1199 // Load up the script before a snapshot is created.
1073 if (app_script_name != NULL) { 1200 if (app_script_name != NULL) {
1074 // This is the case of a custom embedder (e.g: dartium) trying to 1201 // This is the case of a custom embedder (e.g: dartium) trying to
1075 // create a full snapshot. The current isolate is set up so that we can 1202 // create a full snapshot. The current isolate is set up so that we can
1076 // invoke the dart uri resolution code like _resolveURI. App script is 1203 // invoke the dart uri resolution code like _resolveURI. App script is
1077 // loaded into a separate isolate. 1204 // loaded into a separate isolate.
1078 1205
1079 SetupForUriResolution(); 1206 SetupForUriResolution();
(...skipping 21 matching lines...) Expand all
1101 // Now we create an isolate into which we load all the code that needs to 1228 // Now we create an isolate into which we load all the code that needs to
1102 // be in the snapshot. 1229 // be in the snapshot.
1103 isolate_data = new IsolateData(NULL, NULL, NULL); 1230 isolate_data = new IsolateData(NULL, NULL, NULL);
1104 if (Dart_CreateIsolate( 1231 if (Dart_CreateIsolate(
1105 NULL, NULL, NULL, NULL, isolate_data, &error) == NULL) { 1232 NULL, NULL, NULL, NULL, isolate_data, &error) == NULL) {
1106 fprintf(stderr, "%s", error); 1233 fprintf(stderr, "%s", error);
1107 free(error); 1234 free(error);
1108 exit(255); 1235 exit(255);
1109 } 1236 }
1110 Dart_EnterScope(); 1237 Dart_EnterScope();
1238 result = Dart_SetEnvironmentCallback(EnvironmentCallback);
1239 CHECK_RESULT(result);
1111 1240
1112 // Set up the library tag handler in such a manner that it will use the 1241 // Set up the library tag handler in such a manner that it will use the
1113 // URL mapping specified on the command line to load the libraries. 1242 // URL mapping specified on the command line to load the libraries.
1114 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler); 1243 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler);
1115 CHECK_RESULT(result); 1244 CHECK_RESULT(result);
1116 1245
1117 Dart_QualifiedFunctionName* entry_points = 1246 Dart_QualifiedFunctionName* entry_points =
1118 ParseEntryPointsManifestIfPresent(); 1247 ParseEntryPointsManifestIfPresent();
1119 1248
1120 SetupStubNativeResolversForPrecompilation(entry_points); 1249 SetupStubNativeResolversForPrecompilation(entry_points);
1121 1250
1122 // Load the specified script. 1251 // Load the specified script.
1123 library = LoadSnapshotCreationScript(app_script_name); 1252 library = LoadSnapshotCreationScript(app_script_name);
1124 VerifyLoaded(library); 1253 VerifyLoaded(library);
1125 1254
1126 ImportNativeEntryPointLibrariesIntoRoot(entry_points); 1255 ImportNativeEntryPointLibrariesIntoRoot(entry_points);
1127 1256
1128 // Ensure that we mark all libraries as loaded. 1257 // Ensure that we mark all libraries as loaded.
1129 result = Dart_FinalizeLoading(false); 1258 result = Dart_FinalizeLoading(false);
1130 CHECK_RESULT(result); 1259 CHECK_RESULT(result);
1131 1260
1132 if (entry_points == NULL) { 1261 if (!IsSnapshottingForPrecompilation()) {
1133 ASSERT(!IsSnapshottingForPrecompilation());
1134 CreateAndWriteSnapshot(); 1262 CreateAndWriteSnapshot();
1135 } else { 1263 } else {
1136 CreateAndWritePrecompiledSnapshot(entry_points); 1264 CreateAndWritePrecompiledSnapshot(entry_points);
1137 } 1265 }
1138 1266
1139 CleanupEntryPointsCollection(entry_points); 1267 CleanupEntryPointsCollection(entry_points);
1140 1268
1141 Dart_EnterIsolate(UriResolverIsolateScope::isolate); 1269 Dart_EnterIsolate(UriResolverIsolateScope::isolate);
1142 Dart_ShutdownIsolate(); 1270 Dart_ShutdownIsolate();
1143 } else { 1271 } else {
1144 SetupForGenericSnapshotCreation(); 1272 SetupForGenericSnapshotCreation();
1145 CreateAndWriteSnapshot(); 1273 CreateAndWriteSnapshot();
1146 } 1274 }
1147 error = Dart_Cleanup(); 1275 error = Dart_Cleanup();
1148 if (error != NULL) { 1276 if (error != NULL) {
1149 Log::PrintErr("VM cleanup failed: %s\n", error); 1277 Log::PrintErr("VM cleanup failed: %s\n", error);
1150 free(error); 1278 free(error);
1151 } 1279 }
1152 EventHandler::Stop(); 1280 EventHandler::Stop();
1153 return 0; 1281 return 0;
1154 } 1282 }
1155 1283
1156 } // namespace bin 1284 } // namespace bin
1157 } // namespace dart 1285 } // namespace dart
1158 1286
1159 int main(int argc, char** argv) { 1287 int main(int argc, char** argv) {
1160 return dart::bin::main(argc, argv); 1288 return dart::bin::main(argc, argv);
1161 } 1289 }
OLDNEW
« no previous file with comments | « runtime/bin/dart_product_entries.txt ('k') | runtime/platform/globals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698