Chromium Code Reviews| 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/loader.h" | 5 #include "tools/gn/loader.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "base/single_thread_task_runner.h" | |
| 11 #include "tools/gn/build_settings.h" | 10 #include "tools/gn/build_settings.h" |
| 12 #include "tools/gn/err.h" | 11 #include "tools/gn/err.h" |
| 13 #include "tools/gn/filesystem_utils.h" | 12 #include "tools/gn/filesystem_utils.h" |
| 14 #include "tools/gn/input_file_manager.h" | 13 #include "tools/gn/input_file_manager.h" |
| 15 #include "tools/gn/parse_tree.h" | 14 #include "tools/gn/parse_tree.h" |
| 16 #include "tools/gn/scheduler.h" | 15 #include "tools/gn/scheduler.h" |
| 17 #include "tools/gn/scope_per_file_provider.h" | 16 #include "tools/gn/scope_per_file_provider.h" |
| 18 #include "tools/gn/settings.h" | 17 #include "tools/gn/settings.h" |
| 19 #include "tools/gn/source_dir.h" | 18 #include "tools/gn/source_dir.h" |
| 20 #include "tools/gn/source_file.h" | 19 #include "tools/gn/source_file.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 } | 92 } |
| 94 | 93 |
| 95 // static | 94 // static |
| 96 SourceFile Loader::BuildFileForLabel(const Label& label) { | 95 SourceFile Loader::BuildFileForLabel(const Label& label) { |
| 97 return SourceFile(label.dir().value() + "BUILD.gn"); | 96 return SourceFile(label.dir().value() + "BUILD.gn"); |
| 98 } | 97 } |
| 99 | 98 |
| 100 // ----------------------------------------------------------------------------- | 99 // ----------------------------------------------------------------------------- |
| 101 | 100 |
| 102 LoaderImpl::LoaderImpl(const BuildSettings* build_settings) | 101 LoaderImpl::LoaderImpl(const BuildSettings* build_settings) |
| 103 : main_loop_(base::MessageLoop::current()), | 102 : pending_loads_(0), build_settings_(build_settings) { |
| 104 pending_loads_(0), | 103 if (base::ThreadTaskRunnerHandle::IsSet()) |
|
brettw
2016/07/11 20:47:25
Can you add a comment here that there may be no ac
fdoray
2016/07/18 15:28:40
Done.
| |
| 105 build_settings_(build_settings) { | 104 task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 106 } | 105 } |
| 107 | 106 |
| 108 LoaderImpl::~LoaderImpl() { | 107 LoaderImpl::~LoaderImpl() { |
| 109 } | 108 } |
| 110 | 109 |
| 111 void LoaderImpl::Load(const SourceFile& file, | 110 void LoaderImpl::Load(const SourceFile& file, |
| 112 const LocationRange& origin, | 111 const LocationRange& origin, |
| 113 const Label& in_toolchain_name) { | 112 const Label& in_toolchain_name) { |
| 114 const Label& toolchain_name = in_toolchain_name.is_null() | 113 const Label& toolchain_name = in_toolchain_name.is_null() |
| 115 ? default_toolchain_label_ : in_toolchain_name; | 114 ? default_toolchain_label_ : in_toolchain_name; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 g_scheduler->FailWithError(err); | 231 g_scheduler->FailWithError(err); |
| 233 DecrementPendingLoads(); | 232 DecrementPendingLoads(); |
| 234 } | 233 } |
| 235 } | 234 } |
| 236 | 235 |
| 237 void LoaderImpl::BackgroundLoadFile(const Settings* settings, | 236 void LoaderImpl::BackgroundLoadFile(const Settings* settings, |
| 238 const SourceFile& file_name, | 237 const SourceFile& file_name, |
| 239 const LocationRange& origin, | 238 const LocationRange& origin, |
| 240 const ParseNode* root) { | 239 const ParseNode* root) { |
| 241 if (!root) { | 240 if (!root) { |
| 242 main_loop_->task_runner()->PostTask( | 241 task_runner_->PostTask( |
| 243 FROM_HERE, base::Bind(&LoaderImpl::DecrementPendingLoads, this)); | 242 FROM_HERE, base::Bind(&LoaderImpl::DecrementPendingLoads, this)); |
| 244 return; | 243 return; |
| 245 } | 244 } |
| 246 | 245 |
| 247 if (g_scheduler->verbose_logging()) { | 246 if (g_scheduler->verbose_logging()) { |
| 248 g_scheduler->Log("Running", file_name.value() + " with toolchain " + | 247 g_scheduler->Log("Running", file_name.value() + " with toolchain " + |
| 249 settings->toolchain_label().GetUserVisibleName(false)); | 248 settings->toolchain_label().GetUserVisibleName(false)); |
| 250 } | 249 } |
| 251 | 250 |
| 252 Scope our_scope(settings->base_config()); | 251 Scope our_scope(settings->base_config()); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 273 | 272 |
| 274 | 273 |
| 275 // Pass all of the items that were defined off to the builder. | 274 // Pass all of the items that were defined off to the builder. |
| 276 for (auto& item : collected_items) { | 275 for (auto& item : collected_items) { |
| 277 settings->build_settings()->ItemDefined(base::WrapUnique(item)); | 276 settings->build_settings()->ItemDefined(base::WrapUnique(item)); |
| 278 item = nullptr; | 277 item = nullptr; |
| 279 } | 278 } |
| 280 | 279 |
| 281 trace.Done(); | 280 trace.Done(); |
| 282 | 281 |
| 283 main_loop_->task_runner()->PostTask( | 282 task_runner_->PostTask(FROM_HERE, base::Bind(&LoaderImpl::DidLoadFile, this)); |
| 284 FROM_HERE, base::Bind(&LoaderImpl::DidLoadFile, this)); | |
| 285 } | 283 } |
| 286 | 284 |
| 287 void LoaderImpl::BackgroundLoadBuildConfig( | 285 void LoaderImpl::BackgroundLoadBuildConfig( |
| 288 Settings* settings, | 286 Settings* settings, |
| 289 const Scope::KeyValueMap& toolchain_overrides, | 287 const Scope::KeyValueMap& toolchain_overrides, |
| 290 const ParseNode* root) { | 288 const ParseNode* root) { |
| 291 if (!root) { | 289 if (!root) { |
| 292 main_loop_->task_runner()->PostTask( | 290 task_runner_->PostTask( |
| 293 FROM_HERE, base::Bind(&LoaderImpl::DecrementPendingLoads, this)); | 291 FROM_HERE, base::Bind(&LoaderImpl::DecrementPendingLoads, this)); |
| 294 return; | 292 return; |
| 295 } | 293 } |
| 296 | 294 |
| 297 Scope* base_config = settings->base_config(); | 295 Scope* base_config = settings->base_config(); |
| 298 base_config->set_source_dir(SourceDir("//")); | 296 base_config->set_source_dir(SourceDir("//")); |
| 299 | 297 |
| 300 settings->build_settings()->build_args().SetupRootScope( | 298 settings->build_settings()->build_args().SetupRootScope( |
| 301 base_config, toolchain_overrides); | 299 base_config, toolchain_overrides); |
| 302 | 300 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 332 g_scheduler->FailWithError(Err(Location(), | 330 g_scheduler->FailWithError(Err(Location(), |
| 333 "The default build config file did not call set_default_toolchain()", | 331 "The default build config file did not call set_default_toolchain()", |
| 334 "If you don't call this, I can't figure out what toolchain to use\n" | 332 "If you don't call this, I can't figure out what toolchain to use\n" |
| 335 "for all of this code.")); | 333 "for all of this code.")); |
| 336 } else { | 334 } else { |
| 337 DCHECK(settings->toolchain_label().is_null()); | 335 DCHECK(settings->toolchain_label().is_null()); |
| 338 settings->set_toolchain_label(default_toolchain_label); | 336 settings->set_toolchain_label(default_toolchain_label); |
| 339 } | 337 } |
| 340 } | 338 } |
| 341 | 339 |
| 342 main_loop_->task_runner()->PostTask( | 340 task_runner_->PostTask(FROM_HERE, |
| 343 FROM_HERE, base::Bind(&LoaderImpl::DidLoadBuildConfig, this, | 341 base::Bind(&LoaderImpl::DidLoadBuildConfig, this, |
| 344 settings->toolchain_label())); | 342 settings->toolchain_label())); |
| 345 } | 343 } |
| 346 | 344 |
| 347 void LoaderImpl::DidLoadFile() { | 345 void LoaderImpl::DidLoadFile() { |
| 348 DecrementPendingLoads(); | 346 DecrementPendingLoads(); |
| 349 } | 347 } |
| 350 | 348 |
| 351 void LoaderImpl::DidLoadBuildConfig(const Label& label) { | 349 void LoaderImpl::DidLoadBuildConfig(const Label& label) { |
| 352 // Do not return early, we must call DecrementPendingLoads() at the bottom. | 350 // Do not return early, we must call DecrementPendingLoads() at the bottom. |
| 353 | 351 |
| 354 ToolchainRecordMap::iterator found_toolchain = toolchain_records_.find(label); | 352 ToolchainRecordMap::iterator found_toolchain = toolchain_records_.find(label); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 421 const SourceFile& file_name, | 419 const SourceFile& file_name, |
| 422 const base::Callback<void(const ParseNode*)>& callback, | 420 const base::Callback<void(const ParseNode*)>& callback, |
| 423 Err* err) { | 421 Err* err) { |
| 424 if (async_load_file_.is_null()) { | 422 if (async_load_file_.is_null()) { |
| 425 return g_scheduler->input_file_manager()->AsyncLoadFile( | 423 return g_scheduler->input_file_manager()->AsyncLoadFile( |
| 426 origin, build_settings, file_name, callback, err); | 424 origin, build_settings, file_name, callback, err); |
| 427 } | 425 } |
| 428 return async_load_file_.Run( | 426 return async_load_file_.Run( |
| 429 origin, build_settings, file_name, callback, err); | 427 origin, build_settings, file_name, callback, err); |
| 430 } | 428 } |
| OLD | NEW |