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

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

Issue 137713007: Check for GN args using the union of all rather than individually. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
« 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 "build/build_config.h" 7 #include "build/build_config.h"
8 #include "tools/gn/variables.h" 8 #include "tools/gn/variables.h"
9 9
10 #if defined(OS_WIN) 10 #if defined(OS_WIN)
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 const Value* Args::GetArgOverride(const char* name) const { 86 const Value* Args::GetArgOverride(const char* name) const {
87 base::AutoLock lock(lock_); 87 base::AutoLock lock(lock_);
88 88
89 Scope::KeyValueMap::const_iterator found = 89 Scope::KeyValueMap::const_iterator found =
90 all_overrides_.find(base::StringPiece(name)); 90 all_overrides_.find(base::StringPiece(name));
91 if (found == all_overrides_.end()) 91 if (found == all_overrides_.end())
92 return NULL; 92 return NULL;
93 return &found->second; 93 return &found->second;
94 } 94 }
95 95
96 Scope::KeyValueMap Args::GetAllOverrides() const {
97 base::AutoLock lock(lock_);
98 return all_overrides_;
99 }
100
96 void Args::SetupRootScope(Scope* dest, 101 void Args::SetupRootScope(Scope* dest,
97 const Scope::KeyValueMap& toolchain_overrides) const { 102 const Scope::KeyValueMap& toolchain_overrides) const {
98 base::AutoLock lock(lock_); 103 base::AutoLock lock(lock_);
99 104
100 SetSystemVarsLocked(dest); 105 SetSystemVarsLocked(dest);
101 ApplyOverridesLocked(overrides_, dest); 106 ApplyOverridesLocked(overrides_, dest);
102 ApplyOverridesLocked(toolchain_overrides, dest); 107 ApplyOverridesLocked(toolchain_overrides, dest);
103 SaveOverrideRecordLocked(toolchain_overrides); 108 SaveOverrideRecordLocked(toolchain_overrides);
104 } 109 }
105 110
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 scope_to_set->SetValue(i->first, i->second, i->second.origin()); 162 scope_to_set->SetValue(i->first, i->second, i->second.origin());
158 scope_to_set->MarkUsed(i->first); 163 scope_to_set->MarkUsed(i->first);
159 } 164 }
160 } 165 }
161 166
162 return true; 167 return true;
163 } 168 }
164 169
165 bool Args::VerifyAllOverridesUsed(Err* err) const { 170 bool Args::VerifyAllOverridesUsed(Err* err) const {
166 base::AutoLock lock(lock_); 171 base::AutoLock lock(lock_);
172 return VerifyAllOverridesUsed(all_overrides_, declared_arguments_, err);
173 }
167 174
168 for (Scope::KeyValueMap::const_iterator i = all_overrides_.begin(); 175 bool Args::VerifyAllOverridesUsed(
169 i != all_overrides_.end(); ++i) { 176 const Scope::KeyValueMap& overrides,
170 if (declared_arguments_.find(i->first) == declared_arguments_.end()) { 177 const Scope::KeyValueMap& declared_arguments,
178 Err* err) {
179 for (Scope::KeyValueMap::const_iterator i = overrides.begin();
180 i != overrides.end(); ++i) {
181 if (declared_arguments.find(i->first) == declared_arguments.end()) {
171 // Get a list of all possible overrides for help with error finding. 182 // Get a list of all possible overrides for help with error finding.
172 // 183 //
173 // It might be nice to do edit distance checks to see if we can find one 184 // It might be nice to do edit distance checks to see if we can find one
174 // close to what you typed. 185 // close to what you typed.
175 std::string all_declared_str; 186 std::string all_declared_str;
176 for (Scope::KeyValueMap::const_iterator cur_str = 187 for (Scope::KeyValueMap::const_iterator cur_str =
177 declared_arguments_.begin(); 188 declared_arguments.begin();
178 cur_str != declared_arguments_.end(); ++cur_str) { 189 cur_str != declared_arguments.end(); ++cur_str) {
179 if (cur_str != declared_arguments_.begin()) 190 if (cur_str != declared_arguments.begin())
180 all_declared_str += ", "; 191 all_declared_str += ", ";
181 all_declared_str += cur_str->first.as_string(); 192 all_declared_str += cur_str->first.as_string();
182 } 193 }
183 194
184 *err = Err(i->second.origin(), "Build argument has no effect.", 195 *err = Err(i->second.origin(), "Build argument has no effect.",
185 "The variable \"" + i->first.as_string() + "\" was set as a build " 196 "The variable \"" + i->first.as_string() + "\" was set as a build "
186 "argument\nbut never appeared in a declare_args() block in any " 197 "argument\nbut never appeared in a declare_args() block in any "
187 "buildfile.\n\nPossible arguments: " + all_declared_str); 198 "buildfile.\n\nPossible arguments: " + all_declared_str);
188 return false; 199 return false;
189 } 200 }
190 } 201 }
191 return true; 202 return true;
192 } 203 }
193 204
205 void Args::MergeDeclaredArguments(Scope::KeyValueMap* dest) const {
206 base::AutoLock lock(lock_);
207
208 for (Scope::KeyValueMap::const_iterator i = declared_arguments_.begin();
209 i != declared_arguments_.end(); ++i)
210 (*dest)[i->first] = i->second;
211 }
212
194 void Args::SetSystemVarsLocked(Scope* dest) const { 213 void Args::SetSystemVarsLocked(Scope* dest) const {
214 lock_.AssertAcquired();
215
195 // Host OS. 216 // Host OS.
196 const char* os = NULL; 217 const char* os = NULL;
197 #if defined(OS_WIN) 218 #if defined(OS_WIN)
198 os = "win"; 219 os = "win";
199 #elif defined(OS_MACOSX) 220 #elif defined(OS_MACOSX)
200 os = "mac"; 221 os = "mac";
201 #elif defined(OS_LINUX) 222 #elif defined(OS_LINUX)
202 os = "linux"; 223 os = "linux";
203 #else 224 #else
204 #error Unknown OS type. 225 #error Unknown OS type.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 // Mark these variables used so the build config file can override them 278 // Mark these variables used so the build config file can override them
258 // without geting a warning about overwriting an unused variable. 279 // without geting a warning about overwriting an unused variable.
259 declared_arguments_[variables::kOs] = os_val; 280 declared_arguments_[variables::kOs] = os_val;
260 declared_arguments_[variables::kCpuArch] = arch_val; 281 declared_arguments_[variables::kCpuArch] = arch_val;
261 dest->MarkUsed(variables::kCpuArch); 282 dest->MarkUsed(variables::kCpuArch);
262 dest->MarkUsed(variables::kOs); 283 dest->MarkUsed(variables::kOs);
263 } 284 }
264 285
265 void Args::ApplyOverridesLocked(const Scope::KeyValueMap& values, 286 void Args::ApplyOverridesLocked(const Scope::KeyValueMap& values,
266 Scope* scope) const { 287 Scope* scope) const {
288 lock_.AssertAcquired();
267 for (Scope::KeyValueMap::const_iterator i = values.begin(); 289 for (Scope::KeyValueMap::const_iterator i = values.begin();
268 i != values.end(); ++i) 290 i != values.end(); ++i)
269 scope->SetValue(i->first, i->second, i->second.origin()); 291 scope->SetValue(i->first, i->second, i->second.origin());
270 } 292 }
271 293
272 void Args::SaveOverrideRecordLocked(const Scope::KeyValueMap& values) const { 294 void Args::SaveOverrideRecordLocked(const Scope::KeyValueMap& values) const {
295 lock_.AssertAcquired();
273 for (Scope::KeyValueMap::const_iterator i = values.begin(); 296 for (Scope::KeyValueMap::const_iterator i = values.begin();
274 i != values.end(); ++i) 297 i != values.end(); ++i)
275 all_overrides_[i->first] = i->second; 298 all_overrides_[i->first] = i->second;
276 } 299 }
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