| 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 "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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 " listed in the \"How build arguments are set\" section above apply to\n" | 48 " listed in the \"How build arguments are set\" section above apply to\n" |
| 49 " the given argument, but the defaults will not override any of these.\n" | 49 " the given argument, but the defaults will not override any of these.\n" |
| 50 "\n" | 50 "\n" |
| 51 " Often, the root build config file will declare global arguments that\n" | 51 " Often, the root build config file will declare global arguments that\n" |
| 52 " will be passed to all buildfiles. Individual build files can also\n" | 52 " will be passed to all buildfiles. Individual build files can also\n" |
| 53 " specify arguments that apply only to those files. It is also usedful\n" | 53 " specify arguments that apply only to those files. It is also usedful\n" |
| 54 " to specify build args in an \"import\"-ed file if you want such\n" | 54 " to specify build args in an \"import\"-ed file if you want such\n" |
| 55 " arguments to apply to multiple buildfiles.\n"; | 55 " arguments to apply to multiple buildfiles.\n"; |
| 56 | 56 |
| 57 Args::Args() { | 57 Args::Args() { |
| 58 // These system values are always overridden and won't appear in a | |
| 59 // declare_args call, so mark them as used to prevent a warning later. | |
| 60 declared_arguments_[variables::kOs] = Value(); | |
| 61 declared_arguments_[variables::kCpuArch] = Value(); | |
| 62 } | 58 } |
| 63 | 59 |
| 64 Args::Args(const Args& other) | 60 Args::Args(const Args& other) |
| 65 : overrides_(other.overrides_), | 61 : overrides_(other.overrides_), |
| 66 all_overrides_(other.all_overrides_), | 62 all_overrides_(other.all_overrides_), |
| 67 declared_arguments_(other.declared_arguments_) { | 63 declared_arguments_(other.declared_arguments_) { |
| 68 } | 64 } |
| 69 | 65 |
| 70 Args::~Args() { | 66 Args::~Args() { |
| 71 } | 67 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 #elif defined(OS_MACOSX) | 167 #elif defined(OS_MACOSX) |
| 172 os = "mac"; | 168 os = "mac"; |
| 173 #elif defined(OS_LINUX) | 169 #elif defined(OS_LINUX) |
| 174 os = "linux"; | 170 os = "linux"; |
| 175 #else | 171 #else |
| 176 #error Unknown OS type. | 172 #error Unknown OS type. |
| 177 #endif | 173 #endif |
| 178 Value os_val(NULL, std::string(os)); | 174 Value os_val(NULL, std::string(os)); |
| 179 dest->SetValue(variables::kBuildOs, os_val, NULL); | 175 dest->SetValue(variables::kBuildOs, os_val, NULL); |
| 180 dest->SetValue(variables::kOs, os_val, NULL); | 176 dest->SetValue(variables::kOs, os_val, NULL); |
| 181 declared_arguments_[variables::kBuildOs] = os_val; | |
| 182 declared_arguments_[variables::kOs] = os_val; | |
| 183 | 177 |
| 184 // Host architecture. | 178 // Host architecture. |
| 185 static const char kIa32[] = "ia32"; | 179 static const char kIa32[] = "ia32"; |
| 186 static const char kIa64[] = "ia64"; | 180 static const char kIa64[] = "ia64"; |
| 187 const char* arch = NULL; | 181 const char* arch = NULL; |
| 188 #if defined(OS_WIN) | 182 #if defined(OS_WIN) |
| 189 // ...on Windows, set the CPU architecture based on the underlying OS, not | 183 // ...on Windows, set the CPU architecture based on the underlying OS, not |
| 190 // whatever the current bit-tedness of the GN binary is. | 184 // whatever the current bit-tedness of the GN binary is. |
| 191 const base::win::OSInfo* os_info = base::win::OSInfo::GetInstance(); | 185 const base::win::OSInfo* os_info = base::win::OSInfo::GetInstance(); |
| 192 switch (os_info->architecture()) { | 186 switch (os_info->architecture()) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 214 #error Unknown architecture. | 208 #error Unknown architecture. |
| 215 #endif | 209 #endif |
| 216 #endif | 210 #endif |
| 217 // Avoid unused var warning. | 211 // Avoid unused var warning. |
| 218 (void)kIa32; | 212 (void)kIa32; |
| 219 (void)kIa64; | 213 (void)kIa64; |
| 220 | 214 |
| 221 Value arch_val(NULL, std::string(arch)); | 215 Value arch_val(NULL, std::string(arch)); |
| 222 dest->SetValue(variables::kBuildCpuArch, arch_val, NULL); | 216 dest->SetValue(variables::kBuildCpuArch, arch_val, NULL); |
| 223 dest->SetValue(variables::kCpuArch, arch_val, NULL); | 217 dest->SetValue(variables::kCpuArch, arch_val, NULL); |
| 224 declared_arguments_[variables::kBuildOs] = arch_val; | |
| 225 declared_arguments_[variables::kOs] = arch_val; | |
| 226 | 218 |
| 219 // Save the OS and architecture as build arguments that are implicitly |
| 220 // declared. This is so they can be overridden in a toolchain build args |
| 221 // override, and so that they will appear in the "gn args" output. |
| 222 // |
| 223 // Do not declare the build* variants since these shouldn't be changed. |
| 224 // |
| 227 // Mark these variables used so the build config file can override them | 225 // Mark these variables used so the build config file can override them |
| 228 // without geting a warning about overwriting an unused variable. | 226 // without geting a warning about overwriting an unused variable. |
| 227 declared_arguments_[variables::kOs] = os_val; |
| 228 declared_arguments_[variables::kCpuArch] = arch_val; |
| 229 dest->MarkUsed(variables::kCpuArch); | 229 dest->MarkUsed(variables::kCpuArch); |
| 230 dest->MarkUsed(variables::kOs); | 230 dest->MarkUsed(variables::kOs); |
| 231 } | 231 } |
| 232 | 232 |
| 233 | 233 |
| 234 void Args::ApplyOverrides(const Scope::KeyValueMap& values, | 234 void Args::ApplyOverrides(const Scope::KeyValueMap& values, |
| 235 Scope* scope) const { | 235 Scope* scope) const { |
| 236 for (Scope::KeyValueMap::const_iterator i = values.begin(); | 236 for (Scope::KeyValueMap::const_iterator i = values.begin(); |
| 237 i != values.end(); ++i) | 237 i != values.end(); ++i) |
| 238 scope->SetValue(i->first, i->second, i->second.origin()); | 238 scope->SetValue(i->first, i->second, i->second.origin()); |
| 239 } | 239 } |
| 240 | 240 |
| 241 void Args::SaveOverrideRecord(const Scope::KeyValueMap& values) const { | 241 void Args::SaveOverrideRecord(const Scope::KeyValueMap& values) const { |
| 242 base::AutoLock lock(lock_); | 242 base::AutoLock lock(lock_); |
| 243 for (Scope::KeyValueMap::const_iterator i = values.begin(); | 243 for (Scope::KeyValueMap::const_iterator i = values.begin(); |
| 244 i != values.end(); ++i) | 244 i != values.end(); ++i) |
| 245 all_overrides_[i->first] = i->second; | 245 all_overrides_[i->first] = i->second; |
| 246 } | 246 } |
| OLD | NEW |