Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
dart::bin::Options Class Reference

#include <main_options.h>

Static Public Member Functions

static bool ParseArguments (int argc, char **argv, bool vm_run_app_snapshot, CommandLineOptions *vm_options, char **script_name, CommandLineOptions *dart_options, bool *print_flags_seen, bool *verbose_debug_seen)
 
static bool preview_dart_2 ()
 
static dart::SimpleHashMapenvironment ()
 
static bool enable_vm_service ()
 
static const char * vm_service_server_ip ()
 
static int vm_service_server_port ()
 
static Dart_KernelCompilationVerbosityLevel verbosity_level ()
 
static DFEdfe ()
 
static void set_dfe (DFE *dfe)
 
static void PrintUsage ()
 
static void PrintVersion ()
 
static void Cleanup ()
 

Detailed Description

Definition at line 104 of file main_options.h.

Member Function Documentation

◆ Cleanup()

void dart::bin::Options::Cleanup ( )
static

Definition at line 264 of file main_options.cc.

264 {
265#if defined(DART_PRECOMPILED_RUNTIME)
266 DestroyEnvArgv();
267#endif
268 DestroyEnvironment();
269}

◆ dfe()

static DFE * dart::bin::Options::dfe ( )
inlinestatic

Definition at line 157 of file main_options.h.

157{ return dfe_; }

◆ enable_vm_service()

static bool dart::bin::Options::enable_vm_service ( )
inlinestatic

Definition at line 149 of file main_options.h.

149{ return enable_vm_service_; }

◆ environment()

static dart::SimpleHashMap * dart::bin::Options::environment ( )
inlinestatic

Definition at line 147 of file main_options.h.

147{ return environment_; }

◆ ParseArguments()

bool dart::bin::Options::ParseArguments ( int  argc,
char **  argv,
bool  vm_run_app_snapshot,
CommandLineOptions vm_options,
char **  script_name,
CommandLineOptions dart_options,
bool *  print_flags_seen,
bool *  verbose_debug_seen 
)
static

Definition at line 502 of file main_options.cc.

509 {
510 // Store the executable name.
512
513 // Start the rest after the executable name.
514 int i = 1;
515
516 CommandLineOptions temp_vm_options(vm_options->max_count());
517
518 bool enable_dartdev_analytics = false;
519 bool disable_dartdev_analytics = false;
520 char* packages_argument = nullptr;
521
522 // Parse out the vm options.
523 while (i < argc) {
524 bool skipVmOption = false;
525 if (!OptionProcessor::TryProcess(argv[i], &temp_vm_options)) {
526 // Check if this flag is a potentially valid VM flag.
527 if (!OptionProcessor::IsValidFlag(argv[i])) {
528 break;
529 }
530 // The following flags are processed as DartDev flags and are not to
531 // be treated as if they are VM flags.
532 if (IsOption(argv[i], "print-flags")) {
533 *print_flags_seen = true;
534 } else if (IsOption(argv[i], "verbose-debug")) {
535 *verbose_debug_seen = true;
536 } else if (IsOption(argv[i], "enable-analytics")) {
537 enable_dartdev_analytics = true;
538 skipVmOption = true;
539 } else if (IsOption(argv[i], "disable-analytics")) {
540 disable_dartdev_analytics = true;
541 skipVmOption = true;
542 } else if (IsOption(argv[i], "disable-telemetry")) {
543 disable_dartdev_analytics = true;
544 skipVmOption = true;
545 } else if (IsOption(argv[i], "no-analytics")) {
546 // Just add this option even if we don't go to dartdev.
547 // It is irrelevant for the vm.
548 dart_options->AddArgument("--no-analytics");
549 skipVmOption = true;
550 } else if (IsOption(argv[i], "dds")) {
551 // This flag is set by default in dartdev, so we ignore it. --no-dds is
552 // a VM flag as disabling DDS changes how we configure the VM service,
553 // so we don't need to handle that case here.
554 skipVmOption = true;
555 } else if (IsOption(argv[i], "serve-observatory")) {
556 // This flag is currently set by default in vmservice_io.dart, so we
557 // ignore it. --no-serve-observatory is a VM flag so we don't need to
558 // handle that case here.
559 skipVmOption = true;
560 } else if (IsOption(argv[i], "print-dtd-uri")) {
561 skipVmOption = true;
562 }
563 if (!skipVmOption) {
564 temp_vm_options.AddArgument(argv[i]);
565 }
566 }
567 if (IsOption(argv[i], "packages")) {
568 packages_argument = argv[i];
569 }
570 i++;
571 }
572
573#if !defined(DART_PRECOMPILED_RUNTIME)
575#else
576 // DartDev is not supported in AOT.
577 Options::disable_dart_dev_ = true;
578#endif // !defined(DART_PRECOMPILED_RUNTIME)
579 if (Options::deterministic()) {
580 // Both an embedder and VM flag.
581 temp_vm_options.AddArgument("--deterministic");
582 }
583
584 Socket::set_short_socket_read(Options::short_socket_read());
585 Socket::set_short_socket_write(Options::short_socket_write());
586#if !defined(DART_IO_SECURE_SOCKET_DISABLED)
587 SSLCertContext::set_root_certs_file(Options::root_certs_file());
588 SSLCertContext::set_root_certs_cache(Options::root_certs_cache());
590 Options::long_ssl_cert_evaluation());
592 Options::bypass_trusting_system_roots());
593#endif // !defined(DART_IO_SECURE_SOCKET_DISABLED)
594
596 Options::delayed_filewatch_callback());
597
598 // The arguments to the VM are at positions 1 through i-1 in argv.
600
601 bool implicitly_use_dart_dev = false;
602 bool run_script = false;
603 // Get the script name.
604 if (i < argc) {
605#if !defined(DART_PRECOMPILED_RUNTIME)
606 // If the script name is a valid file or a URL, we'll run the script
607 // directly. Otherwise, this might be a DartDev command and we need to try
608 // to find the DartDev snapshot so we can forward the command and its
609 // arguments.
610 bool is_potential_file_path = !DartDevIsolate::ShouldParseCommand(argv[i]);
611#else
612 bool is_potential_file_path = true;
613#endif // !defined(DART_PRECOMPILED_RUNTIME)
614 if (Options::disable_dart_dev() ||
615 (Options::snapshot_filename() != nullptr) ||
616 (is_potential_file_path && !enable_vm_service_)) {
617 *script_name = Utils::StrDup(argv[i]);
618 run_script = true;
619 i++;
620 }
621#if !defined(DART_PRECOMPILED_RUNTIME)
622 else { // NOLINT
624 }
625 if (!Options::disable_dart_dev() && enable_vm_service_) {
626 // Handle the special case where the user is running a Dart program
627 // without using a DartDev command and wants to use the VM service. Here
628 // we'll run the program using DartDev as it's used to spawn a DDS
629 // instance.
630 if (is_potential_file_path) {
631 implicitly_use_dart_dev = true;
632 }
633 }
634#endif // !defined(DART_PRECOMPILED_RUNTIME)
635 }
636#if !defined(DART_PRECOMPILED_RUNTIME)
637 else if (!Options::disable_dart_dev()) { // NOLINT
638 // Handles following invocation arguments:
639 // - dart help
640 // - dart --help
641 // - dart
642 if (((Options::help_option() && !Options::verbose_option()) ||
643 (argc == 1))) {
645 // Let DartDev handle the default help message.
646 dart_options->AddArgument("help");
647 return true;
648 }
649 // Handles cases where only analytics flags are provided. We need to start
650 // the DartDev isolate to set this state.
651 else if (enable_dartdev_analytics || disable_dartdev_analytics) { // NOLINT
652 // The analytics flags are a special case as we don't have a target script
653 // or DartDev command but we still want to launch DartDev.
655 dart_options->AddArgument(enable_dartdev_analytics
656 ? "--enable-analytics"
657 : "--disable-analytics");
658 return true;
659 }
660 // Let the VM handle '--version' and '--help --disable-dart-dev'.
661 // Otherwise, we'll launch the DartDev isolate to print its help message
662 // and set an error exit code.
663 else if (!Options::help_option() && !Options::version_option()) { // NOLINT
665 return true;
666 }
667 return false;
668 }
669#endif // !defined(DART_PRECOMPILED_RUNTIME)
670 // Handle argument parsing errors.
671 else { // NOLINT
672 return false;
673 }
674 USE(enable_dartdev_analytics);
675 USE(disable_dartdev_analytics);
676 USE(packages_argument);
677
678 const char** vm_argv = temp_vm_options.arguments();
679 int vm_argc = temp_vm_options.count();
680
681 vm_options->AddArguments(vm_argv, vm_argc);
682
683 // If running with dartdev, attempt to parse VM flags which are part of the
684 // dartdev command (e.g., --enable-vm-service, --observe, etc).
685 if (!run_script) {
686 int tmp_i = i;
687 // We only run the CLI implicitly if the service is enabled and the user
688 // didn't run with the 'run' command. If they did provide a command, we need
689 // to skip it here to continue parsing VM flags.
690 if (!implicitly_use_dart_dev) {
691 tmp_i++;
692 }
693 while (tmp_i < argc) {
694 // Check if this flag is a potentially valid VM flag. If not, we've likely
695 // hit a script name and are done parsing VM flags.
696 if (!OptionProcessor::IsValidFlag(argv[tmp_i]) &&
697 !OptionProcessor::IsValidShortFlag(argv[tmp_i])) {
698 break;
699 }
700 OptionProcessor::TryProcess(argv[tmp_i], vm_options);
701 tmp_i++;
702 }
703 }
704 bool first_option = true;
705 // Parse out options to be passed to dart main.
706 while (i < argc) {
707 if (implicitly_use_dart_dev && first_option) {
708 // Special case where user enables VM service without using a dartdev
709 // run command. If 'run' is provided, it will be the first argument
710 // processed in this loop.
711 dart_options->AddArgument("run");
712 } else {
713 // dart run isn't able to parse these options properly. Since it doesn't
714 // need to use the values from these options, just strip them from the
715 // argument list passed to dart run.
716 if (!IsOption(argv[i], "observe") &&
717 !IsOption(argv[i], "enable-vm-service")) {
718 dart_options->AddArgument(argv[i]);
719 }
720 i++;
721 }
722 // Add DDS specific flags immediately after the dartdev command.
723 if (first_option) {
724 // DDS is only enabled for the run command. Make sure we don't pass DDS
725 // specific flags along with other commands, otherwise argument parsing
726 // will fail unexpectedly.
727 bool run_command = implicitly_use_dart_dev;
728 if (!run_command && strcmp(argv[i - 1], "run") == 0) {
729 run_command = true;
730 }
731#if !defined(DART_PRECOMPILED_RUNTIME)
732 // Bring any --packages option into the dartdev command
734 packages_argument != nullptr) {
735 dart_options->AddArgument(packages_argument);
736 }
737#endif // !defined(DART_PRECOMPILED_RUNTIME)
738 first_option = false;
739 }
740 }
741
742 // Verify consistency of arguments.
743
744 // snapshot_depfile is an alias for depfile. Passing them both is an error.
745 if ((snapshot_deps_filename_ != nullptr) && (depfile_ != nullptr)) {
746 Syslog::PrintErr("Specify only one of --depfile and --snapshot_depfile\n");
747 return false;
748 }
749 if (snapshot_deps_filename_ != nullptr) {
750 depfile_ = snapshot_deps_filename_;
751 snapshot_deps_filename_ = nullptr;
752 }
753
754 if ((packages_file_ != nullptr) && (strlen(packages_file_) == 0)) {
755 Syslog::PrintErr("Empty package file name specified.\n");
756 return false;
757 }
758 if ((gen_snapshot_kind_ != kNone) && (snapshot_filename_ == nullptr)) {
760 "Generating a snapshot requires a filename (--snapshot).\n");
761 return false;
762 }
763 if ((gen_snapshot_kind_ == kNone) && (depfile_ != nullptr) &&
764 (snapshot_filename_ == nullptr) &&
765 (depfile_output_filename_ == nullptr)) {
767 "Generating a depfile requires an output filename"
768 " (--depfile-output-filename or --snapshot).\n");
769 return false;
770 }
771 if ((gen_snapshot_kind_ != kNone) && vm_run_app_snapshot) {
773 "Specifying an option to generate a snapshot and"
774 " run using a snapshot is invalid.\n");
775 return false;
776 }
777
778 // If --snapshot is given without --snapshot-kind, default to script snapshot.
779 if ((snapshot_filename_ != nullptr) && (gen_snapshot_kind_ == kNone)) {
780 gen_snapshot_kind_ = kKernel;
781 }
782
783 return true;
784}
static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static char * StrDup(const char *s)
void set_use_dfe(bool value=true)
Definition dfe.h:41
static bool should_run_dart_dev()
static void PrintUsageErrorOnRun()
static void set_should_run_dart_dev(bool enable)
static bool ShouldParseCommand(const char *script_uri)
static void set_delayed_filewatch_callback(bool value)
static bool TryProcess(const char *option, CommandLineOptions *options)
Definition options.cc:34
static bool IsValidShortFlag(const char *name)
Definition options.cc:16
static bool IsValidFlag(const char *name)
Definition options.cc:12
static DFE * dfe()
static void SetExecutableName(const char *executable_name)
Definition platform.h:71
static void SetExecutableArguments(int script_index, char **argv)
Definition platform.h:92
static void set_long_ssl_cert_evaluation(bool long_ssl_cert_evaluation)
static void set_bypass_trusting_system_roots(bool bypass_trusting_system_roots)
static void set_root_certs_file(const char *root_certs_file)
static void set_root_certs_cache(const char *root_certs_cache)
static void set_short_socket_read(bool short_socket_read)
Definition socket.h:103
static void set_short_socket_write(bool short_socket_write)
Definition socket.h:107
char ** argv
Definition library.h:9
static bool IsOption(const char *arg, const char *option)
static bool vm_run_app_snapshot
Definition main_impl.cc:71
static void USE(T &&)
Definition globals.h:618
run_command(command)

◆ preview_dart_2()

static bool dart::bin::Options::preview_dart_2 ( )
inlinestatic

Definition at line 145 of file main_options.h.

145{ return true; }

◆ PrintUsage()

void dart::bin::Options::PrintUsage ( )
static

Definition at line 134 of file main_options.cc.

134 {
136 "Usage: dart [<vm-flags>] <dart-script-file> [<script-arguments>]\n"
137 "\n"
138 "Executes the Dart script <dart-script-file> with "
139 "the given list of <script-arguments>.\n"
140 "\n");
141 if (!Options::verbose_option()) {
143"Common VM flags:\n"
144#if !defined(PRODUCT)
145"--enable-asserts\n"
146" Enable assert statements.\n"
147#endif // !defined(PRODUCT)
148"--help or -h\n"
149" Display this message (add -v or --verbose for information about\n"
150" all VM options).\n"
151"--packages=<path>\n"
152" Where to find a package spec file.\n"
153"--define=<key>=<value> or -D<key>=<value>\n"
154" Define an environment declaration. To specify multiple declarations,\n"
155" use multiple instances of this option.\n"
156#if !defined(PRODUCT)
157"--observe[=<port>[/<bind-address>]]\n"
158" The observe flag is a convenience flag used to run a program with a\n"
159" set of options which are often useful for debugging under Observatory.\n"
160" These options are currently:\n"
161" --enable-vm-service[=<port>[/<bind-address>]]\n"
162" --serve-devtools\n"
163" --pause-isolates-on-exit\n"
164" --pause-isolates-on-unhandled-exceptions\n"
165" --warn-on-pause-with-no-debugger\n"
166" --timeline-streams=\"Compiler, Dart, GC\"\n"
167" This set is subject to change.\n"
168" Please see these options (--help --verbose) for further documentation.\n"
169"--write-service-info=<file_uri>\n"
170" Outputs information necessary to connect to the VM service to the\n"
171" specified file in JSON format. Useful for clients which are unable to\n"
172" listen to stdout for the Dart VM service listening message.\n"
173#endif // !defined(PRODUCT)
174"--snapshot-kind=<snapshot_kind>\n"
175"--snapshot=<file_name>\n"
176" These snapshot options are used to generate a snapshot of the loaded\n"
177" Dart script:\n"
178" <snapshot-kind> controls the kind of snapshot, it could be\n"
179" kernel(default) or app-jit\n"
180" <file_name> specifies the file into which the snapshot is written\n"
181"--version\n"
182" Print the SDK version.\n");
183 } else {
185"Supported options:\n"
186#if !defined(PRODUCT)
187"--enable-asserts\n"
188" Enable assert statements.\n"
189#endif // !defined(PRODUCT)
190"--help or -h\n"
191" Display this message (add -v or --verbose for information about\n"
192" all VM options).\n"
193"--packages=<path>\n"
194" Where to find a package spec file.\n"
195"--define=<key>=<value> or -D<key>=<value>\n"
196" Define an environment declaration. To specify multiple declarations,\n"
197" use multiple instances of this option.\n"
198#if !defined(PRODUCT)
199"--observe[=<port>[/<bind-address>]]\n"
200" The observe flag is a convenience flag used to run a program with a\n"
201" set of options which are often useful for debugging under Observatory.\n"
202" These options are currently:\n"
203" --enable-vm-service[=<port>[/<bind-address>]]\n"
204" --serve-devtools\n"
205" --pause-isolates-on-exit\n"
206" --pause-isolates-on-unhandled-exceptions\n"
207" --warn-on-pause-with-no-debugger\n"
208" --timeline-streams=\"Compiler, Dart, GC\"\n"
209" This set is subject to change.\n"
210" Please see these options for further documentation.\n"
211#endif // !defined(PRODUCT)
212"--version\n"
213" Print the VM version.\n"
214"\n"
215"--trace-loading\n"
216" enables tracing of library and script loading\n"
217"\n"
218#if !defined(PRODUCT)
219"--enable-vm-service[=<port>[/<bind-address>]]\n"
220" Enables the VM service and listens on specified port for connections\n"
221" (default port number is 8181, default bind address is localhost).\n"
222"\n"
223"--disable-service-auth-codes\n"
224" Disables the requirement for an authentication code to communicate with\n"
225" the VM service. Authentication codes help protect against CSRF attacks,\n"
226" so it is not recommended to disable them unless behind a firewall on a\n"
227" secure device.\n"
228"\n"
229"--enable-service-port-fallback\n"
230" When the VM service is told to bind to a particular port, fallback to 0 if\n"
231" it fails to bind instead of failing to start.\n"
232"\n"
233#endif // !defined(PRODUCT)
234"--root-certs-file=<path>\n"
235" The path to a file containing the trusted root certificates to use for\n"
236" secure socket connections.\n"
237"--root-certs-cache=<path>\n"
238" The path to a cache directory containing the trusted root certificates to\n"
239" use for secure socket connections.\n"
240#if defined(DART_HOST_OS_LINUX) || \
241 defined(DART_HOST_OS_ANDROID) || \
242 defined(DART_HOST_OS_FUCHSIA)
243"--namespace=<path>\n"
244" The path to a directory that dart:io calls will treat as the root of the\n"
245" filesystem.\n"
246#endif // defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_ANDROID)
247"\n"
248"The following options are only used for VM development and may\n"
249"be changed in any future version:\n");
250 const char* print_flags = "--print_flags";
251 char* error = Dart_SetVMFlags(1, &print_flags);
252 ASSERT(error == nullptr);
253 }
254}
static void Print(const char *format,...) PRINTF_ATTRIBUTE(1
#define ASSERT(E)
const uint8_t uint32_t uint32_t GError ** error
DART_EXPORT char * Dart_SetVMFlags(int argc, const char **argv)

◆ PrintVersion()

void dart::bin::Options::PrintVersion ( )
static

Definition at line 129 of file main_options.cc.

129 {
130 Syslog::Print("Dart SDK version: %s\n", Dart_VersionString());
131}
DART_EXPORT const char * Dart_VersionString()

◆ set_dfe()

static void dart::bin::Options::set_dfe ( DFE dfe)
inlinestatic

Definition at line 158 of file main_options.h.

158{ dfe_ = dfe; }

◆ verbosity_level()

static Dart_KernelCompilationVerbosityLevel dart::bin::Options::verbosity_level ( )
inlinestatic

Definition at line 153 of file main_options.h.

153 {
154 return VerbosityLevelToDartAPI(verbosity_);
155 }

◆ vm_service_server_ip()

static const char * dart::bin::Options::vm_service_server_ip ( )
inlinestatic

Definition at line 150 of file main_options.h.

150{ return vm_service_server_ip_; }

◆ vm_service_server_port()

static int dart::bin::Options::vm_service_server_port ( )
inlinestatic

Definition at line 151 of file main_options.h.

151{ return vm_service_server_port_; }

The documentation for this class was generated from the following files: