Files
sdk/runtime/bin/main_options.h
T
asiva 5399dbf6f6 [VM/dartdev] Switch dartdev to use an AOT runtime.
- split the Dart CLI tool out of the VM into it's own embedder which
  runs in AOT mode. The pure Dart VM executable is called 'dartvm' and
  has no Dart CLI functionality in it
- the Dart CLI executable parses the CLI commands and invokes the rest
  of the AOT tools in the same process, for the 'run' and 'test'
  commands it execs a process which runs 'dartvm' to run
- 'dart hello.dart' execs the 'dartvm' process and runs 'hello.dart'
- the Dart CLI is not generated for ia32 as we are not shipping a
  Dart SDK for ia32 anymore (support to execute the 'dartvm' for ia32
  architecture is retained)
- the Dart CLI tool is not built in the internal Dart SDK builds

TEST=ci

Some performance improvement numbers
'dart format pkg/dartdev' goes from 1.17 secs to 0.22 secs
'dart doc pkg/dartdev' goes from 100.2 secs to 66.6 secs
'dart fix pkg/dartdev' goes from 19.3 secs to 14.5 secs

Change-Id: I66984a26cb2ab014b34dc1873f1f3d2884e13518
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364202
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2025-07-04 13:22:13 -07:00

269 lines
11 KiB
C++

// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#ifndef RUNTIME_BIN_MAIN_OPTIONS_H_
#define RUNTIME_BIN_MAIN_OPTIONS_H_
#include "bin/dartutils.h"
#include "bin/dfe.h"
#include "bin/options.h"
#include "platform/globals.h"
#include "platform/growable_array.h"
#include "platform/hashmap.h"
namespace dart {
namespace bin {
// A list of options taking string arguments. Organized as:
// V(flag_name, field_name)
// The value of the flag can then be accessed with Options::field_name().
#define STRING_OPTIONS_LIST(V) \
V(packages, packages_file) \
V(snapshot, snapshot_filename) \
V(snapshot_depfile, snapshot_deps_filename) \
V(depfile, depfile) \
V(depfile_output_filename, depfile_output_filename) \
V(root_certs_file, root_certs_file) \
V(root_certs_cache, root_certs_cache) \
V(namespace, namespc) \
V(write_service_info, vm_write_service_info_filename) \
V(executable_name, executable_name) \
/* The purpose of these flags is documented in */ \
/* pkg/dartdev/lib/src/commands/compilation_server.dart. */ \
V(resident_server_info_file, resident_server_info_file_path) \
V(resident_compiler_info_file, resident_compiler_info_file_path)
// As STRING_OPTIONS_LIST but for boolean valued options. The default value is
// always false, and the presence of the flag switches the value to true.
#define BOOL_OPTIONS_LIST(V) \
V(version, version_option) \
V(compile_all, compile_all) \
V(disable_service_origin_check, vm_service_dev_mode) \
V(disable_service_auth_codes, vm_service_auth_disabled) \
V(deterministic, deterministic) \
V(trace_loading, trace_loading) \
V(short_socket_read, short_socket_read) \
V(short_socket_write, short_socket_write) \
V(disable_exit, exit_disabled) \
V(suppress_core_dump, suppress_core_dump) \
V(enable_service_port_fallback, enable_service_port_fallback) \
V(long_ssl_cert_evaluation, long_ssl_cert_evaluation) \
V(bypass_trusting_system_roots, bypass_trusting_system_roots) \
V(delayed_filewatch_callback, delayed_filewatch_callback) \
V(mark_main_isolate_as_system_isolate, mark_main_isolate_as_system_isolate) \
V(no_serve_devtools, disable_devtools) \
V(serve_devtools, enable_devtools) \
V(no_serve_observatory, disable_observatory) \
V(serve_observatory, enable_observatory) \
V(print_dtd, print_dtd) \
V(profile_microtasks, profile_microtasks) \
/* The purpose of this flag is documented in */ \
/* pkg/dartdev/lib/src/commands/run.dart. */ \
V(resident, resident)
// Boolean flags that have a short form.
#define SHORT_BOOL_OPTIONS_LIST(V) \
V(h, help, help_option) \
V(v, verbose, verbose_option)
#define DEBUG_BOOL_OPTIONS_LIST(V) \
V(force_load_from_memory, force_load_from_memory)
// A list of flags taking arguments from an enum. Organized as:
// V(flag_name, enum_type, field_name)
// In main_options.cc there must be a list of strings that matches the enum
// called k{enum_type}Names. The field is not automatically declared in
// main_options.cc. It must be explicitly declared.
#define ENUM_OPTIONS_LIST(V) \
V(snapshot_kind, SnapshotKind, gen_snapshot_kind) \
V(verbosity, VerbosityLevel, verbosity)
// Callbacks passed to DEFINE_CB_OPTION().
#define CB_OPTIONS_LIST(V) \
V(ProcessEnvironmentOption) \
V(ProcessEnableVmServiceOption) \
V(ProcessObserveOption) \
V(ProcessDdsOption)
// This enum must match the strings in kSnapshotKindNames in main_options.cc.
enum SnapshotKind {
kNone,
kKernel,
kAppJIT,
};
enum VerbosityLevel {
kError,
kWarning,
kInfo,
kAll,
};
static const char* const kVerbosityLevelNames[] = {
"error", "warning", "info", "all", nullptr,
};
class Options {
public:
// Returns true if argument parsing succeeded. False otherwise.
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);
#define STRING_OPTION_GETTER(flag, variable) \
static const char* variable() { return variable##_; }
STRING_OPTIONS_LIST(STRING_OPTION_GETTER)
#undef STRING_OPTION_GETTER
#define BOOL_OPTION_GETTER(flag, variable) \
static bool variable() { return variable##_; }
BOOL_OPTIONS_LIST(BOOL_OPTION_GETTER)
#if defined(DEBUG)
DEBUG_BOOL_OPTIONS_LIST(BOOL_OPTION_GETTER)
#endif
#undef BOOL_OPTION_GETTER
#define SHORT_BOOL_OPTION_GETTER(short_name, long_name, variable) \
static bool variable() { return variable##_; }
SHORT_BOOL_OPTIONS_LIST(SHORT_BOOL_OPTION_GETTER)
#undef SHORT_BOOL_OPTION_GETTER
#define ENUM_OPTIONS_GETTER(flag, type, variable) \
static type variable() { return variable##_; }
ENUM_OPTIONS_LIST(ENUM_OPTIONS_GETTER)
#undef ENUM_OPTIONS_GETTER
// Callbacks have to be public.
#define CB_OPTIONS_DECL(callback) \
static bool callback(const char* arg, CommandLineOptions* vm_options);
CB_OPTIONS_LIST(CB_OPTIONS_DECL)
#undef CB_OPTIONS_DECL
static dart::SimpleHashMap* environment() { return environment_; }
static bool enable_vm_service() { return enable_vm_service_; }
#if !defined(PRODUCT)
static const char* vm_service_server_ip() { return vm_service_server_ip_; }
static int vm_service_server_port() { return vm_service_server_port_; }
#endif // !defined(PRODUCT)
static bool enable_dds() { return enable_dds_; }
static Dart_KernelCompilationVerbosityLevel verbosity_level() {
return VerbosityLevelToDartAPI(verbosity_);
}
#if !defined(DART_PRECOMPILED_RUNTIME)
static DFE* dfe() { return dfe_; }
static void set_dfe(DFE* dfe) { dfe_ = dfe; }
#endif // !defined(DART_PRECOMPILED_RUNTIME)
static void PrintUsage();
static void PrintVersion();
static void Cleanup();
#if defined(DART_PRECOMPILED_RUNTIME)
// Get the list of options in DART_VM_OPTIONS.
static char** GetEnvArguments(int* argc);
#endif // defined(DART_PRECOMPILED_RUNTIME)
private:
static void DestroyEnvironment();
#if defined(DART_PRECOMPILED_RUNTIME)
static void DestroyEnvArgv();
#endif // defined(DART_PRECOMPILED_RUNTIME)
#define STRING_OPTION_DECL(flag, variable) static const char* variable##_;
STRING_OPTIONS_LIST(STRING_OPTION_DECL)
#undef STRING_OPTION_DECL
#define BOOL_OPTION_DECL(flag, variable) static bool variable##_;
BOOL_OPTIONS_LIST(BOOL_OPTION_DECL)
#if defined(DEBUG)
DEBUG_BOOL_OPTIONS_LIST(BOOL_OPTION_DECL)
#endif
#undef BOOL_OPTION_DECL
#define SHORT_BOOL_OPTION_DECL(short_name, long_name, variable) \
static bool variable##_;
SHORT_BOOL_OPTIONS_LIST(SHORT_BOOL_OPTION_DECL)
#undef SHORT_BOOL_OPTION_DECL
#define ENUM_OPTION_DECL(flag, type, variable) static type variable##_;
ENUM_OPTIONS_LIST(ENUM_OPTION_DECL)
#undef ENUM_OPTION_DECL
static dart::SimpleHashMap* environment_;
#if defined(DART_PRECOMPILED_RUNTIME)
static char** env_argv_;
static int env_argc_;
#endif // defined(DART_PRECOMPILED_RUNTIME)
// Frontend argument processing.
#if !defined(DART_PRECOMPILED_RUNTIME)
static DFE* dfe_;
#endif // !defined(DART_PRECOMPILED_RUNTIME)
static Dart_KernelCompilationVerbosityLevel VerbosityLevelToDartAPI(
VerbosityLevel level) {
switch (level) {
case kError:
return Dart_KernelCompilationVerbosityLevel_Error;
case kWarning:
return Dart_KernelCompilationVerbosityLevel_Warning;
case kInfo:
return Dart_KernelCompilationVerbosityLevel_Info;
case kAll:
return Dart_KernelCompilationVerbosityLevel_All;
default:
UNREACHABLE();
}
}
// VM Service argument processing.
static bool enable_vm_service_;
#if !defined(PRODUCT)
static const char* vm_service_server_ip_;
static int vm_service_server_port_;
#endif // !defined(PRODUCT)
static bool enable_dds_;
static bool ExtractPortAndAddress(const char* option_value,
int* out_port,
const char** out_ip,
int default_port,
const char* default_ip);
#define OPTION_FRIEND(flag, variable) friend class OptionProcessor_##flag;
STRING_OPTIONS_LIST(OPTION_FRIEND)
BOOL_OPTIONS_LIST(OPTION_FRIEND)
#if defined(DEBUG)
DEBUG_BOOL_OPTIONS_LIST(OPTION_FRIEND)
#endif
#undef OPTION_FRIEND
#define SHORT_BOOL_OPTION_FRIEND(short_name, long_name, variable) \
friend class OptionProcessor_##long_name;
SHORT_BOOL_OPTIONS_LIST(SHORT_BOOL_OPTION_FRIEND)
#undef SHORT_BOOL_OPTION_FRIEND
#define ENUM_OPTION_FRIEND(flag, type, variable) \
friend class OptionProcessor_##flag;
ENUM_OPTIONS_LIST(ENUM_OPTION_FRIEND)
#undef ENUM_OPTION_FRIEND
DISALLOW_ALLOCATION();
DISALLOW_IMPLICIT_CONSTRUCTORS(Options);
};
} // namespace bin
} // namespace dart
#endif // RUNTIME_BIN_MAIN_OPTIONS_H_