Add --overrides-only switch for `gn args`.
Specifying --overrides-only with --list will cause only build
arguments with overrides (e.g. from args.gn or //.gn) to get printed.
TEST=build gn; gn args --list --short --overrides-only
Change-Id: Ib6deff324841559a7785c2c62d1965ca31a80765
Reviewed-on: https://chromium-review.googlesource.com/642717
Reviewed-by: Brett Wilson <brettw@chromium.org>
Commit-Queue: Mike Bjorge <mbjorge@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#498611}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: fcbf3354655456f6c907f85eef7cfe84f982ac23
diff --git a/tools/gn/command_args.cc b/tools/gn/command_args.cc
index 2772fc2..2a24510 100644
--- a/tools/gn/command_args.cc
+++ b/tools/gn/command_args.cc
@@ -36,6 +36,7 @@
const char kSwitchList[] = "list";
const char kSwitchShort[] = "short";
+const char kSwitchOverridesOnly[] = "overrides-only";
bool DoesLineBeginWithComment(const base::StringPiece& line) {
// Skip whitespace.
@@ -171,9 +172,15 @@
args.insert(preserved);
}
+ // Cache this to avoid looking it up for each |arg| in the loops below.
+ const bool overrides_only =
+ base::CommandLine::ForCurrentProcess()->HasSwitch(kSwitchOverridesOnly);
+
if (base::CommandLine::ForCurrentProcess()->HasSwitch(kSwitchShort)) {
// Short <key>=<current_value> output.
for (const auto& arg : args) {
+ if (overrides_only && !arg.second.has_override)
+ continue;
OutputString(arg.first.as_string());
OutputString(" = ");
if (arg.second.has_override)
@@ -187,6 +194,8 @@
// Long output.
for (const auto& arg : args) {
+ if (overrides_only && !arg.second.has_override)
+ continue;
PrintArgHelp(arg.first, arg.second);
OutputString("\n");
}
@@ -323,7 +332,7 @@
extern const char kArgs_HelpShort[] =
"args: Display or configure arguments declared by the build.";
extern const char kArgs_Help[] =
- R"(gn args <out_dir> [--list] [--short] [--args]
+ R"(gn args <out_dir> [--list] [--short] [--args] [--overrides-only]
See also "gn help buildargs" for a more high-level overview of how
build arguments work.
@@ -345,7 +354,7 @@
Note: you can edit the build args manually by editing the file "args.gn"
in the build directory and then running "gn gen <out_dir>".
- gn args <out_dir> --list[=<exact_arg>] [--short]
+ gn args <out_dir> --list[=<exact_arg>] [--short] [--overrides-only]
Lists all build arguments available in the current configuration, or, if
an exact_arg is specified for the list flag, just that one build
argument.
@@ -357,6 +366,11 @@
If --short is specified, only the names and current values will be
printed.
+ If --overrides-only is specified, only the names and current values of
+ arguments that have been overridden (i.e. non-default arguments) will
+ be printed. Overrides come from the <out_dir>/args.gn file and //.gn
+
+
Examples
gn args out/Debug
@@ -366,6 +380,9 @@
Prints all arguments with their default values for the out/Debug
build.
+ gn args out/Debug --list --short --overrides-only
+ Prints overridden arguments for the out/Debug build.
+
gn args out/Debug --list=target_cpu
Prints information about the "target_cpu" argument for the "
"out/Debug