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

Side by Side Diff: tools/gn/args.cc

Issue 2651023004: Display override values in GN args help. (Closed)
Patch Set: Spellinc Created 3 years, 10 months 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 unified diff | Download patch
« no previous file with comments | « tools/gn/args.h ('k') | tools/gn/command_args.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "tools/gn/args.h" 5 #include "tools/gn/args.h"
6 6
7 #include "base/sys_info.h" 7 #include "base/sys_info.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "tools/gn/string_utils.h" 9 #include "tools/gn/string_utils.h"
10 #include "tools/gn/variables.h" 10 #include "tools/gn/variables.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 override != overrides->end();) { 77 override != overrides->end();) {
78 if (declared_arguments.find(override->first) == declared_arguments.end()) 78 if (declared_arguments.find(override->first) == declared_arguments.end())
79 ++override; 79 ++override;
80 else 80 else
81 overrides->erase(override++); 81 overrides->erase(override++);
82 } 82 }
83 } 83 }
84 84
85 } // namespace 85 } // namespace
86 86
87 Args::ValueWithOverride::ValueWithOverride()
88 : default_value(),
89 has_override(false),
90 override_value() {
91 }
92
93 Args::ValueWithOverride::ValueWithOverride(const Value& def_val)
94 : default_value(def_val),
95 has_override(false),
96 override_value() {
97 }
98
99 Args::ValueWithOverride::~ValueWithOverride() {
100 }
101
87 Args::Args() { 102 Args::Args() {
88 } 103 }
89 104
90 Args::Args(const Args& other) 105 Args::Args(const Args& other)
91 : overrides_(other.overrides_), 106 : overrides_(other.overrides_),
92 all_overrides_(other.all_overrides_), 107 all_overrides_(other.all_overrides_),
93 declared_arguments_per_toolchain_( 108 declared_arguments_per_toolchain_(
94 other.declared_arguments_per_toolchain_), 109 other.declared_arguments_per_toolchain_),
95 toolchain_overrides_(other.toolchain_overrides_) { 110 toolchain_overrides_(other.toolchain_overrides_) {
96 } 111 }
(...skipping 20 matching lines...) Expand all
117 const Value* Args::GetArgOverride(const char* name) const { 132 const Value* Args::GetArgOverride(const char* name) const {
118 base::AutoLock lock(lock_); 133 base::AutoLock lock(lock_);
119 134
120 Scope::KeyValueMap::const_iterator found = 135 Scope::KeyValueMap::const_iterator found =
121 all_overrides_.find(base::StringPiece(name)); 136 all_overrides_.find(base::StringPiece(name));
122 if (found == all_overrides_.end()) 137 if (found == all_overrides_.end())
123 return nullptr; 138 return nullptr;
124 return &found->second; 139 return &found->second;
125 } 140 }
126 141
127 Scope::KeyValueMap Args::GetAllOverrides() const {
128 base::AutoLock lock(lock_);
129 return all_overrides_;
130 }
131
132 void Args::SetupRootScope(Scope* dest, 142 void Args::SetupRootScope(Scope* dest,
133 const Scope::KeyValueMap& toolchain_overrides) const { 143 const Scope::KeyValueMap& toolchain_overrides) const {
134 base::AutoLock lock(lock_); 144 base::AutoLock lock(lock_);
135 145
136 SetSystemVarsLocked(dest); 146 SetSystemVarsLocked(dest);
137 147
138 // Apply overrides for already declared args. 148 // Apply overrides for already declared args.
139 // (i.e. the system vars we set above) 149 // (i.e. the system vars we set above)
140 ApplyOverridesLocked(overrides_, dest); 150 ApplyOverridesLocked(overrides_, dest);
141 ApplyOverridesLocked(toolchain_overrides, dest); 151 ApplyOverridesLocked(toolchain_overrides, dest);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 candidates.push_back(declared_arg.first); 257 candidates.push_back(declared_arg.first);
248 } 258 }
249 base::StringPiece suggestion = SpellcheckString(name, candidates); 259 base::StringPiece suggestion = SpellcheckString(name, candidates);
250 if (!suggestion.empty()) 260 if (!suggestion.empty())
251 err_help = "Did you mean \"" + suggestion + "\"?\n\n" + err_help; 261 err_help = "Did you mean \"" + suggestion + "\"?\n\n" + err_help;
252 262
253 *err = Err(value.origin(), "Build argument has no effect.", err_help); 263 *err = Err(value.origin(), "Build argument has no effect.", err_help);
254 return false; 264 return false;
255 } 265 }
256 266
257 void Args::MergeDeclaredArguments(Scope::KeyValueMap* dest) const { 267 Args::ValueWithOverrideMap Args::GetAllArguments() const {
268 ValueWithOverrideMap result;
269
258 base::AutoLock lock(lock_); 270 base::AutoLock lock(lock_);
271
272 // Default values.
259 for (const auto& map_pair : declared_arguments_per_toolchain_) { 273 for (const auto& map_pair : declared_arguments_per_toolchain_) {
260 for (const auto& arg : map_pair.second) 274 for (const auto& arg : map_pair.second)
261 (*dest)[arg.first] = arg.second; 275 result.insert(std::make_pair(arg.first, ValueWithOverride(arg.second)));
262 } 276 }
277
278 // Merge in overrides.
279 for (const auto& over : overrides_) {
280 auto found = result.find(over.first);
281 if (found != result.end()) {
282 found->second.has_override = true;
283 found->second.override_value = over.second;
284 }
285 }
286
287 return result;
263 } 288 }
264 289
265 void Args::SetSystemVarsLocked(Scope* dest) const { 290 void Args::SetSystemVarsLocked(Scope* dest) const {
266 lock_.AssertAcquired(); 291 lock_.AssertAcquired();
267 292
268 // Host OS. 293 // Host OS.
269 const char* os = nullptr; 294 const char* os = nullptr;
270 #if defined(OS_WIN) 295 #if defined(OS_WIN)
271 os = "win"; 296 os = "win";
272 #elif defined(OS_MACOSX) 297 #elif defined(OS_MACOSX)
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 Scope* scope) const { 399 Scope* scope) const {
375 lock_.AssertAcquired(); 400 lock_.AssertAcquired();
376 return declared_arguments_per_toolchain_[scope->settings()]; 401 return declared_arguments_per_toolchain_[scope->settings()];
377 } 402 }
378 403
379 Scope::KeyValueMap& Args::OverridesForToolchainLocked( 404 Scope::KeyValueMap& Args::OverridesForToolchainLocked(
380 Scope* scope) const { 405 Scope* scope) const {
381 lock_.AssertAcquired(); 406 lock_.AssertAcquired();
382 return toolchain_overrides_[scope->settings()]; 407 return toolchain_overrides_[scope->settings()];
383 } 408 }
OLDNEW
« no previous file with comments | « tools/gn/args.h ('k') | tools/gn/command_args.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698