Flutter Engine
The Flutter Engine
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, bool parsing_dart_vm_options, 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 void set_mark_main_isolate_as_system_isolate (bool state)
 
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 101 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 163 of file main_options.h.

163{ return dfe_; }

◆ enable_vm_service()

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

Definition at line 147 of file main_options.h.

147{ return enable_vm_service_; }

◆ environment()

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

Definition at line 145 of file main_options.h.

145{ return environment_; }

◆ ParseArguments()

bool dart::bin::Options::ParseArguments ( int  argc,
char **  argv,
bool  vm_run_app_snapshot,
bool  parsing_dart_vm_options,
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.

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

◆ preview_dart_2()

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

Definition at line 143 of file main_options.h.

143{ 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
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 164 of file main_options.h.

164{ dfe_ = dfe; }

◆ set_mark_main_isolate_as_system_isolate()

static void dart::bin::Options::set_mark_main_isolate_as_system_isolate ( bool  state)
inlinestatic

Definition at line 155 of file main_options.h.

155 {
156 mark_main_isolate_as_system_isolate_ = state;
157 }
AtkStateType state

◆ verbosity_level()

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

Definition at line 159 of file main_options.h.

159 {
160 return VerbosityLevelToDartAPI(verbosity_);
161 }

◆ vm_service_server_ip()

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

Definition at line 148 of file main_options.h.

148{ return vm_service_server_ip_; }

◆ vm_service_server_port()

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

Definition at line 149 of file main_options.h.

149{ return vm_service_server_port_; }

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