OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #include <stdlib.h> | 5 #include <stdlib.h> |
6 #include <string.h> | 6 #include <string.h> |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
10 #include "include/dart_tools_api.h" | 10 #include "include/dart_tools_api.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 static const char* debug_ip = NULL; | 53 static const char* debug_ip = NULL; |
54 static int debug_port = -1; | 54 static int debug_port = -1; |
55 static const char* DEFAULT_DEBUG_IP = "127.0.0.1"; | 55 static const char* DEFAULT_DEBUG_IP = "127.0.0.1"; |
56 static const int DEFAULT_DEBUG_PORT = 5858; | 56 static const int DEFAULT_DEBUG_PORT = 5858; |
57 | 57 |
58 // Value of the --package-root flag. | 58 // Value of the --package-root flag. |
59 // (This pointer points into an argv buffer and does not need to be | 59 // (This pointer points into an argv buffer and does not need to be |
60 // free'd.) | 60 // free'd.) |
61 static const char* commandline_package_root = NULL; | 61 static const char* commandline_package_root = NULL; |
62 | 62 |
63 // Value of the --packages flag. | |
64 // (This pointer points into an argv buffer and does not need to be | |
65 // free'd.) | |
66 static const char* commandline_packages_file = NULL; | |
67 | |
63 | 68 |
64 // Global flag that is used to indicate that we want to compile all the | 69 // Global flag that is used to indicate that we want to compile all the |
65 // dart functions and not run anything. | 70 // dart functions and not run anything. |
66 static bool has_compile_all = false; | 71 static bool has_compile_all = false; |
67 | 72 |
68 // Global flag that is used to indicate that we want to trace resolution of | 73 // Global flag that is used to indicate that we want to trace resolution of |
69 // URIs and the loading of libraries, parts and scripts. | 74 // URIs and the loading of libraries, parts and scripts. |
70 static bool has_trace_loading = false; | 75 static bool has_trace_loading = false; |
71 | 76 |
72 | 77 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 CommandLineOptions* vm_options) { | 167 CommandLineOptions* vm_options) { |
163 ASSERT(arg != NULL); | 168 ASSERT(arg != NULL); |
164 if (*arg == '\0' || *arg == '-') { | 169 if (*arg == '\0' || *arg == '-') { |
165 return false; | 170 return false; |
166 } | 171 } |
167 commandline_package_root = arg; | 172 commandline_package_root = arg; |
168 return true; | 173 return true; |
169 } | 174 } |
170 | 175 |
171 | 176 |
177 static bool ProcessPackagesOption(const char* arg, | |
178 CommandLineOptions* vm_options) { | |
179 ASSERT(arg != NULL); | |
180 if (*arg == '\0' || *arg == '-') { | |
181 return false; | |
182 } | |
183 commandline_packages_file = arg; | |
184 return true; | |
185 } | |
186 | |
187 | |
172 static void* GetHashmapKeyFromString(char* key) { | 188 static void* GetHashmapKeyFromString(char* key) { |
173 return reinterpret_cast<void*>(key); | 189 return reinterpret_cast<void*>(key); |
174 } | 190 } |
175 | 191 |
176 | 192 |
177 static bool ExtractPortAndIP(const char *option_value, | 193 static bool ExtractPortAndIP(const char *option_value, |
178 int *out_port, | 194 int *out_port, |
179 const char **out_ip, | 195 const char **out_ip, |
180 int default_port, | 196 int default_port, |
181 const char *default_ip) { | 197 const char *default_ip) { |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 const char* option_name; | 380 const char* option_name; |
365 bool (*process)(const char* option, CommandLineOptions* vm_options); | 381 bool (*process)(const char* option, CommandLineOptions* vm_options); |
366 } main_options[] = { | 382 } main_options[] = { |
367 // Standard options shared with dart2js. | 383 // Standard options shared with dart2js. |
368 { "--version", ProcessVersionOption }, | 384 { "--version", ProcessVersionOption }, |
369 { "--help", ProcessHelpOption }, | 385 { "--help", ProcessHelpOption }, |
370 { "-h", ProcessHelpOption }, | 386 { "-h", ProcessHelpOption }, |
371 { "--verbose", ProcessVerboseOption }, | 387 { "--verbose", ProcessVerboseOption }, |
372 { "-v", ProcessVerboseOption }, | 388 { "-v", ProcessVerboseOption }, |
373 { "--package-root=", ProcessPackageRootOption }, | 389 { "--package-root=", ProcessPackageRootOption }, |
390 { "--packages=", ProcessPackagesOption }, | |
siva
2015/07/28 23:50:09
PrintUsage needs to be updated for this option.
Ivan Posva
2015/07/29 18:22:18
Done.
| |
374 { "-D", ProcessEnvironmentOption }, | 391 { "-D", ProcessEnvironmentOption }, |
375 // VM specific options to the standalone dart program. | 392 // VM specific options to the standalone dart program. |
376 { "--break-at=", ProcessBreakpointOption }, | 393 { "--break-at=", ProcessBreakpointOption }, |
377 { "--compile_all", ProcessCompileAllOption }, | 394 { "--compile_all", ProcessCompileAllOption }, |
378 { "--debug", ProcessDebugOption }, | 395 { "--debug", ProcessDebugOption }, |
379 { "--snapshot=", ProcessGenScriptSnapshotOption }, | 396 { "--snapshot=", ProcessGenScriptSnapshotOption }, |
380 { "--enable-vm-service", ProcessEnableVmServiceOption }, | 397 { "--enable-vm-service", ProcessEnableVmServiceOption }, |
381 { "--observe", ProcessObserveOption }, | 398 { "--observe", ProcessObserveOption }, |
382 { "--trace-debug-protocol", ProcessTraceDebugProtocolOption }, | 399 { "--trace-debug-protocol", ProcessTraceDebugProtocolOption }, |
383 { "--trace-loading", ProcessTraceLoadingOption}, | 400 { "--trace-loading", ProcessTraceLoadingOption}, |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
482 } else { | 499 } else { |
483 return -1; | 500 return -1; |
484 } | 501 } |
485 | 502 |
486 // Parse out options to be passed to dart main. | 503 // Parse out options to be passed to dart main. |
487 while (i < argc) { | 504 while (i < argc) { |
488 dart_options->AddArgument(argv[i]); | 505 dart_options->AddArgument(argv[i]); |
489 i++; | 506 i++; |
490 } | 507 } |
491 | 508 |
509 // Verify consistency of arguments. | |
510 if ((commandline_package_root != NULL) && | |
511 (commandline_packages_file != NULL)) { | |
512 Log::PrintErr("Specifying both a packages directory and a packages " | |
513 "file is invalid."); | |
514 return -1; | |
515 } | |
516 | |
492 return 0; | 517 return 0; |
493 } | 518 } |
494 | 519 |
495 | 520 |
496 static Dart_Handle CreateRuntimeOptions(CommandLineOptions* options) { | 521 static Dart_Handle CreateRuntimeOptions(CommandLineOptions* options) { |
497 int options_count = options->count(); | 522 int options_count = options->count(); |
498 Dart_Handle dart_arguments = Dart_NewList(options_count); | 523 Dart_Handle dart_arguments = Dart_NewList(options_count); |
499 if (Dart_IsError(dart_arguments)) { | 524 if (Dart_IsError(dart_arguments)) { |
500 return dart_arguments; | 525 return dart_arguments; |
501 } | 526 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
554 Dart_ExitScope(); \ | 579 Dart_ExitScope(); \ |
555 Dart_ShutdownIsolate(); \ | 580 Dart_ShutdownIsolate(); \ |
556 return NULL; \ | 581 return NULL; \ |
557 } \ | 582 } \ |
558 | 583 |
559 | 584 |
560 // Returns true on success, false on failure. | 585 // Returns true on success, false on failure. |
561 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, | 586 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, |
562 const char* main, | 587 const char* main, |
563 const char* package_root, | 588 const char* package_root, |
589 const char* packages_file, | |
564 Dart_IsolateFlags* flags, | 590 Dart_IsolateFlags* flags, |
565 char** error, | 591 char** error, |
566 int* exit_code) { | 592 int* exit_code) { |
567 ASSERT(script_uri != NULL); | 593 ASSERT(script_uri != NULL); |
568 IsolateData* isolate_data = new IsolateData(script_uri, package_root); | 594 IsolateData* isolate_data = new IsolateData(script_uri, |
595 package_root, | |
596 packages_file); | |
569 Dart_Isolate isolate = NULL; | 597 Dart_Isolate isolate = NULL; |
570 | 598 |
571 isolate = Dart_CreateIsolate(script_uri, | 599 isolate = Dart_CreateIsolate(script_uri, |
572 main, | 600 main, |
573 isolate_snapshot_buffer, | 601 isolate_snapshot_buffer, |
574 flags, | 602 flags, |
575 isolate_data, | 603 isolate_data, |
576 error); | 604 error); |
577 | 605 |
578 if (isolate == NULL) { | 606 if (isolate == NULL) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
611 // Prepare builtin and its dependent libraries for use to resolve URIs. | 639 // Prepare builtin and its dependent libraries for use to resolve URIs. |
612 // The builtin library is part of the core snapshot and would already be | 640 // The builtin library is part of the core snapshot and would already be |
613 // available here in the case of script snapshot loading. | 641 // available here in the case of script snapshot loading. |
614 Dart_Handle builtin_lib = | 642 Dart_Handle builtin_lib = |
615 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 643 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
616 CHECK_RESULT(builtin_lib); | 644 CHECK_RESULT(builtin_lib); |
617 | 645 |
618 // Prepare for script loading by setting up the 'print' and 'timer' | 646 // Prepare for script loading by setting up the 'print' and 'timer' |
619 // closures and setting up 'package root' for URI resolution. | 647 // closures and setting up 'package root' for URI resolution. |
620 result = DartUtils::PrepareForScriptLoading(package_root, | 648 result = DartUtils::PrepareForScriptLoading(package_root, |
649 packages_file, | |
621 false, | 650 false, |
622 has_trace_loading, | 651 has_trace_loading, |
623 builtin_lib); | 652 builtin_lib); |
624 CHECK_RESULT(result); | 653 CHECK_RESULT(result); |
625 | 654 |
626 result = Dart_SetEnvironmentCallback(EnvironmentCallback); | 655 result = Dart_SetEnvironmentCallback(EnvironmentCallback); |
627 CHECK_RESULT(result); | 656 CHECK_RESULT(result); |
628 | 657 |
629 // Load the script. | 658 // Load the script. |
630 result = DartUtils::LoadScript(script_uri, builtin_lib); | 659 result = DartUtils::LoadScript(script_uri, builtin_lib); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
668 if (data == NULL) { | 697 if (data == NULL) { |
669 *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate"); | 698 *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate"); |
670 return NULL; | 699 return NULL; |
671 } | 700 } |
672 script_uri = parent_isolate_data->script_url; | 701 script_uri = parent_isolate_data->script_url; |
673 if (script_uri == NULL) { | 702 if (script_uri == NULL) { |
674 *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate"); | 703 *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate"); |
675 return NULL; | 704 return NULL; |
676 } | 705 } |
677 } | 706 } |
707 const char* packages_file = NULL; | |
678 if (package_root == NULL) { | 708 if (package_root == NULL) { |
679 if (parent_isolate_data != NULL) { | 709 if (parent_isolate_data != NULL) { |
680 package_root = parent_isolate_data->package_root; | 710 package_root = parent_isolate_data->package_root; |
681 } else { | 711 packages_file = parent_isolate_data->packages_file; |
682 package_root = "."; | |
683 } | 712 } |
684 } | 713 } |
685 return CreateIsolateAndSetupHelper(script_uri, | 714 return CreateIsolateAndSetupHelper(script_uri, |
686 main, | 715 main, |
687 package_root, | 716 package_root, |
717 packages_file, | |
688 flags, | 718 flags, |
689 error, | 719 error, |
690 &exit_code); | 720 &exit_code); |
691 } | 721 } |
692 | 722 |
693 | 723 |
694 static void PrintVersion() { | 724 static void PrintVersion() { |
695 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); | 725 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); |
696 } | 726 } |
697 | 727 |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
982 &ServiceStreamCancelCallback); | 1012 &ServiceStreamCancelCallback); |
983 | 1013 |
984 // Call CreateIsolateAndSetup which creates an isolate and loads up | 1014 // Call CreateIsolateAndSetup which creates an isolate and loads up |
985 // the specified application script. | 1015 // the specified application script. |
986 char* error = NULL; | 1016 char* error = NULL; |
987 int exit_code = 0; | 1017 int exit_code = 0; |
988 char* isolate_name = BuildIsolateName(script_name, "main"); | 1018 char* isolate_name = BuildIsolateName(script_name, "main"); |
989 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, | 1019 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, |
990 "main", | 1020 "main", |
991 commandline_package_root, | 1021 commandline_package_root, |
1022 commandline_packages_file, | |
992 NULL, | 1023 NULL, |
993 &error, | 1024 &error, |
994 &exit_code); | 1025 &exit_code); |
995 if (isolate == NULL) { | 1026 if (isolate == NULL) { |
996 Log::PrintErr("%s\n", error); | 1027 Log::PrintErr("%s\n", error); |
997 free(error); | 1028 free(error); |
998 delete [] isolate_name; | 1029 delete [] isolate_name; |
999 exit((exit_code != 0) ? exit_code : kErrorExitCode); | 1030 exit((exit_code != 0) ? exit_code : kErrorExitCode); |
1000 } | 1031 } |
1001 delete [] isolate_name; | 1032 delete [] isolate_name; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1117 exit(Process::GlobalExitCode()); | 1148 exit(Process::GlobalExitCode()); |
1118 } | 1149 } |
1119 | 1150 |
1120 } // namespace bin | 1151 } // namespace bin |
1121 } // namespace dart | 1152 } // namespace dart |
1122 | 1153 |
1123 int main(int argc, char** argv) { | 1154 int main(int argc, char** argv) { |
1124 dart::bin::main(argc, argv); | 1155 dart::bin::main(argc, argv); |
1125 UNREACHABLE(); | 1156 UNREACHABLE(); |
1126 } | 1157 } |
OLD | NEW |