Files
sdk/runtime/bin/common_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

174 lines
6.2 KiB
C++

// Copyright (c) 2025, 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_COMMON_OPTIONS_H_
#define RUNTIME_BIN_COMMON_OPTIONS_H_
#include "include/dart_api.h"
#include "platform/assert.h"
#include "platform/globals.h"
#include "platform/syslog.h"
namespace dart {
namespace bin {
static void _PrintVersion() {
Syslog::Print("Dart SDK version: %s\n", Dart_VersionString());
}
// clang-format off
static void _PrintUsage() {
Syslog::Print(
"Usage: dart [<vm-flags>] <dart-script-file> [<script-arguments>]\n"
"\n"
"Executes the Dart script <dart-script-file> with "
"the given list of <script-arguments>.\n"
"\n");
}
static void _PrintNonVerboseUsage() {
Syslog::Print(
"Common VM flags:\n"
#if !defined(PRODUCT)
"--enable-asserts\n"
" Enable assert statements.\n"
#endif // !defined(PRODUCT)
"--help or -h\n"
" Display this message (add -v or --verbose for information about\n"
" all VM options).\n"
"--packages=<path>\n"
" Where to find a package spec file.\n"
"--define=<key>=<value> or -D<key>=<value>\n"
" Define an environment declaration. To specify multiple declarations,\n"
" use multiple instances of this option.\n"
#if !defined(PRODUCT)
"--observe[=<port>[/<bind-address>]]\n"
" The observe flag is a convenience flag used to run a program with a\n"
" set of options which are often useful for debugging under Dart DevTools.\n"
" These options are currently:\n"
" --enable-vm-service[=<port>[/<bind-address>]]\n"
" --serve-devtools\n"
" --pause-isolates-on-exit\n"
" --pause-isolates-on-unhandled-exceptions\n"
" --warn-on-pause-with-no-debugger\n"
" --timeline-streams=\"Compiler, Dart, GC, Microtask\"\n"
" This set is subject to change.\n"
" Please see these options (--help --verbose) for further documentation.\n"
"--write-service-info=<file_uri>\n"
" Outputs information necessary to connect to the VM service to the\n"
" specified file in JSON format. Useful for clients which are unable to\n"
" listen to stdout for the Dart VM service listening message.\n"
#endif // !defined(PRODUCT)
"--snapshot-kind=<snapshot_kind>\n"
"--snapshot=<file_name>\n"
" These snapshot options are used to generate a snapshot of the loaded\n"
" Dart script:\n"
" <snapshot-kind> controls the kind of snapshot, it could be\n"
" kernel(default) or app-jit\n"
" <file_name> specifies the file into which the snapshot is written\n"
"--version\n"
" Print the SDK version.\n");
}
static void _PrintVerboseUsage() {
Syslog::Print(
"Supported options:\n"
#if !defined(PRODUCT)
"--enable-asserts\n"
" Enable assert statements.\n"
#endif // !defined(PRODUCT)
"--help or -h\n"
" Display this message (add -v or --verbose for information about\n"
" all VM options).\n"
"--packages=<path>\n"
" Where to find a package spec file.\n"
"--define=<key>=<value> or -D<key>=<value>\n"
" Define an environment declaration. To specify multiple declarations,\n"
" use multiple instances of this option.\n"
#if !defined(PRODUCT)
"--observe[=<port>[/<bind-address>]]\n"
" The observe flag is a convenience flag used to run a program with a\n"
" set of options which are often useful for debugging under Dart DevTools.\n"
" These options are currently:\n"
" --enable-vm-service[=<port>[/<bind-address>]]\n"
" --serve-devtools\n"
" --pause-isolates-on-exit\n"
" --pause-isolates-on-unhandled-exceptions\n"
" --warn-on-pause-with-no-debugger\n"
" --timeline-streams=\"Compiler, Dart, GC, Microtask\"\n"
" This set is subject to change.\n"
" Please see these options for further documentation.\n"
"--profile-microtasks\n"
" Record information about each microtask. Information about completed\n"
" microtasks will be written to the \"Microtask\" timeline stream.\n"
#endif // !defined(PRODUCT)
"--version\n"
" Print the VM version.\n"
"\n"
"--trace-loading\n"
" enables tracing of library and script loading\n"
"\n"
#if !defined(PRODUCT)
"--enable-vm-service[=<port>[/<bind-address>]]\n"
" Enables the VM service and listens on specified port for connections\n"
" (default port number is 8181, default bind address is localhost).\n"
"\n"
"--disable-service-auth-codes\n"
" Disables the requirement for an authentication code to communicate with\n"
" the VM service. Authentication codes help protect against CSRF attacks,\n"
" so it is not recommended to disable them unless behind a firewall on a\n"
" secure device.\n"
"\n"
"--enable-service-port-fallback\n"
" When the VM service is told to bind to a particular port, fallback to 0 if\n"
" it fails to bind instead of failing to start.\n"
"\n"
#endif // !defined(PRODUCT)
"--root-certs-file=<path>\n"
" The path to a file containing the trusted root certificates to use for\n"
" secure socket connections.\n"
"--root-certs-cache=<path>\n"
" The path to a cache directory containing the trusted root certificates to\n"
" use for secure socket connections.\n"
#if defined(DART_HOST_OS_LINUX) || \
defined(DART_HOST_OS_ANDROID) || \
defined(DART_HOST_OS_FUCHSIA)
"--namespace=<path>\n"
" The path to a directory that dart:io calls will treat as the root of the\n"
" filesystem.\n"
#endif // defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_ANDROID)
"\n"
"The following options are only used for VM development and may\n"
"be changed in any future version:\n");
const char* print_flags = "--print_flags";
char* error = Dart_SetVMFlags(1, &print_flags);
ASSERT(error == nullptr);
}
// clang-format on
// Returns true if arg starts with the characters "--" followed by option, but
// all '_' in the option name are treated as '-'.
static bool IsOption(const char* arg, const char* option) {
if (arg[0] != '-' || arg[1] != '-') {
// Special case first two characters to avoid recognizing __flag.
return false;
}
for (int i = 0; option[i] != '\0'; i++) {
auto c = arg[i + 2];
if (c == '\0') {
// Not long enough.
return false;
}
if ((c == '_' ? '-' : c) != option[i]) {
return false;
}
}
return true;
}
} // namespace bin
} // namespace dart
#endif // RUNTIME_BIN_COMMON_OPTIONS_H_