| 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/setup.h" | 5 #include "tools/gn/setup.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 for a BUILD.gn file (or the build config file discussed above), the file | 99 for a BUILD.gn file (or the build config file discussed above), the file |
| 100 will first be looked for in the source root. If it's not found, the | 100 will first be looked for in the source root. If it's not found, the |
| 101 secondary source root will be checked (which would contain a parallel | 101 secondary source root will be checked (which would contain a parallel |
| 102 directory hierarchy). | 102 directory hierarchy). |
| 103 | 103 |
| 104 This behavior is intended to be used when BUILD.gn files can't be checked | 104 This behavior is intended to be used when BUILD.gn files can't be checked |
| 105 in to certain source directories for whatever reason. | 105 in to certain source directories for whatever reason. |
| 106 | 106 |
| 107 The secondary source root must be inside the main source tree. | 107 The secondary source root must be inside the main source tree. |
| 108 | 108 |
| 109 default_args [optional] |
| 110 Scope containing the default overrides for declared arguments. These |
| 111 overrides take precedence over the default values specified in the |
| 112 declare_args() block, but can be overriden using --args or the |
| 113 args.gn file. |
| 114 |
| 115 This is intended to be used when subprojects declare arguments with |
| 116 default values that need to be changed for whatever reason. |
| 117 |
| 109 Example .gn file contents | 118 Example .gn file contents |
| 110 | 119 |
| 111 buildconfig = "//build/config/BUILDCONFIG.gn" | 120 buildconfig = "//build/config/BUILDCONFIG.gn" |
| 112 | 121 |
| 113 check_targets = [ | 122 check_targets = [ |
| 114 "//doom_melon/*", # Check everything in this subtree. | 123 "//doom_melon/*", # Check everything in this subtree. |
| 115 "//tools:mind_controlling_ant", # Check this specific target. | 124 "//tools:mind_controlling_ant", # Check this specific target. |
| 116 ] | 125 ] |
| 117 | 126 |
| 118 root = "//:root" | 127 root = "//:root" |
| 119 | 128 |
| 120 secondary_source = "//build/config/temporary_buildfiles/" | 129 secondary_source = "//build/config/temporary_buildfiles/" |
| 130 |
| 131 default_args = { |
| 132 # Default to release builds for this project. |
| 133 is_debug = false |
| 134 is_component_build = false |
| 135 } |
| 121 )"; | 136 )"; |
| 122 | 137 |
| 123 namespace { | 138 namespace { |
| 124 | 139 |
| 125 const base::FilePath::CharType kGnFile[] = FILE_PATH_LITERAL(".gn"); | 140 const base::FilePath::CharType kGnFile[] = FILE_PATH_LITERAL(".gn"); |
| 126 | 141 |
| 127 base::FilePath FindDotFile(const base::FilePath& current_dir) { | 142 base::FilePath FindDotFile(const base::FilePath& current_dir) { |
| 128 base::FilePath try_this_file = current_dir.Append(kGnFile); | 143 base::FilePath try_this_file = current_dir.Append(kGnFile); |
| 129 if (base::PathExists(try_this_file)) | 144 if (base::PathExists(try_this_file)) |
| 130 return try_this_file; | 145 return try_this_file; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 const char Setup::kBuildArgFileName[] = "args.gn"; | 265 const char Setup::kBuildArgFileName[] = "args.gn"; |
| 251 | 266 |
| 252 Setup::Setup() | 267 Setup::Setup() |
| 253 : build_settings_(), | 268 : build_settings_(), |
| 254 loader_(new LoaderImpl(&build_settings_)), | 269 loader_(new LoaderImpl(&build_settings_)), |
| 255 builder_(loader_.get()), | 270 builder_(loader_.get()), |
| 256 root_build_file_("//BUILD.gn"), | 271 root_build_file_("//BUILD.gn"), |
| 257 check_public_headers_(false), | 272 check_public_headers_(false), |
| 258 dotfile_settings_(&build_settings_, std::string()), | 273 dotfile_settings_(&build_settings_, std::string()), |
| 259 dotfile_scope_(&dotfile_settings_), | 274 dotfile_scope_(&dotfile_settings_), |
| 275 default_args_(nullptr), |
| 260 fill_arguments_(true) { | 276 fill_arguments_(true) { |
| 261 dotfile_settings_.set_toolchain_label(Label()); | 277 dotfile_settings_.set_toolchain_label(Label()); |
| 262 | 278 |
| 263 build_settings_.set_item_defined_callback( | 279 build_settings_.set_item_defined_callback( |
| 264 base::Bind(&ItemDefinedCallback, scheduler_.task_runner(), &builder_)); | 280 base::Bind(&ItemDefinedCallback, scheduler_.task_runner(), &builder_)); |
| 265 | 281 |
| 266 loader_->set_complete_callback(base::Bind(&DecrementWorkCount)); | 282 loader_->set_complete_callback(base::Bind(&DecrementWorkCount)); |
| 267 // The scheduler's task runner wasn't created when the Loader was created, so | 283 // The scheduler's task runner wasn't created when the Loader was created, so |
| 268 // we need to set it now. | 284 // we need to set it now. |
| 269 loader_->set_task_runner(scheduler_.task_runner()); | 285 loader_->set_task_runner(scheduler_.task_runner()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 293 if (!FillBuildDir(build_dir, !force_create)) | 309 if (!FillBuildDir(build_dir, !force_create)) |
| 294 return false; | 310 return false; |
| 295 | 311 |
| 296 // Check for unused variables in the .gn file. | 312 // Check for unused variables in the .gn file. |
| 297 Err err; | 313 Err err; |
| 298 if (!dotfile_scope_.CheckForUnusedVars(&err)) { | 314 if (!dotfile_scope_.CheckForUnusedVars(&err)) { |
| 299 err.PrintToStdout(); | 315 err.PrintToStdout(); |
| 300 return false; | 316 return false; |
| 301 } | 317 } |
| 302 | 318 |
| 319 // Apply project-specific default (if specified). |
| 320 // Must happen before FillArguments(). |
| 321 if (default_args_) { |
| 322 Scope::KeyValueMap overrides; |
| 323 default_args_->GetCurrentScopeValues(&overrides); |
| 324 build_settings_.build_args().AddArgOverrides(overrides); |
| 325 } |
| 326 |
| 303 if (fill_arguments_) { | 327 if (fill_arguments_) { |
| 304 if (!FillArguments(*cmdline)) | 328 if (!FillArguments(*cmdline)) |
| 305 return false; | 329 return false; |
| 306 } | 330 } |
| 307 FillPythonPath(*cmdline); | 331 FillPythonPath(*cmdline); |
| 308 | 332 |
| 309 return true; | 333 return true; |
| 310 } | 334 } |
| 311 | 335 |
| 312 bool Setup::Run() { | 336 bool Setup::Run() { |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 } | 755 } |
| 732 whitelist->insert(current_dir.ResolveRelativeFile(item, &err)); | 756 whitelist->insert(current_dir.ResolveRelativeFile(item, &err)); |
| 733 if (err.has_error()) { | 757 if (err.has_error()) { |
| 734 err.PrintToStdout(); | 758 err.PrintToStdout(); |
| 735 return false; | 759 return false; |
| 736 } | 760 } |
| 737 } | 761 } |
| 738 build_settings_.set_exec_script_whitelist(std::move(whitelist)); | 762 build_settings_.set_exec_script_whitelist(std::move(whitelist)); |
| 739 } | 763 } |
| 740 | 764 |
| 765 // Fill optional default_args. |
| 766 const Value* default_args_value = |
| 767 dotfile_scope_.GetValue("default_args", true); |
| 768 if (default_args_value) { |
| 769 if (!default_args_value->VerifyTypeIs(Value::SCOPE, &err)) { |
| 770 err.PrintToStdout(); |
| 771 return false; |
| 772 } |
| 773 |
| 774 default_args_ = default_args_value->scope_value(); |
| 775 } |
| 776 |
| 741 return true; | 777 return true; |
| 742 } | 778 } |
| OLD | NEW |