OLD | NEW |
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/variables.h" | 9 #include "tools/gn/variables.h" |
10 | 10 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 err->AppendSubErr(Err(previously_declared->second.origin(), | 177 err->AppendSubErr(Err(previously_declared->second.origin(), |
178 "Previous declaration.", | 178 "Previous declaration.", |
179 "See also \"gn help buildargs\" for more on how " | 179 "See also \"gn help buildargs\" for more on how " |
180 "build arguments work.")); | 180 "build arguments work.")); |
181 return false; | 181 return false; |
182 } | 182 } |
183 } else { | 183 } else { |
184 declared_arguments.insert(arg); | 184 declared_arguments.insert(arg); |
185 } | 185 } |
186 | 186 |
| 187 // In all the cases below, mark the variable used. If a variable is set |
| 188 // that's only used in one toolchain, we don't want to report unused |
| 189 // variable errors in other toolchains. Also, in some cases it's reasonable |
| 190 // for the build file to overwrite the value with a different value based |
| 191 // on some other condition without dereferencing the value first. |
| 192 |
187 // Check whether this argument has been overridden on the toolchain level | 193 // Check whether this argument has been overridden on the toolchain level |
188 // and use the override instead. | 194 // and use the override instead. |
189 Scope::KeyValueMap::const_iterator toolchain_override = | 195 Scope::KeyValueMap::const_iterator toolchain_override = |
190 toolchain_overrides.find(arg.first); | 196 toolchain_overrides.find(arg.first); |
191 if (toolchain_override != toolchain_overrides.end()) { | 197 if (toolchain_override != toolchain_overrides.end()) { |
192 scope_to_set->SetValue(toolchain_override->first, | 198 scope_to_set->SetValue(toolchain_override->first, |
193 toolchain_override->second, | 199 toolchain_override->second, |
194 toolchain_override->second.origin()); | 200 toolchain_override->second.origin()); |
| 201 scope_to_set->MarkUsed(arg.first); |
195 continue; | 202 continue; |
196 } | 203 } |
197 | 204 |
198 // Check whether this argument has been overridden and use the override | 205 // Check whether this argument has been overridden and use the override |
199 // instead. | 206 // instead. |
200 Scope::KeyValueMap::const_iterator override = overrides_.find(arg.first); | 207 Scope::KeyValueMap::const_iterator override = overrides_.find(arg.first); |
201 if (override != overrides_.end()) { | 208 if (override != overrides_.end()) { |
202 scope_to_set->SetValue(override->first, override->second, | 209 scope_to_set->SetValue(override->first, override->second, |
203 override->second.origin()); | 210 override->second.origin()); |
| 211 scope_to_set->MarkUsed(override->first); |
204 continue; | 212 continue; |
205 } | 213 } |
206 | 214 |
207 // Mark the variable used so the build script can override it in | |
208 // certain cases without getting unused value errors. | |
209 scope_to_set->SetValue(arg.first, arg.second, arg.second.origin()); | 215 scope_to_set->SetValue(arg.first, arg.second, arg.second.origin()); |
210 scope_to_set->MarkUsed(arg.first); | 216 scope_to_set->MarkUsed(arg.first); |
211 } | 217 } |
212 | 218 |
213 return true; | 219 return true; |
214 } | 220 } |
215 | 221 |
216 bool Args::VerifyAllOverridesUsed(Err* err) const { | 222 bool Args::VerifyAllOverridesUsed(Err* err) const { |
217 base::AutoLock lock(lock_); | 223 base::AutoLock lock(lock_); |
218 Scope::KeyValueMap all_overrides(all_overrides_); | 224 Scope::KeyValueMap all_overrides(all_overrides_); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 Scope* scope) const { | 346 Scope* scope) const { |
341 lock_.AssertAcquired(); | 347 lock_.AssertAcquired(); |
342 return declared_arguments_per_toolchain_[scope->settings()]; | 348 return declared_arguments_per_toolchain_[scope->settings()]; |
343 } | 349 } |
344 | 350 |
345 Scope::KeyValueMap& Args::OverridesForToolchainLocked( | 351 Scope::KeyValueMap& Args::OverridesForToolchainLocked( |
346 Scope* scope) const { | 352 Scope* scope) const { |
347 lock_.AssertAcquired(); | 353 lock_.AssertAcquired(); |
348 return toolchain_overrides_[scope->settings()]; | 354 return toolchain_overrides_[scope->settings()]; |
349 } | 355 } |
OLD | NEW |