| 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/string_utils.h" |
| 9 #include "tools/gn/variables.h" | 10 #include "tools/gn/variables.h" |
| 10 | 11 |
| 11 const char kBuildArgs_Help[] = | 12 const char kBuildArgs_Help[] = |
| 12 R"(Build Arguments Overview | 13 R"(Build Arguments Overview |
| 13 | 14 |
| 14 Build arguments are variables passed in from outside of the build that build | 15 Build arguments are variables passed in from outside of the build that build |
| 15 files can query to determine how the build works. | 16 files can query to determine how the build works. |
| 16 | 17 |
| 17 How build arguments are set | 18 How build arguments are set |
| 18 | 19 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 213 |
| 213 scope_to_set->SetValue(arg.first, arg.second, arg.second.origin()); | 214 scope_to_set->SetValue(arg.first, arg.second, arg.second.origin()); |
| 214 scope_to_set->MarkUsed(arg.first); | 215 scope_to_set->MarkUsed(arg.first); |
| 215 } | 216 } |
| 216 | 217 |
| 217 return true; | 218 return true; |
| 218 } | 219 } |
| 219 | 220 |
| 220 bool Args::VerifyAllOverridesUsed(Err* err) const { | 221 bool Args::VerifyAllOverridesUsed(Err* err) const { |
| 221 base::AutoLock lock(lock_); | 222 base::AutoLock lock(lock_); |
| 222 Scope::KeyValueMap all_overrides(all_overrides_); | 223 Scope::KeyValueMap unused_overrides(all_overrides_); |
| 223 for (const auto& map_pair : declared_arguments_per_toolchain_) | 224 for (const auto& map_pair : declared_arguments_per_toolchain_) |
| 224 RemoveDeclaredOverrides(map_pair.second, &all_overrides); | 225 RemoveDeclaredOverrides(map_pair.second, &unused_overrides); |
| 225 | 226 |
| 226 if (all_overrides.empty()) | 227 if (unused_overrides.empty()) |
| 227 return true; | 228 return true; |
| 228 | 229 |
| 229 *err = Err( | 230 // Some assignments in args.gn had no effect. Show an error for the first |
| 230 all_overrides.begin()->second.origin(), "Build argument has no effect.", | 231 // unused assignment. |
| 231 "The variable \"" + all_overrides.begin()->first.as_string() + | 232 base::StringPiece name = unused_overrides.begin()->first; |
| 232 "\" was set as a build argument\nbut never appeared in a " + | 233 const Value& value = unused_overrides.begin()->second; |
| 233 "declare_args() block in any buildfile.\n\n" | 234 |
| 234 "To view possible args, run \"gn args --list <builddir>\""); | 235 std::string err_help( |
| 236 "The variable \"" + name + "\" was set as a build argument\n" |
| 237 "but never appeared in a declare_args() block in any buildfile.\n\n" |
| 238 "To view all possible args, run \"gn args --list <builddir>\""); |
| 239 |
| 240 // Use all declare_args for a spelling suggestion. |
| 241 std::vector<base::StringPiece> candidates; |
| 242 for (const auto& map_pair : declared_arguments_per_toolchain_) { |
| 243 for (const auto& declared_arg : map_pair.second) |
| 244 candidates.push_back(declared_arg.first); |
| 245 } |
| 246 base::StringPiece suggestion = SpellcheckString(name, candidates); |
| 247 if (!suggestion.empty()) |
| 248 err_help = "Did you mean \"" + suggestion + "\"?\n\n" + err_help; |
| 249 |
| 250 *err = Err(value.origin(), "Build argument has no effect.", err_help); |
| 235 return false; | 251 return false; |
| 236 } | 252 } |
| 237 | 253 |
| 238 void Args::MergeDeclaredArguments(Scope::KeyValueMap* dest) const { | 254 void Args::MergeDeclaredArguments(Scope::KeyValueMap* dest) const { |
| 239 base::AutoLock lock(lock_); | 255 base::AutoLock lock(lock_); |
| 240 for (const auto& map_pair : declared_arguments_per_toolchain_) { | 256 for (const auto& map_pair : declared_arguments_per_toolchain_) { |
| 241 for (const auto& arg : map_pair.second) | 257 for (const auto& arg : map_pair.second) |
| 242 (*dest)[arg.first] = arg.second; | 258 (*dest)[arg.first] = arg.second; |
| 243 } | 259 } |
| 244 } | 260 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 Scope* scope) const { | 368 Scope* scope) const { |
| 353 lock_.AssertAcquired(); | 369 lock_.AssertAcquired(); |
| 354 return declared_arguments_per_toolchain_[scope->settings()]; | 370 return declared_arguments_per_toolchain_[scope->settings()]; |
| 355 } | 371 } |
| 356 | 372 |
| 357 Scope::KeyValueMap& Args::OverridesForToolchainLocked( | 373 Scope::KeyValueMap& Args::OverridesForToolchainLocked( |
| 358 Scope* scope) const { | 374 Scope* scope) const { |
| 359 lock_.AssertAcquired(); | 375 lock_.AssertAcquired(); |
| 360 return toolchain_overrides_[scope->settings()]; | 376 return toolchain_overrides_[scope->settings()]; |
| 361 } | 377 } |
| OLD | NEW |