Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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// we define sound_null_safety as an unused option here just to make sure
34// scripts that were passing in this option do not break.
35#define BOOL_OPTIONS_LIST(V) \
36 V(version, version_option) \
37 V(compile_all, compile_all) \
38 V(disable_service_origin_check, vm_service_dev_mode) \
39 V(disable_service_auth_codes, vm_service_auth_disabled) \
40 V(deterministic, deterministic) \
41 V(trace_loading, trace_loading) \
42 V(short_socket_read, short_socket_read) \
43 V(short_socket_write, short_socket_write) \
44 V(disable_exit, exit_disabled) \
45 V(preview_dart_2, nop_option) \
46 V(suppress_core_dump, suppress_core_dump) \
47 V(enable_service_port_fallback, enable_service_port_fallback) \
48 V(disable_dart_dev, disable_dart_dev) \
49 V(no_dds, disable_dds) \
50 V(long_ssl_cert_evaluation, long_ssl_cert_evaluation) \
51 V(bypass_trusting_system_roots, bypass_trusting_system_roots) \
52 V(delayed_filewatch_callback, delayed_filewatch_callback) \
53 V(mark_main_isolate_as_system_isolate, mark_main_isolate_as_system_isolate) \
54 V(no_serve_devtools, disable_devtools) \
55 V(serve_devtools, enable_devtools) \
56 V(no_serve_observatory, disable_observatory) \
57 V(serve_observatory, enable_observatory) \
58 V(print_dtd, print_dtd) \
59 V(sound_null_safety, sound_null_safety)
60
61// Boolean flags that have a short form.
62#define SHORT_BOOL_OPTIONS_LIST(V) \
63 V(h, help, help_option) \
64 V(v, verbose, verbose_option)
65
66#define DEBUG_BOOL_OPTIONS_LIST(V) \
67 V(force_load_elf_from_memory, force_load_elf_from_memory)
68
69// A list of flags taking arguments from an enum. Organized as:
70// V(flag_name, enum_type, field_name)
71// In main_options.cc there must be a list of strings that matches the enum
72// called k{enum_type}Names. The field is not automatically declared in
73// main_options.cc. It must be explicitly declared.
74#define ENUM_OPTIONS_LIST(V) \
75 V(snapshot_kind, SnapshotKind, gen_snapshot_kind) \
76 V(verbosity, VerbosityLevel, verbosity)
77
78// Callbacks passed to DEFINE_CB_OPTION().
79#define CB_OPTIONS_LIST(V) \
80 V(ProcessEnvironmentOption) \
81 V(ProcessEnableVmServiceOption) \
82 V(ProcessObserveOption) \
83 V(ProcessVMDebuggingOptions)
84
85// This enum must match the strings in kSnapshotKindNames in main_options.cc.
91
92// This enum must match the strings in kVerbosityLevelNames in main_options.cc.
99
100static constexpr const char* DEFAULT_VM_SERVICE_SERVER_IP = "localhost";
101static constexpr int DEFAULT_VM_SERVICE_SERVER_PORT = 8181;
102static constexpr int INVALID_VM_SERVICE_SERVER_PORT = -1;
103
104class Options {
105 public:
106 // Returns true if argument parsing succeeded. False otherwise.
107 static bool ParseArguments(int argc,
108 char** argv,
110 CommandLineOptions* vm_options,
111 char** script_name,
112 CommandLineOptions* dart_options,
113 bool* print_flags_seen,
114 bool* verbose_debug_seen);
115
116#define STRING_OPTION_GETTER(flag, variable) \
117 static const char* variable() { return variable##_; }
119#undef STRING_OPTION_GETTER
120
121#define BOOL_OPTION_GETTER(flag, variable) \
122 static bool variable() { return variable##_; }
124#if defined(DEBUG)
126#endif
127#undef BOOL_OPTION_GETTER
128
129#define SHORT_BOOL_OPTION_GETTER(short_name, long_name, variable) \
130 static bool variable() { return variable##_; }
132#undef SHORT_BOOL_OPTION_GETTER
133
134#define ENUM_OPTIONS_GETTER(flag, type, variable) \
135 static type variable() { return variable##_; }
137#undef ENUM_OPTIONS_GETTER
138
139// Callbacks have to be public.
140#define CB_OPTIONS_DECL(callback) \
141 static bool callback(const char* arg, CommandLineOptions* vm_options);
143#undef CB_OPTIONS_DECL
144
145 static bool preview_dart_2() { return true; }
146
147 static dart::SimpleHashMap* environment() { return environment_; }
148
149 static bool enable_vm_service() { return enable_vm_service_; }
150 static const char* vm_service_server_ip() { return vm_service_server_ip_; }
151 static int vm_service_server_port() { return vm_service_server_port_; }
152
154 return VerbosityLevelToDartAPI(verbosity_);
155 }
156#if !defined(DART_PRECOMPILED_RUNTIME)
157 static DFE* dfe() { return dfe_; }
158 static void set_dfe(DFE* dfe) { dfe_ = dfe; }
159#endif // !defined(DART_PRECOMPILED_RUNTIME)
160
161 static void PrintUsage();
162 static void PrintVersion();
163
164 static void Cleanup();
165
166#if defined(DART_PRECOMPILED_RUNTIME)
167 // Get the list of options in DART_VM_OPTIONS.
168 static char** GetEnvArguments(int* argc);
169#endif // defined(DART_PRECOMPILED_RUNTIME)
170
171 private:
172 static void DestroyEnvironment();
173#if defined(DART_PRECOMPILED_RUNTIME)
174 static void DestroyEnvArgv();
175#endif // defined(DART_PRECOMPILED_RUNTIME)
176
177#define STRING_OPTION_DECL(flag, variable) static const char* variable##_;
179#undef STRING_OPTION_DECL
180
181#define BOOL_OPTION_DECL(flag, variable) static bool variable##_;
183#if defined(DEBUG)
185#endif
186#undef BOOL_OPTION_DECL
187
188#define SHORT_BOOL_OPTION_DECL(short_name, long_name, variable) \
189 static bool variable##_;
191#undef SHORT_BOOL_OPTION_DECL
192
193#define ENUM_OPTION_DECL(flag, type, variable) static type variable##_;
195#undef ENUM_OPTION_DECL
196
197 static dart::SimpleHashMap* environment_;
198
199#if defined(DART_PRECOMPILED_RUNTIME)
200 static char** env_argv_;
201 static int env_argc_;
202#endif // defined(DART_PRECOMPILED_RUNTIME)
203
204// Frontend argument processing.
205#if !defined(DART_PRECOMPILED_RUNTIME)
206 static DFE* dfe_;
207#endif // !defined(DART_PRECOMPILED_RUNTIME)
208
209 static Dart_KernelCompilationVerbosityLevel VerbosityLevelToDartAPI(
210 VerbosityLevel level) {
211 switch (level) {
212 case kError:
214 case kWarning:
216 case kInfo:
218 case kAll:
220 default:
221 UNREACHABLE();
222 }
223 }
224
225 // VM Service argument processing.
226 static const char* vm_service_server_ip_;
227 static bool enable_vm_service_;
228 static int vm_service_server_port_;
229 static bool ExtractPortAndAddress(const char* option_value,
230 int* out_port,
231 const char** out_ip,
232 int default_port,
233 const char* default_ip);
234
235#define OPTION_FRIEND(flag, variable) friend class OptionProcessor_##flag;
238#if defined(DEBUG)
240#endif
241#undef OPTION_FRIEND
242
243#define SHORT_BOOL_OPTION_FRIEND(short_name, long_name, variable) \
244 friend class OptionProcessor_##long_name;
246#undef SHORT_BOOL_OPTION_FRIEND
247
248#define ENUM_OPTION_FRIEND(flag, type, variable) \
249 friend class OptionProcessor_##flag;
251#undef ENUM_OPTION_FRIEND
252
253 DISALLOW_ALLOCATION();
255};
256
257} // namespace bin
258} // namespace dart
259
260#endif // RUNTIME_BIN_MAIN_OPTIONS_H_
#define UNREACHABLE()
Definition assert.h:248
static bool preview_dart_2()
static void Cleanup()
static void PrintVersion()
static void set_dfe(DFE *dfe)
static DFE * dfe()
static void PrintUsage()
static Dart_KernelCompilationVerbosityLevel verbosity_level()
static bool enable_vm_service()
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 const char * vm_service_server_ip()
static int vm_service_server_port()
static dart::SimpleHashMap * environment()
Dart_KernelCompilationVerbosityLevel
Definition dart_api.h:3741
@ Dart_KernelCompilationVerbosityLevel_Error
Definition dart_api.h:3742
@ Dart_KernelCompilationVerbosityLevel_Warning
Definition dart_api.h:3743
@ Dart_KernelCompilationVerbosityLevel_All
Definition dart_api.h:3745
@ Dart_KernelCompilationVerbosityLevel_Info
Definition dart_api.h:3744
#define BOOL_OPTIONS_LIST(V)
#define STRING_OPTIONS_LIST(V)
char ** argv
Definition library.h:9
#define DEBUG_BOOL_OPTIONS_LIST(V)
#define STRING_OPTION_DECL(flag, variable)
#define ENUM_OPTIONS_LIST(V)
#define SHORT_BOOL_OPTION_DECL(short_name, long_name, variable)
#define ENUM_OPTIONS_GETTER(flag, type, variable)
#define SHORT_BOOL_OPTIONS_LIST(V)
#define ENUM_OPTION_FRIEND(flag, type, variable)
#define STRING_OPTION_GETTER(flag, variable)
#define CB_OPTIONS_DECL(callback)
#define BOOL_OPTION_DECL(flag, variable)
#define BOOL_OPTION_GETTER(flag, variable)
#define ENUM_OPTION_DECL(flag, type, variable)
#define CB_OPTIONS_LIST(V)
#define SHORT_BOOL_OPTION_GETTER(short_name, long_name, variable)
#define OPTION_FRIEND(flag, variable)
#define SHORT_BOOL_OPTION_FRIEND(short_name, long_name, variable)
static bool vm_run_app_snapshot
Definition main_impl.cc:71
static constexpr const char * DEFAULT_VM_SERVICE_SERVER_IP
static constexpr int DEFAULT_VM_SERVICE_SERVER_PORT
static constexpr int INVALID_VM_SERVICE_SERVER_PORT
#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName)
Definition globals.h:593