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

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

Issue 914873002: Rework handling of os and cpu_arch in GN. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update w/ review comments Created 5 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
« no previous file with comments | « no previous file | 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 "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
11 const char kBuildArgs_Help[] = 11 const char kBuildArgs_Help[] =
12 "Build Arguments Overview\n" 12 "Build Arguments Overview\n"
13 "\n" 13 "\n"
14 " Build arguments are variables passed in from outside of the build\n" 14 " Build arguments are variables passed in from outside of the build\n"
15 " that build files can query to determine how the build works.\n" 15 " that build files can query to determine how the build works.\n"
16 "\n" 16 "\n"
17 "How build arguments are set\n" 17 "How build arguments are set\n"
18 "\n" 18 "\n"
19 " First, system default arguments are set based on the current system.\n" 19 " First, system default arguments are set based on the current system.\n"
20 " The built-in arguments are:\n" 20 " The built-in arguments are:\n"
21 " - cpu_arch (by default this is the same as \"default_cpu_arch\")\n" 21 " - host_cpu\n"
22 " - default_cpu_arch\n" 22 " - host_os\n"
23 " - default_os\n" 23 " - current_cpu\n"
24 " - os (by default this is the same as \"default_os\")\n" 24 " - current_os\n"
25 " - target_cpu\n"
26 " - target_os\n"
25 "\n" 27 "\n"
26 " If specified, arguments from the --args command line flag are used. If\n" 28 " If specified, arguments from the --args command line flag are used. If\n"
27 " that flag is not specified, args from previous builds in the build\n" 29 " that flag is not specified, args from previous builds in the build\n"
28 " directory will be used (this is in the file args.gn in the build\n" 30 " directory will be used (this is in the file args.gn in the build\n"
29 " directory).\n" 31 " directory).\n"
30 "\n" 32 "\n"
31 " Last, for targets being compiled with a non-default toolchain, the\n" 33 " Last, for targets being compiled with a non-default toolchain, the\n"
32 " toolchain overrides are applied. These are specified in the\n" 34 " toolchain overrides are applied. These are specified in the\n"
33 " toolchain_args section of a toolchain definition. The use-case for\n" 35 " toolchain_args section of a toolchain definition. The use-case for\n"
34 " this is that a toolchain may be building code for a different\n" 36 " this is that a toolchain may be building code for a different\n"
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 os = "win"; 216 os = "win";
215 #elif defined(OS_MACOSX) 217 #elif defined(OS_MACOSX)
216 os = "mac"; 218 os = "mac";
217 #elif defined(OS_LINUX) 219 #elif defined(OS_LINUX)
218 os = "linux"; 220 os = "linux";
219 #elif defined(OS_ANDROID) 221 #elif defined(OS_ANDROID)
220 os = "android"; 222 os = "android";
221 #else 223 #else
222 #error Unknown OS type. 224 #error Unknown OS type.
223 #endif 225 #endif
224 Value os_val(nullptr, std::string(os));
225 dest->SetValue(variables::kBuildOs, os_val, nullptr);
226 dest->SetValue(variables::kOs, os_val, nullptr);
227 226
228 // Host architecture. 227 // Host architecture.
229 static const char kX86[] = "x86"; 228 static const char kX86[] = "x86";
230 static const char kX64[] = "x64"; 229 static const char kX64[] = "x64";
231 static const char kArm[] = "arm"; 230 static const char kArm[] = "arm";
232 const char* arch = nullptr; 231 const char* arch = nullptr;
233 232
234 // Set the CPU architecture based on the underlying OS, not 233 // Set the host CPU architecture based on the underlying OS, not
235 // whatever the current bit-tedness of the GN binary is. 234 // whatever the current bit-tedness of the GN binary is.
236 std::string os_arch = base::SysInfo::OperatingSystemArchitecture(); 235 std::string os_arch = base::SysInfo::OperatingSystemArchitecture();
237 if (os_arch == "x86") 236 if (os_arch == "x86")
238 arch = kX86; 237 arch = kX86;
239 else if (os_arch == "x86_64") 238 else if (os_arch == "x86_64")
240 arch = kX64; 239 arch = kX64;
241 else if (os_arch.substr(3) == "arm") 240 else if (os_arch.substr(3) == "arm")
242 arch = kArm; 241 arch = kArm;
243 else 242 else
244 CHECK(false) << "OS architecture not handled."; 243 CHECK(false) << "OS architecture not handled.";
245 244
246 Value arch_val(nullptr, std::string(arch));
247 dest->SetValue(variables::kBuildCpuArch, arch_val, nullptr);
248 dest->SetValue(variables::kCpuArch, arch_val, nullptr);
249
250 // Save the OS and architecture as build arguments that are implicitly 245 // Save the OS and architecture as build arguments that are implicitly
251 // declared. This is so they can be overridden in a toolchain build args 246 // declared. This is so they can be overridden in a toolchain build args
252 // override, and so that they will appear in the "gn args" output. 247 // override, and so that they will appear in the "gn args" output.
253 // 248 Value empty_string(nullptr, std::string());
254 // Do not declare the build* variants since these shouldn't be changed. 249
255 // 250 Value os_val(nullptr, std::string(os));
251 dest->SetValue(variables::kHostOs, os_val, nullptr);
252 dest->SetValue(variables::kTargetOs, empty_string, nullptr);
253 dest->SetValue(variables::kCurrentOs, empty_string, nullptr);
254
255 Value arch_val(nullptr, std::string(arch));
256 dest->SetValue(variables::kHostCpu, arch_val, nullptr);
257 dest->SetValue(variables::kTargetCpu, empty_string, nullptr);
258 dest->SetValue(variables::kCurrentCpu, empty_string, nullptr);
259
260 declared_arguments_[variables::kHostOs] = os_val;
261 declared_arguments_[variables::kCurrentOs] = empty_string;
262 declared_arguments_[variables::kTargetOs] = empty_string;
263 declared_arguments_[variables::kHostCpu] = arch_val;
264 declared_arguments_[variables::kCurrentCpu] = empty_string;
265 declared_arguments_[variables::kTargetCpu] = empty_string;
266
256 // Mark these variables used so the build config file can override them 267 // Mark these variables used so the build config file can override them
257 // without geting a warning about overwriting an unused variable. 268 // without geting a warning about overwriting an unused variable.
258 declared_arguments_[variables::kOs] = os_val; 269 dest->MarkUsed(variables::kHostCpu);
259 declared_arguments_[variables::kCpuArch] = arch_val; 270 dest->MarkUsed(variables::kCurrentCpu);
260 dest->MarkUsed(variables::kCpuArch); 271 dest->MarkUsed(variables::kTargetCpu);
261 dest->MarkUsed(variables::kOs); 272 dest->MarkUsed(variables::kHostOs);
273 dest->MarkUsed(variables::kCurrentOs);
274 dest->MarkUsed(variables::kTargetOs);
262 } 275 }
263 276
264 void Args::ApplyOverridesLocked(const Scope::KeyValueMap& values, 277 void Args::ApplyOverridesLocked(const Scope::KeyValueMap& values,
265 Scope* scope) const { 278 Scope* scope) const {
266 lock_.AssertAcquired(); 279 lock_.AssertAcquired();
267 for (const auto& val : values) 280 for (const auto& val : values)
268 scope->SetValue(val.first, val.second, val.second.origin()); 281 scope->SetValue(val.first, val.second, val.second.origin());
269 } 282 }
270 283
271 void Args::SaveOverrideRecordLocked(const Scope::KeyValueMap& values) const { 284 void Args::SaveOverrideRecordLocked(const Scope::KeyValueMap& values) const {
272 lock_.AssertAcquired(); 285 lock_.AssertAcquired();
273 for (const auto& val : values) 286 for (const auto& val : values)
274 all_overrides_[val.first] = val.second; 287 all_overrides_[val.first] = val.second;
275 } 288 }
OLDNEW
« no previous file with comments | « no previous file | tools/gn/command_args.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698