diff options
author | Eric Holk <eholk@google.com> | 2021-01-30 02:03:29 +0000 |
---|---|---|
committer | Treehugger Robot <treehugger-gerrit@google.com> | 2021-02-17 15:05:02 +0000 |
commit | 3dba023d4fb47882fa215715c196cfa3be30c098 (patch) | |
tree | da22f82b7cde87f37100f715a0e05f332b377f73 /cmdline | |
parent | 381d35c1b01401e193544f679bfaf4f5c197f7cd (diff) |
Add a server-configurable flags API
Adds a new set of flags that can be set by the command line, server
configuration, or system properties. These flags can be used to enable
or disable certain features or otherwise change their behavior. The
flexible configuration options facilitate both development and also
experimentation.
As an example of their use, this CL also moves the
-Xwrite-metrics-to-log command line option to the flags system
instead. Future work will migrate the rest of the metrics settings.
Test: ./test/run-test --host --jit 2232-write-metrics-to-log
Bug: 175050458
Change-Id: I1ef37e7d355204a3172b7aa5c0baa4cbd8c7076b
Diffstat (limited to 'cmdline')
-rw-r--r-- | cmdline/cmdline_parser.h | 18 | ||||
-rw-r--r-- | cmdline/cmdline_types.h | 17 |
2 files changed, 35 insertions, 0 deletions
diff --git a/cmdline/cmdline_parser.h b/cmdline/cmdline_parser.h index 22eb44c211..7e343f8ef2 100644 --- a/cmdline/cmdline_parser.h +++ b/cmdline/cmdline_parser.h @@ -210,6 +210,24 @@ struct CmdlineParser { return parent_; } + // Write the results of this argument into a variable pointed to by destination. + // An optional is used to tell whether the command line argument was present. + CmdlineParser::Builder& IntoLocation(std::optional<TArg>* destination) { + save_value_ = [destination](TArg& value) { + *destination = value; + }; + + load_value_ = [destination]() -> TArg& { + return destination->value(); + }; + + save_value_specified_ = true; + load_value_specified_ = true; + + CompleteArgument(); + return parent_; + } + // Ensure we always move this when returning a new builder. ArgumentBuilder(ArgumentBuilder&&) = default; diff --git a/cmdline/cmdline_types.h b/cmdline/cmdline_types.h index 2d7d5f1b78..7f01be6472 100644 --- a/cmdline/cmdline_types.h +++ b/cmdline/cmdline_types.h @@ -21,6 +21,7 @@ #include <list> #include <ostream> +#include "android-base/parsebool.h" #include "android-base/stringprintf.h" #include "cmdline_type_parser.h" #include "detail/cmdline_debug_detail.h" @@ -67,6 +68,22 @@ struct CmdlineType<Unit> : CmdlineTypeParser<Unit> { }; template <> +struct CmdlineType<bool> : CmdlineTypeParser<bool> { + Result Parse(const std::string& args) { + switch (::android::base::ParseBool(args)) { + case ::android::base::ParseBoolResult::kError: + return Result::Failure("Could not parse '" + args + "' as boolean"); + case ::android::base::ParseBoolResult::kTrue: + return Result::Success(true); + case ::android::base::ParseBoolResult::kFalse: + return Result::Success(false); + } + } + + static const char* DescribeType() { return "true|false|0|1|y|n|yes|no|on|off"; } +}; + +template <> struct CmdlineType<JdwpProvider> : CmdlineTypeParser<JdwpProvider> { /* * Handle a single JDWP provider name. Must be either 'internal', 'default', or the file name of |