| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 } | 56 } |
| 57 | 57 |
| 58 | 58 |
| 59 // 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 |
| 60 // if so which file to write the snapshot into. | 60 // if so which file to write the snapshot into. |
| 61 static const char* vm_isolate_snapshot_filename = NULL; | 61 static const char* vm_isolate_snapshot_filename = NULL; |
| 62 static const char* isolate_snapshot_filename = NULL; | 62 static const char* isolate_snapshot_filename = NULL; |
| 63 static const char* assembly_filename = NULL; | 63 static const char* assembly_filename = NULL; |
| 64 static const char* instructions_blob_filename = NULL; | 64 static const char* instructions_blob_filename = NULL; |
| 65 static const char* rodata_blob_filename = NULL; | 65 static const char* rodata_blob_filename = NULL; |
| 66 static const char* package_root = NULL; | 66 |
| 67 |
| 68 // Value of the --package-root flag. |
| 69 // (This pointer points into an argv buffer and does not need to be |
| 70 // free'd.) |
| 71 static const char* commandline_package_root = NULL; |
| 72 |
| 73 // Value of the --packages flag. |
| 74 // (This pointer points into an argv buffer and does not need to be |
| 75 // free'd.) |
| 76 static const char* commandline_packages_file = NULL; |
| 67 | 77 |
| 68 | 78 |
| 69 // Global state which contains a pointer to the script name for which | 79 // Global state which contains a pointer to the script name for which |
| 70 // a snapshot needs to be created (NULL would result in the creation | 80 // a snapshot needs to be created (NULL would result in the creation |
| 71 // of a generic snapshot that contains only the corelibs). | 81 // of a generic snapshot that contains only the corelibs). |
| 72 static char* app_script_name = NULL; | 82 static char* app_script_name = NULL; |
| 73 | 83 |
| 74 | 84 |
| 75 // Global state that captures the URL mappings specified on the command line. | 85 // Global state that captures the URL mappings specified on the command line. |
| 76 static CommandLineOptions* url_mapping = NULL; | 86 static CommandLineOptions* url_mapping = NULL; |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 return false; | 252 return false; |
| 243 } | 253 } |
| 244 | 254 |
| 245 | 255 |
| 246 static bool ProcessPackageRootOption(const char* option) { | 256 static bool ProcessPackageRootOption(const char* option) { |
| 247 const char* name = ProcessOption(option, "--package_root="); | 257 const char* name = ProcessOption(option, "--package_root="); |
| 248 if (name == NULL) { | 258 if (name == NULL) { |
| 249 name = ProcessOption(option, "--package-root="); | 259 name = ProcessOption(option, "--package-root="); |
| 250 } | 260 } |
| 251 if (name != NULL) { | 261 if (name != NULL) { |
| 252 package_root = name; | 262 commandline_package_root = name; |
| 253 return true; | 263 return true; |
| 254 } | 264 } |
| 255 return false; | 265 return false; |
| 266 } |
| 267 |
| 268 |
| 269 static bool ProcessPackagesOption(const char* option) { |
| 270 const char* name = ProcessOption(option, "--packages="); |
| 271 if (name != NULL) { |
| 272 commandline_packages_file = name; |
| 273 return true; |
| 274 } |
| 275 return false; |
| 256 } | 276 } |
| 257 | 277 |
| 258 | 278 |
| 259 static bool ProcessURLmappingOption(const char* option) { | 279 static bool ProcessURLmappingOption(const char* option) { |
| 260 const char* mapping = ProcessOption(option, "--url_mapping="); | 280 const char* mapping = ProcessOption(option, "--url_mapping="); |
| 261 if (mapping == NULL) { | 281 if (mapping == NULL) { |
| 262 mapping = ProcessOption(option, "--url-mapping="); | 282 mapping = ProcessOption(option, "--url-mapping="); |
| 263 } | 283 } |
| 264 if (mapping != NULL) { | 284 if (mapping != NULL) { |
| 265 url_mapping->AddArgument(mapping); | 285 url_mapping->AddArgument(mapping); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 289 // Parse out the vm options. | 309 // Parse out the vm options. |
| 290 while ((i < argc) && IsValidFlag(argv[i], kPrefix, kPrefixLen)) { | 310 while ((i < argc) && IsValidFlag(argv[i], kPrefix, kPrefixLen)) { |
| 291 if (ProcessVmIsolateSnapshotOption(argv[i]) || | 311 if (ProcessVmIsolateSnapshotOption(argv[i]) || |
| 292 ProcessIsolateSnapshotOption(argv[i]) || | 312 ProcessIsolateSnapshotOption(argv[i]) || |
| 293 ProcessAssemblyOption(argv[i]) || | 313 ProcessAssemblyOption(argv[i]) || |
| 294 ProcessInstructionsBlobOption(argv[i]) || | 314 ProcessInstructionsBlobOption(argv[i]) || |
| 295 ProcessRodataBlobOption(argv[i]) || | 315 ProcessRodataBlobOption(argv[i]) || |
| 296 ProcessEmbedderEntryPointsManifestOption(argv[i]) || | 316 ProcessEmbedderEntryPointsManifestOption(argv[i]) || |
| 297 ProcessURLmappingOption(argv[i]) || | 317 ProcessURLmappingOption(argv[i]) || |
| 298 ProcessPackageRootOption(argv[i]) || | 318 ProcessPackageRootOption(argv[i]) || |
| 319 ProcessPackagesOption(argv[i]) || |
| 299 ProcessEnvironmentOption(argv[i])) { | 320 ProcessEnvironmentOption(argv[i])) { |
| 300 i += 1; | 321 i += 1; |
| 301 continue; | 322 continue; |
| 302 } | 323 } |
| 303 vm_options->AddArgument(argv[i]); | 324 vm_options->AddArgument(argv[i]); |
| 304 i += 1; | 325 i += 1; |
| 305 } | 326 } |
| 306 | 327 |
| 307 // Get the script name. | 328 // Get the script name. |
| 308 if (i < argc) { | 329 if (i < argc) { |
| 309 *script_name = argv[i]; | 330 *script_name = argv[i]; |
| 310 i += 1; | 331 i += 1; |
| 311 } else { | 332 } else { |
| 312 *script_name = NULL; | 333 *script_name = NULL; |
| 313 } | 334 } |
| 314 | 335 |
| 336 // Verify consistency of arguments. |
| 337 if ((commandline_package_root != NULL) && |
| 338 (commandline_packages_file != NULL)) { |
| 339 Log::PrintErr("Specifying both a packages directory and a packages " |
| 340 "file is invalid.\n"); |
| 341 return -1; |
| 342 } |
| 343 |
| 315 if (vm_isolate_snapshot_filename == NULL) { | 344 if (vm_isolate_snapshot_filename == NULL) { |
| 316 Log::PrintErr("No vm isolate snapshot output file specified.\n\n"); | 345 Log::PrintErr("No vm isolate snapshot output file specified.\n\n"); |
| 317 return -1; | 346 return -1; |
| 318 } | 347 } |
| 319 | 348 |
| 320 if (isolate_snapshot_filename == NULL) { | 349 if (isolate_snapshot_filename == NULL) { |
| 321 Log::PrintErr("No isolate snapshot output file specified.\n\n"); | 350 Log::PrintErr("No isolate snapshot output file specified.\n\n"); |
| 322 return -1; | 351 return -1; |
| 323 } | 352 } |
| 324 | 353 |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 " \n" | 668 " \n" |
| 640 " Supported options: \n" | 669 " Supported options: \n" |
| 641 " --vm_isolate_snapshot=<file> A full snapshot is a compact \n" | 670 " --vm_isolate_snapshot=<file> A full snapshot is a compact \n" |
| 642 " --isolate_snapshot=<file> representation of the dart vm isolate \n" | 671 " --isolate_snapshot=<file> representation of the dart vm isolate \n" |
| 643 " heap and dart isolate heap states. \n" | 672 " heap and dart isolate heap states. \n" |
| 644 " Both these options are required \n" | 673 " Both these options are required \n" |
| 645 " \n" | 674 " \n" |
| 646 " --package_root=<path> Where to find packages, that is, \n" | 675 " --package_root=<path> Where to find packages, that is, \n" |
| 647 " package:... imports. \n" | 676 " package:... imports. \n" |
| 648 " \n" | 677 " \n" |
| 678 " --packages=<packages_file> Where to find a package spec file \n" |
| 679 " \n" |
| 649 " --url_mapping=<mapping> Uses the URL mapping(s) specified on \n" | 680 " --url_mapping=<mapping> Uses the URL mapping(s) specified on \n" |
| 650 " the command line to load the \n" | 681 " the command line to load the \n" |
| 651 " libraries. \n" | 682 " libraries. \n" |
| 652 " \n" | 683 " \n" |
| 653 " --assembly=<file> (Precompilation only) Contains the \n" | 684 " --assembly=<file> (Precompilation only) Contains the \n" |
| 654 " assembly that must be linked into \n" | 685 " assembly that must be linked into \n" |
| 655 " the target binary \n" | 686 " the target binary \n" |
| 656 " \n" | 687 " \n" |
| 657 " --instructions_blob=<file> (Precompilation only) Contains the \n" | 688 " --instructions_blob=<file> (Precompilation only) Contains the \n" |
| 658 " --rodata_blob=<file> instructions and read-only data that \n" | 689 " --rodata_blob=<file> instructions and read-only data that \n" |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1279 // Set up 'package root' for URI resolution. | 1310 // Set up 'package root' for URI resolution. |
| 1280 result = DartUtils::PrepareForScriptLoading(false, false); | 1311 result = DartUtils::PrepareForScriptLoading(false, false); |
| 1281 CHECK_RESULT(result); | 1312 CHECK_RESULT(result); |
| 1282 | 1313 |
| 1283 // Set up the load port provided by the service isolate so that we can | 1314 // Set up the load port provided by the service isolate so that we can |
| 1284 // load scripts. | 1315 // load scripts. |
| 1285 result = DartUtils::SetupServiceLoadPort(); | 1316 result = DartUtils::SetupServiceLoadPort(); |
| 1286 CHECK_RESULT(result); | 1317 CHECK_RESULT(result); |
| 1287 | 1318 |
| 1288 // Setup package root if specified. | 1319 // Setup package root if specified. |
| 1289 result = DartUtils::SetupPackageRoot(package_root, NULL); | 1320 result = DartUtils::SetupPackageRoot(commandline_package_root, |
| 1321 commandline_packages_file); |
| 1290 CHECK_RESULT(result); | 1322 CHECK_RESULT(result); |
| 1291 | 1323 |
| 1292 Dart_ExitScope(); | 1324 Dart_ExitScope(); |
| 1293 Dart_ExitIsolate(); | 1325 Dart_ExitIsolate(); |
| 1294 | 1326 |
| 1295 UriResolverIsolateScope::isolate = isolate; | 1327 UriResolverIsolateScope::isolate = isolate; |
| 1296 | 1328 |
| 1297 // Now we create an isolate into which we load all the code that needs to | 1329 // Now we create an isolate into which we load all the code that needs to |
| 1298 // be in the snapshot. | 1330 // be in the snapshot. |
| 1299 isolate_data = new IsolateData(NULL, NULL, NULL); | 1331 isolate_data = new IsolateData(NULL, NULL, NULL); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1349 EventHandler::Stop(); | 1381 EventHandler::Stop(); |
| 1350 return 0; | 1382 return 0; |
| 1351 } | 1383 } |
| 1352 | 1384 |
| 1353 } // namespace bin | 1385 } // namespace bin |
| 1354 } // namespace dart | 1386 } // namespace dart |
| 1355 | 1387 |
| 1356 int main(int argc, char** argv) { | 1388 int main(int argc, char** argv) { |
| 1357 return dart::bin::main(argc, argv); | 1389 return dart::bin::main(argc, argv); |
| 1358 } | 1390 } |
| OLD | NEW |