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

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

Issue 2130443002: Remove calls to MessageLoop::current() in tools. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR brettw (add comment) Created 4 years, 5 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 | « tools/gn/loader.h ('k') | tools/gn/loader_unittest.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/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
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 // There may not be an active TaskRunner at this point. When that's the case,
105 build_settings_(build_settings) { 104 // the calling code is expected to call set_task_runner().
105 if (base::ThreadTaskRunnerHandle::IsSet())
106 task_runner_ = base::ThreadTaskRunnerHandle::Get();
106 } 107 }
107 108
108 LoaderImpl::~LoaderImpl() { 109 LoaderImpl::~LoaderImpl() {
109 } 110 }
110 111
111 void LoaderImpl::Load(const SourceFile& file, 112 void LoaderImpl::Load(const SourceFile& file,
112 const LocationRange& origin, 113 const LocationRange& origin,
113 const Label& in_toolchain_name) { 114 const Label& in_toolchain_name) {
114 const Label& toolchain_name = in_toolchain_name.is_null() 115 const Label& toolchain_name = in_toolchain_name.is_null()
115 ? default_toolchain_label_ : in_toolchain_name; 116 ? default_toolchain_label_ : in_toolchain_name;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 g_scheduler->FailWithError(err); 233 g_scheduler->FailWithError(err);
233 DecrementPendingLoads(); 234 DecrementPendingLoads();
234 } 235 }
235 } 236 }
236 237
237 void LoaderImpl::BackgroundLoadFile(const Settings* settings, 238 void LoaderImpl::BackgroundLoadFile(const Settings* settings,
238 const SourceFile& file_name, 239 const SourceFile& file_name,
239 const LocationRange& origin, 240 const LocationRange& origin,
240 const ParseNode* root) { 241 const ParseNode* root) {
241 if (!root) { 242 if (!root) {
242 main_loop_->task_runner()->PostTask( 243 task_runner_->PostTask(
243 FROM_HERE, base::Bind(&LoaderImpl::DecrementPendingLoads, this)); 244 FROM_HERE, base::Bind(&LoaderImpl::DecrementPendingLoads, this));
244 return; 245 return;
245 } 246 }
246 247
247 if (g_scheduler->verbose_logging()) { 248 if (g_scheduler->verbose_logging()) {
248 g_scheduler->Log("Running", file_name.value() + " with toolchain " + 249 g_scheduler->Log("Running", file_name.value() + " with toolchain " +
249 settings->toolchain_label().GetUserVisibleName(false)); 250 settings->toolchain_label().GetUserVisibleName(false));
250 } 251 }
251 252
252 Scope our_scope(settings->base_config()); 253 Scope our_scope(settings->base_config());
(...skipping 20 matching lines...) Expand all
273 274
274 275
275 // Pass all of the items that were defined off to the builder. 276 // Pass all of the items that were defined off to the builder.
276 for (auto& item : collected_items) { 277 for (auto& item : collected_items) {
277 settings->build_settings()->ItemDefined(base::WrapUnique(item)); 278 settings->build_settings()->ItemDefined(base::WrapUnique(item));
278 item = nullptr; 279 item = nullptr;
279 } 280 }
280 281
281 trace.Done(); 282 trace.Done();
282 283
283 main_loop_->task_runner()->PostTask( 284 task_runner_->PostTask(FROM_HERE, base::Bind(&LoaderImpl::DidLoadFile, this));
284 FROM_HERE, base::Bind(&LoaderImpl::DidLoadFile, this));
285 } 285 }
286 286
287 void LoaderImpl::BackgroundLoadBuildConfig( 287 void LoaderImpl::BackgroundLoadBuildConfig(
288 Settings* settings, 288 Settings* settings,
289 const Scope::KeyValueMap& toolchain_overrides, 289 const Scope::KeyValueMap& toolchain_overrides,
290 const ParseNode* root) { 290 const ParseNode* root) {
291 if (!root) { 291 if (!root) {
292 main_loop_->task_runner()->PostTask( 292 task_runner_->PostTask(
293 FROM_HERE, base::Bind(&LoaderImpl::DecrementPendingLoads, this)); 293 FROM_HERE, base::Bind(&LoaderImpl::DecrementPendingLoads, this));
294 return; 294 return;
295 } 295 }
296 296
297 Scope* base_config = settings->base_config(); 297 Scope* base_config = settings->base_config();
298 base_config->set_source_dir(SourceDir("//")); 298 base_config->set_source_dir(SourceDir("//"));
299 299
300 settings->build_settings()->build_args().SetupRootScope( 300 settings->build_settings()->build_args().SetupRootScope(
301 base_config, toolchain_overrides); 301 base_config, toolchain_overrides);
302 302
(...skipping 29 matching lines...) Expand all
332 g_scheduler->FailWithError(Err(Location(), 332 g_scheduler->FailWithError(Err(Location(),
333 "The default build config file did not call set_default_toolchain()", 333 "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" 334 "If you don't call this, I can't figure out what toolchain to use\n"
335 "for all of this code.")); 335 "for all of this code."));
336 } else { 336 } else {
337 DCHECK(settings->toolchain_label().is_null()); 337 DCHECK(settings->toolchain_label().is_null());
338 settings->set_toolchain_label(default_toolchain_label); 338 settings->set_toolchain_label(default_toolchain_label);
339 } 339 }
340 } 340 }
341 341
342 main_loop_->task_runner()->PostTask( 342 task_runner_->PostTask(FROM_HERE,
343 FROM_HERE, base::Bind(&LoaderImpl::DidLoadBuildConfig, this, 343 base::Bind(&LoaderImpl::DidLoadBuildConfig, this,
344 settings->toolchain_label())); 344 settings->toolchain_label()));
345 } 345 }
346 346
347 void LoaderImpl::DidLoadFile() { 347 void LoaderImpl::DidLoadFile() {
348 DecrementPendingLoads(); 348 DecrementPendingLoads();
349 } 349 }
350 350
351 void LoaderImpl::DidLoadBuildConfig(const Label& label) { 351 void LoaderImpl::DidLoadBuildConfig(const Label& label) {
352 // Do not return early, we must call DecrementPendingLoads() at the bottom. 352 // Do not return early, we must call DecrementPendingLoads() at the bottom.
353 353
354 ToolchainRecordMap::iterator found_toolchain = toolchain_records_.find(label); 354 ToolchainRecordMap::iterator found_toolchain = toolchain_records_.find(label);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 const SourceFile& file_name, 421 const SourceFile& file_name,
422 const base::Callback<void(const ParseNode*)>& callback, 422 const base::Callback<void(const ParseNode*)>& callback,
423 Err* err) { 423 Err* err) {
424 if (async_load_file_.is_null()) { 424 if (async_load_file_.is_null()) {
425 return g_scheduler->input_file_manager()->AsyncLoadFile( 425 return g_scheduler->input_file_manager()->AsyncLoadFile(
426 origin, build_settings, file_name, callback, err); 426 origin, build_settings, file_name, callback, err);
427 } 427 }
428 return async_load_file_.Run( 428 return async_load_file_.Run(
429 origin, build_settings, file_name, callback, err); 429 origin, build_settings, file_name, callback, err);
430 } 430 }
OLDNEW
« no previous file with comments | « tools/gn/loader.h ('k') | tools/gn/loader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698