| 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/scheduler.h" |
| 9 #include "tools/gn/string_utils.h" | 10 #include "tools/gn/string_utils.h" |
| 10 #include "tools/gn/variables.h" | 11 #include "tools/gn/variables.h" |
| 11 | 12 |
| 12 const char kBuildArgs_Help[] = | 13 const char kBuildArgs_Help[] = |
| 13 R"(Build Arguments Overview | 14 R"(Build Arguments Overview |
| 14 | 15 |
| 15 Build arguments are variables passed in from outside of the build that build | 16 Build arguments are variables passed in from outside of the build that build |
| 16 files can query to determine how the build works. | 17 files can query to determine how the build works. |
| 17 | 18 |
| 18 How build arguments are set | 19 How build arguments are set |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 // on some other condition without dereferencing the value first. | 204 // on some other condition without dereferencing the value first. |
| 204 | 205 |
| 205 // Check whether this argument has been overridden on the toolchain level | 206 // Check whether this argument has been overridden on the toolchain level |
| 206 // and use the override instead. | 207 // and use the override instead. |
| 207 Scope::KeyValueMap::const_iterator toolchain_override = | 208 Scope::KeyValueMap::const_iterator toolchain_override = |
| 208 toolchain_overrides.find(arg.first); | 209 toolchain_overrides.find(arg.first); |
| 209 if (toolchain_override != toolchain_overrides.end()) { | 210 if (toolchain_override != toolchain_overrides.end()) { |
| 210 scope_to_set->SetValue(toolchain_override->first, | 211 scope_to_set->SetValue(toolchain_override->first, |
| 211 toolchain_override->second, | 212 toolchain_override->second, |
| 212 toolchain_override->second.origin()); | 213 toolchain_override->second.origin()); |
| 213 scope_to_set->MarkUsed(arg.first); | 214 scope_to_set->MarkUsed(arg.first, err); |
| 214 continue; | 215 continue; |
| 215 } | 216 } |
| 216 | 217 |
| 217 // Check whether this argument has been overridden and use the override | 218 // Check whether this argument has been overridden and use the override |
| 218 // instead. | 219 // instead. |
| 219 Scope::KeyValueMap::const_iterator override = overrides_.find(arg.first); | 220 Scope::KeyValueMap::const_iterator override = overrides_.find(arg.first); |
| 220 if (override != overrides_.end()) { | 221 if (override != overrides_.end()) { |
| 221 scope_to_set->SetValue(override->first, override->second, | 222 scope_to_set->SetValue(override->first, override->second, |
| 222 override->second.origin()); | 223 override->second.origin()); |
| 223 scope_to_set->MarkUsed(override->first); | 224 scope_to_set->MarkUsed(override->first, err); |
| 224 continue; | 225 continue; |
| 225 } | 226 } |
| 226 | 227 |
| 227 scope_to_set->SetValue(arg.first, arg.second, arg.second.origin()); | 228 scope_to_set->SetValue(arg.first, arg.second, arg.second.origin()); |
| 228 scope_to_set->MarkUsed(arg.first); | 229 scope_to_set->MarkUsed(arg.first, err); |
| 229 } | 230 } |
| 230 | 231 |
| 231 return true; | 232 return true; |
| 232 } | 233 } |
| 233 | 234 |
| 234 bool Args::VerifyAllOverridesUsed(Err* err) const { | 235 bool Args::VerifyAllOverridesUsed(Err* err) const { |
| 235 base::AutoLock lock(lock_); | 236 base::AutoLock lock(lock_); |
| 236 Scope::KeyValueMap unused_overrides(all_overrides_); | 237 Scope::KeyValueMap unused_overrides(all_overrides_); |
| 237 for (const auto& map_pair : declared_arguments_per_toolchain_) | 238 for (const auto& map_pair : declared_arguments_per_toolchain_) |
| 238 RemoveDeclaredOverrides(map_pair.second, &unused_overrides); | 239 RemoveDeclaredOverrides(map_pair.second, &unused_overrides); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 DeclaredArgumentsForToolchainLocked(dest)); | 363 DeclaredArgumentsForToolchainLocked(dest)); |
| 363 declared_arguments[variables::kHostOs] = os_val; | 364 declared_arguments[variables::kHostOs] = os_val; |
| 364 declared_arguments[variables::kCurrentOs] = empty_string; | 365 declared_arguments[variables::kCurrentOs] = empty_string; |
| 365 declared_arguments[variables::kTargetOs] = empty_string; | 366 declared_arguments[variables::kTargetOs] = empty_string; |
| 366 declared_arguments[variables::kHostCpu] = arch_val; | 367 declared_arguments[variables::kHostCpu] = arch_val; |
| 367 declared_arguments[variables::kCurrentCpu] = empty_string; | 368 declared_arguments[variables::kCurrentCpu] = empty_string; |
| 368 declared_arguments[variables::kTargetCpu] = empty_string; | 369 declared_arguments[variables::kTargetCpu] = empty_string; |
| 369 | 370 |
| 370 // Mark these variables used so the build config file can override them | 371 // Mark these variables used so the build config file can override them |
| 371 // without geting a warning about overwriting an unused variable. | 372 // without geting a warning about overwriting an unused variable. |
| 372 dest->MarkUsed(variables::kHostCpu); | 373 Err err; |
| 373 dest->MarkUsed(variables::kCurrentCpu); | 374 dest->MarkUsed(variables::kHostCpu, &err); |
| 374 dest->MarkUsed(variables::kTargetCpu); | 375 dest->MarkUsed(variables::kCurrentCpu, &err); |
| 375 dest->MarkUsed(variables::kHostOs); | 376 dest->MarkUsed(variables::kTargetCpu, &err); |
| 376 dest->MarkUsed(variables::kCurrentOs); | 377 dest->MarkUsed(variables::kHostOs, &err); |
| 377 dest->MarkUsed(variables::kTargetOs); | 378 dest->MarkUsed(variables::kCurrentOs, &err); |
| 379 dest->MarkUsed(variables::kTargetOs, &err); |
| 380 if (err.has_error()) |
| 381 g_scheduler->FailWithError(err); |
| 378 } | 382 } |
| 379 | 383 |
| 380 void Args::ApplyOverridesLocked(const Scope::KeyValueMap& values, | 384 void Args::ApplyOverridesLocked(const Scope::KeyValueMap& values, |
| 381 Scope* scope) const { | 385 Scope* scope) const { |
| 382 lock_.AssertAcquired(); | 386 lock_.AssertAcquired(); |
| 383 | 387 |
| 384 const Scope::KeyValueMap& declared_arguments( | 388 const Scope::KeyValueMap& declared_arguments( |
| 385 DeclaredArgumentsForToolchainLocked(scope)); | 389 DeclaredArgumentsForToolchainLocked(scope)); |
| 386 | 390 |
| 387 // Only set a value if it has been declared. | 391 // Only set a value if it has been declared. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 406 Scope* scope) const { | 410 Scope* scope) const { |
| 407 lock_.AssertAcquired(); | 411 lock_.AssertAcquired(); |
| 408 return declared_arguments_per_toolchain_[scope->settings()]; | 412 return declared_arguments_per_toolchain_[scope->settings()]; |
| 409 } | 413 } |
| 410 | 414 |
| 411 Scope::KeyValueMap& Args::OverridesForToolchainLocked( | 415 Scope::KeyValueMap& Args::OverridesForToolchainLocked( |
| 412 Scope* scope) const { | 416 Scope* scope) const { |
| 413 lock_.AssertAcquired(); | 417 lock_.AssertAcquired(); |
| 414 return toolchain_overrides_[scope->settings()]; | 418 return toolchain_overrides_[scope->settings()]; |
| 415 } | 419 } |
| OLD | NEW |