Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Unified Diff: tools/gn/args.cc

Issue 2552593002: gn: Add spelling suggestions for args.gn and --args. (Closed)
Patch Set: rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/args.cc
diff --git a/tools/gn/args.cc b/tools/gn/args.cc
index 7285d7a5388a4e042d7674f14090c2d3446fc58c..022192f96e57ac853931dafdfbf5f8c111ca39ad 100644
--- a/tools/gn/args.cc
+++ b/tools/gn/args.cc
@@ -6,6 +6,7 @@
#include "base/sys_info.h"
#include "build/build_config.h"
+#include "tools/gn/string_utils.h"
#include "tools/gn/variables.h"
const char kBuildArgs_Help[] =
@@ -219,19 +220,34 @@ bool Args::DeclareArgs(const Scope::KeyValueMap& args,
bool Args::VerifyAllOverridesUsed(Err* err) const {
base::AutoLock lock(lock_);
- Scope::KeyValueMap all_overrides(all_overrides_);
+ Scope::KeyValueMap unused_overrides(all_overrides_);
for (const auto& map_pair : declared_arguments_per_toolchain_)
- RemoveDeclaredOverrides(map_pair.second, &all_overrides);
+ RemoveDeclaredOverrides(map_pair.second, &unused_overrides);
- if (all_overrides.empty())
+ if (unused_overrides.empty())
return true;
- *err = Err(
- all_overrides.begin()->second.origin(), "Build argument has no effect.",
- "The variable \"" + all_overrides.begin()->first.as_string() +
- "\" was set as a build argument\nbut never appeared in a " +
- "declare_args() block in any buildfile.\n\n"
- "To view possible args, run \"gn args --list <builddir>\"");
+ // Some assignments in args.gn had no effect. Show an error for the first
+ // unused assignment.
+ base::StringPiece name = unused_overrides.begin()->first;
+ const Value& value = unused_overrides.begin()->second;
+
+ std::string err_help(
+ "The variable \"" + name + "\" was set as a build argument\n"
+ "but never appeared in a declare_args() block in any buildfile.\n\n"
+ "To view all possible args, run \"gn args --list <builddir>\"");
+
+ // Use all declare_args for a spelling suggestion.
+ std::vector<base::StringPiece> candidates;
+ for (const auto& map_pair : declared_arguments_per_toolchain_) {
+ for (const auto& declared_arg : map_pair.second)
+ candidates.push_back(declared_arg.first);
+ }
+ base::StringPiece suggestion = SpellcheckString(name, candidates);
+ if (!suggestion.empty())
+ err_help = "Did you mean \"" + suggestion + "\"?\n\n" + err_help;
+
+ *err = Err(value.origin(), "Build argument has no effect.", err_help);
return false;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698