| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 base::FilePath up_one_dir = with_no_slash.DirName(); | 135 base::FilePath up_one_dir = with_no_slash.DirName(); |
| 136 if (up_one_dir == current_dir) | 136 if (up_one_dir == current_dir) |
| 137 return base::FilePath(); // Got to the top. | 137 return base::FilePath(); // Got to the top. |
| 138 | 138 |
| 139 return FindDotFile(up_one_dir); | 139 return FindDotFile(up_one_dir); |
| 140 } | 140 } |
| 141 | 141 |
| 142 // Called on any thread. Post the item to the builder on the main thread. | 142 // Called on any thread. Post the item to the builder on the main thread. |
| 143 void ItemDefinedCallback( | 143 void ItemDefinedCallback( |
| 144 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 144 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 145 scoped_refptr<Builder> builder, | 145 Builder* builder_call_on_main_thread_only, |
| 146 std::unique_ptr<Item> item) { | 146 std::unique_ptr<Item> item) { |
| 147 DCHECK(item); | 147 DCHECK(item); |
| 148 task_runner->PostTask(FROM_HERE, base::Bind(&Builder::ItemDefined, builder, | 148 task_runner->PostTask( |
| 149 base::Passed(&item))); | 149 FROM_HERE, |
| 150 base::Bind(&Builder::ItemDefined, |
| 151 base::Unretained(builder_call_on_main_thread_only), |
| 152 base::Passed(&item))); |
| 150 } | 153 } |
| 151 | 154 |
| 152 void DecrementWorkCount() { | 155 void DecrementWorkCount() { |
| 153 g_scheduler->DecrementWorkCount(); | 156 g_scheduler->DecrementWorkCount(); |
| 154 } | 157 } |
| 155 | 158 |
| 156 #if defined(OS_WIN) | 159 #if defined(OS_WIN) |
| 157 | 160 |
| 158 // Given the path to a batch file that runs Python, extracts the name of the | 161 // Given the path to a batch file that runs Python, extracts the name of the |
| 159 // executable actually implementing Python. Generally people write a batch file | 162 // executable actually implementing Python. Generally people write a batch file |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 return true; | 247 return true; |
| 245 } | 248 } |
| 246 | 249 |
| 247 } // namespace | 250 } // namespace |
| 248 | 251 |
| 249 const char Setup::kBuildArgFileName[] = "args.gn"; | 252 const char Setup::kBuildArgFileName[] = "args.gn"; |
| 250 | 253 |
| 251 Setup::Setup() | 254 Setup::Setup() |
| 252 : build_settings_(), | 255 : build_settings_(), |
| 253 loader_(new LoaderImpl(&build_settings_)), | 256 loader_(new LoaderImpl(&build_settings_)), |
| 254 builder_(new Builder(loader_.get())), | 257 builder_(loader_.get()), |
| 255 root_build_file_("//BUILD.gn"), | 258 root_build_file_("//BUILD.gn"), |
| 256 check_public_headers_(false), | 259 check_public_headers_(false), |
| 257 dotfile_settings_(&build_settings_, std::string()), | 260 dotfile_settings_(&build_settings_, std::string()), |
| 258 dotfile_scope_(&dotfile_settings_), | 261 dotfile_scope_(&dotfile_settings_), |
| 259 fill_arguments_(true) { | 262 fill_arguments_(true) { |
| 260 dotfile_settings_.set_toolchain_label(Label()); | 263 dotfile_settings_.set_toolchain_label(Label()); |
| 261 build_settings_.set_item_defined_callback( | 264 build_settings_.set_item_defined_callback( |
| 262 base::Bind(&ItemDefinedCallback, scheduler_.task_runner(), builder_)); | 265 base::Bind(&ItemDefinedCallback, scheduler_.task_runner(), &builder_)); |
| 263 | 266 |
| 264 loader_->set_complete_callback(base::Bind(&DecrementWorkCount)); | 267 loader_->set_complete_callback(base::Bind(&DecrementWorkCount)); |
| 265 // The scheduler's task runner wasn't created when the Loader was created, so | 268 // The scheduler's task runner wasn't created when the Loader was created, so |
| 266 // we need to set it now. | 269 // we need to set it now. |
| 267 loader_->set_task_runner(scheduler_.task_runner()); | 270 loader_->set_task_runner(scheduler_.task_runner()); |
| 268 } | 271 } |
| 269 | 272 |
| 270 Setup::~Setup() { | 273 Setup::~Setup() { |
| 271 } | 274 } |
| 272 | 275 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 // Load the root build file. | 325 // Load the root build file. |
| 323 loader_->Load(root_build_file_, LocationRange(), Label()); | 326 loader_->Load(root_build_file_, LocationRange(), Label()); |
| 324 | 327 |
| 325 // Will be decremented with the loader is drained. | 328 // Will be decremented with the loader is drained. |
| 326 g_scheduler->IncrementWorkCount(); | 329 g_scheduler->IncrementWorkCount(); |
| 327 } | 330 } |
| 328 | 331 |
| 329 bool Setup::RunPostMessageLoop() { | 332 bool Setup::RunPostMessageLoop() { |
| 330 Err err; | 333 Err err; |
| 331 if (build_settings_.check_for_bad_items()) { | 334 if (build_settings_.check_for_bad_items()) { |
| 332 if (!builder_->CheckForBadItems(&err)) { | 335 if (!builder_.CheckForBadItems(&err)) { |
| 333 err.PrintToStdout(); | 336 err.PrintToStdout(); |
| 334 return false; | 337 return false; |
| 335 } | 338 } |
| 336 | 339 |
| 337 if (!build_settings_.build_args().VerifyAllOverridesUsed(&err)) { | 340 if (!build_settings_.build_args().VerifyAllOverridesUsed(&err)) { |
| 338 // TODO(brettw) implement a system to have a different marker for | 341 // TODO(brettw) implement a system to have a different marker for |
| 339 // warnings. Until we have a better system, print the error but don't | 342 // warnings. Until we have a better system, print the error but don't |
| 340 // return failure unless requested on the command line. | 343 // return failure unless requested on the command line. |
| 341 err.PrintToStdout(); | 344 err.PrintToStdout(); |
| 342 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 345 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 343 switches::kFailOnUnusedArgs)) | 346 switches::kFailOnUnusedArgs)) |
| 344 return false; | 347 return false; |
| 345 return true; | 348 return true; |
| 346 } | 349 } |
| 347 } | 350 } |
| 348 | 351 |
| 349 if (check_public_headers_) { | 352 if (check_public_headers_) { |
| 350 std::vector<const Target*> all_targets = builder_->GetAllResolvedTargets(); | 353 std::vector<const Target*> all_targets = builder_.GetAllResolvedTargets(); |
| 351 std::vector<const Target*> to_check; | 354 std::vector<const Target*> to_check; |
| 352 if (check_patterns()) { | 355 if (check_patterns()) { |
| 353 commands::FilterTargetsByPatterns(all_targets, *check_patterns(), | 356 commands::FilterTargetsByPatterns(all_targets, *check_patterns(), |
| 354 &to_check); | 357 &to_check); |
| 355 } else { | 358 } else { |
| 356 to_check = all_targets; | 359 to_check = all_targets; |
| 357 } | 360 } |
| 358 | 361 |
| 359 if (!commands::CheckPublicHeaders(&build_settings_, all_targets, | 362 if (!commands::CheckPublicHeaders(&build_settings_, all_targets, |
| 360 to_check, false)) { | 363 to_check, false)) { |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 if (err.has_error()) { | 737 if (err.has_error()) { |
| 735 err.PrintToStdout(); | 738 err.PrintToStdout(); |
| 736 return false; | 739 return false; |
| 737 } | 740 } |
| 738 } | 741 } |
| 739 build_settings_.set_exec_script_whitelist(std::move(whitelist)); | 742 build_settings_.set_exec_script_whitelist(std::move(whitelist)); |
| 740 } | 743 } |
| 741 | 744 |
| 742 return true; | 745 return true; |
| 743 } | 746 } |
| OLD | NEW |