Flutter Engine
The Flutter Engine
main_options.h
Go to the documentation of this file.
1// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
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.
4
5#ifndef RUNTIME_BIN_MAIN_OPTIONS_H_
6#define RUNTIME_BIN_MAIN_OPTIONS_H_
7
8#include "bin/dartutils.h"
9#include "bin/dfe.h"
10#include "platform/globals.h"
12#include "platform/hashmap.h"
13
14namespace dart {
15namespace bin {
16
17// A list of options taking string arguments. Organized as:
18// V(flag_name, field_name)
19// The value of the flag can then be accessed with Options::field_name().
20#define STRING_OPTIONS_LIST(V) \
21 V(packages, packages_file) \
22 V(snapshot, snapshot_filename) \
23 V(snapshot_depfile, snapshot_deps_filename) \
24 V(depfile, depfile) \
25 V(depfile_output_filename, depfile_output_filename) \
26 V(root_certs_file, root_certs_file) \
27 V(root_certs_cache, root_certs_cache) \
28 V(namespace, namespc) \
29 V(write_service_info, vm_write_service_info_filename)
30
31// As STRING_OPTIONS_LIST but for boolean valued options. The default value is
32// always false, and the presence of the flag switches the value to true.
33#define BOOL_OPTIONS_LIST(V) \
34 V(version, version_option) \
35 V(compile_all, compile_all) \
36 V(disable_service_origin_check, vm_service_dev_mode) \
37 V(disable_service_auth_codes, vm_service_auth_disabled) \
38 V(deterministic, deterministic) \
39 V(trace_loading, trace_loading) \
40 V(short_socket_read, short_socket_read) \
41 V(short_socket_write, short_socket_write) \
42 V(disable_exit, exit_disabled) \
43 V(preview_dart_2, nop_option) \
44 V(suppress_core_dump, suppress_core_dump) \
45 V(enable_service_port_fallback, enable_service_port_fallback) \
46 V(disable_dart_dev, disable_dart_dev) \
47 V(no_dds, disable_dds) \
48 V(long_ssl_cert_evaluation, long_ssl_cert_evaluation) \
49 V(bypass_trusting_system_roots, bypass_trusting_system_roots) \
50 V(delayed_filewatch_callback, delayed_filewatch_callback) \
51 V(mark_main_isolate_as_system_isolate, mark_main_isolate_as_system_isolate) \
52 V(no_serve_devtools, disable_devtools) \
53 V(serve_devtools, enable_devtools) \
54 V(no_serve_observatory, disable_observatory) \
55 V(serve_observatory, enable_observatory) \
56 V(print_dtd, print_dtd)
57
58// Boolean flags that have a short form.
59#define SHORT_BOOL_OPTIONS_LIST(V) \
60 V(h, help, help_option) \
61 V(v, verbose, verbose_option)
62
63#define DEBUG_BOOL_OPTIONS_LIST(V) \
64 V(force_load_elf_from_memory, force_load_elf_from_memory)
65
66// A list of flags taking arguments from an enum. Organized as:
67// V(flag_name, enum_type, field_name)
68// In main_options.cc there must be a list of strings that matches the enum
69// called k{enum_type}Names. The field is not automatically declared in
70// main_options.cc. It must be explicitly declared.
71#define ENUM_OPTIONS_LIST(V) \
72 V(snapshot_kind, SnapshotKind, gen_snapshot_kind) \
73 V(verbosity, VerbosityLevel, verbosity)
74
75// Callbacks passed to DEFINE_CB_OPTION().
76#define CB_OPTIONS_LIST(V) \
77 V(ProcessEnvironmentOption) \
78 V(ProcessEnableVmServiceOption) \
79 V(ProcessObserveOption) \
80 V(ProcessVMDebuggingOptions)
81
82// This enum must match the strings in kSnapshotKindNames in main_options.cc.
86 kAppJIT,
87};
88
89// This enum must match the strings in kVerbosityLevelNames in main_options.cc.
95};
96
97static constexpr const char* DEFAULT_VM_SERVICE_SERVER_IP = "localhost";
98static constexpr int DEFAULT_VM_SERVICE_SERVER_PORT = 8181;
99static constexpr int INVALID_VM_SERVICE_SERVER_PORT = -1;
100
101class Options {
102 public:
103 // Returns true if argument parsing succeeded. False otherwise.
104 static bool ParseArguments(int argc,
105 char** argv,
107 bool parsing_dart_vm_options,
108 CommandLineOptions* vm_options,
109 char** script_name,
110 CommandLineOptions* dart_options,
111 bool* print_flags_seen,
112 bool* verbose_debug_seen);
113
114#define STRING_OPTION_GETTER(flag, variable) \
115 static const char* variable() { return variable##_; }
117#undef STRING_OPTION_GETTER
118
119#define BOOL_OPTION_GETTER(flag, variable) \
120 static bool variable() { return variable##_; }
122#if defined(DEBUG)
124#endif
125#undef BOOL_OPTION_GETTER
126
127#define SHORT_BOOL_OPTION_GETTER(short_name, long_name, variable) \
128 static bool variable() { return variable##_; }
130#undef SHORT_BOOL_OPTION_GETTER
131
132#define ENUM_OPTIONS_GETTER(flag, type, variable) \
133 static type variable() { return variable##_; }
135#undef ENUM_OPTIONS_GETTER
136
137// Callbacks have to be public.
138#define CB_OPTIONS_DECL(callback) \
139 static bool callback(const char* arg, CommandLineOptions* vm_options);
141#undef CB_OPTIONS_DECL
142
143 static bool preview_dart_2() { return true; }
144
145 static dart::SimpleHashMap* environment() { return environment_; }
146
147 static bool enable_vm_service() { return enable_vm_service_; }
148 static const char* vm_service_server_ip() { return vm_service_server_ip_; }
149 static int vm_service_server_port() { return vm_service_server_port_; }
150
151 // TODO(bkonyi): remove once DartDev moves to AOT and this flag can be
152 // provided directly to the process spawned by `dart run` and `dart test`.
153 //
154 // See https://github.com/dart-lang/sdk/issues/53576
156 mark_main_isolate_as_system_isolate_ = state;
157 }
158
160 return VerbosityLevelToDartAPI(verbosity_);
161 }
162#if !defined(DART_PRECOMPILED_RUNTIME)
163 static DFE* dfe() { return dfe_; }
164 static void set_dfe(DFE* dfe) { dfe_ = dfe; }
165#endif // !defined(DART_PRECOMPILED_RUNTIME)
166
167 static void PrintUsage();
168 static void PrintVersion();
169
170 static void Cleanup();
171
172#if defined(DART_PRECOMPILED_RUNTIME)
173 // Get the list of options in DART_VM_OPTIONS.
174 static char** GetEnvArguments(int* argc);
175#endif // defined(DART_PRECOMPILED_RUNTIME)
176
177 private:
178 static void DestroyEnvironment();
179#if defined(DART_PRECOMPILED_RUNTIME)
180 static void DestroyEnvArgv();
181#endif // defined(DART_PRECOMPILED_RUNTIME)
182
183#define STRING_OPTION_DECL(flag, variable) static const char* variable##_;
185#undef STRING_OPTION_DECL
186
187#define BOOL_OPTION_DECL(flag, variable) static bool variable##_;
189#if defined(DEBUG)
191#endif
192#undef BOOL_OPTION_DECL
193
194#define SHORT_BOOL_OPTION_DECL(short_name, long_name, variable) \
195 static bool variable##_;
197#undef SHORT_BOOL_OPTION_DECL
198
199#define ENUM_OPTION_DECL(flag, type, variable) static type variable##_;
201#undef ENUM_OPTION_DECL
202
203 static dart::SimpleHashMap* environment_;
204
205#if defined(DART_PRECOMPILED_RUNTIME)
206 static char** env_argv_;
207 static int env_argc_;
208#endif // defined(DART_PRECOMPILED_RUNTIME)
209
210// Frontend argument processing.
211#if !defined(DART_PRECOMPILED_RUNTIME)
212 static DFE* dfe_;
213#endif // !defined(DART_PRECOMPILED_RUNTIME)
214
215 static Dart_KernelCompilationVerbosityLevel VerbosityLevelToDartAPI(
217 switch (level) {
218 case kError:
220 case kWarning:
222 case kInfo:
224 case kAll:
226 default:
227 UNREACHABLE();
228 }
229 }
230
231 // VM Service argument processing.
232 static const char* vm_service_server_ip_;
233 static bool enable_vm_service_;
234 static int vm_service_server_port_;
235 static bool ExtractPortAndAddress(const char* option_value,
236 int* out_port,
237 const char** out_ip,
238 int default_port,
239 const char* default_ip);
240
241#define OPTION_FRIEND(flag, variable) friend class OptionProcessor_##flag;
244#if defined(DEBUG)
246#endif
247#undef OPTION_FRIEND
248
249#define SHORT_BOOL_OPTION_FRIEND(short_name, long_name, variable) \
250 friend class OptionProcessor_##long_name;
252#undef SHORT_BOOL_OPTION_FRIEND
253
254#define ENUM_OPTION_FRIEND(flag, type, variable) \
255 friend class OptionProcessor_##flag;
257#undef ENUM_OPTION_FRIEND
258
259 DISALLOW_ALLOCATION();
260 DISALLOW_IMPLICIT_CONSTRUCTORS(Options);
261};
262
263} // namespace bin
264} // namespace dart
265
266#endif // RUNTIME_BIN_MAIN_OPTIONS_H_
#define UNREACHABLE()
Definition: assert.h:248
static bool preview_dart_2()
Definition: main_options.h:143
static void set_mark_main_isolate_as_system_isolate(bool state)
Definition: main_options.h:155
static void Cleanup()
static void PrintVersion()
static void set_dfe(DFE *dfe)
Definition: main_options.h:164
static DFE * dfe()
Definition: main_options.h:163
static void PrintUsage()
static Dart_KernelCompilationVerbosityLevel verbosity_level()
Definition: main_options.h:159
static bool enable_vm_service()
Definition: main_options.h:147
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 const char * vm_service_server_ip()
Definition: main_options.h:148
static int vm_service_server_port()
Definition: main_options.h:149
static dart::SimpleHashMap * environment()
Definition: main_options.h:145
Dart_KernelCompilationVerbosityLevel
Definition: dart_api.h:3798
@ Dart_KernelCompilationVerbosityLevel_Error
Definition: dart_api.h:3799
@ Dart_KernelCompilationVerbosityLevel_Warning
Definition: dart_api.h:3800
@ Dart_KernelCompilationVerbosityLevel_All
Definition: dart_api.h:3802
@ Dart_KernelCompilationVerbosityLevel_Info
Definition: dart_api.h:3801
AtkStateType state
char ** argv
Definition: library.h:9
#define DEBUG_BOOL_OPTIONS_LIST(V)
Definition: main_options.h:63
#define STRING_OPTION_DECL(flag, variable)
Definition: main_options.h:183
#define ENUM_OPTIONS_LIST(V)
Definition: main_options.h:71
#define SHORT_BOOL_OPTION_DECL(short_name, long_name, variable)
Definition: main_options.h:194
#define BOOL_OPTIONS_LIST(V)
Definition: main_options.h:33
#define ENUM_OPTIONS_GETTER(flag, type, variable)
Definition: main_options.h:132
#define SHORT_BOOL_OPTIONS_LIST(V)
Definition: main_options.h:59
#define ENUM_OPTION_FRIEND(flag, type, variable)
Definition: main_options.h:254
#define STRING_OPTION_GETTER(flag, variable)
Definition: main_options.h:114
#define CB_OPTIONS_DECL(callback)
Definition: main_options.h:138
#define BOOL_OPTION_DECL(flag, variable)
Definition: main_options.h:187
#define BOOL_OPTION_GETTER(flag, variable)
Definition: main_options.h:119
#define ENUM_OPTION_DECL(flag, type, variable)
Definition: main_options.h:199
#define CB_OPTIONS_LIST(V)
Definition: main_options.h:76
#define SHORT_BOOL_OPTION_GETTER(short_name, long_name, variable)
Definition: main_options.h:127
#define OPTION_FRIEND(flag, variable)
Definition: main_options.h:241
#define STRING_OPTIONS_LIST(V)
Definition: main_options.h:20
#define SHORT_BOOL_OPTION_FRIEND(short_name, long_name, variable)
Definition: main_options.h:249
static bool vm_run_app_snapshot
Definition: main_impl.cc:67
static constexpr const char * DEFAULT_VM_SERVICE_SERVER_IP
Definition: main_options.h:97
static constexpr int DEFAULT_VM_SERVICE_SERVER_PORT
Definition: main_options.h:98
static constexpr int INVALID_VM_SERVICE_SERVER_PORT
Definition: main_options.h:99
Definition: dart_vm.cc:33