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/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "tools/gn/build_settings.h" | 10 #include "tools/gn/build_settings.h" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 258 |
259 Err err; | 259 Err err; |
260 root->Execute(&our_scope, &err); | 260 root->Execute(&our_scope, &err); |
261 if (err.has_error()) | 261 if (err.has_error()) |
262 g_scheduler->FailWithError(err); | 262 g_scheduler->FailWithError(err); |
263 | 263 |
264 if (!our_scope.CheckForUnusedVars(&err)) | 264 if (!our_scope.CheckForUnusedVars(&err)) |
265 g_scheduler->FailWithError(err); | 265 g_scheduler->FailWithError(err); |
266 | 266 |
267 // Pass all of the items that were defined off to the builder. | 267 // Pass all of the items that were defined off to the builder. |
268 for (size_t i = 0; i < collected_items.size(); i++) | 268 for (const auto& item : collected_items) |
269 settings->build_settings()->ItemDefined(collected_items[i]->Pass()); | 269 settings->build_settings()->ItemDefined(item->Pass()); |
270 | 270 |
271 trace.Done(); | 271 trace.Done(); |
272 | 272 |
273 main_loop_->PostTask(FROM_HERE, base::Bind(&LoaderImpl::DidLoadFile, this)); | 273 main_loop_->PostTask(FROM_HERE, base::Bind(&LoaderImpl::DidLoadFile, this)); |
274 } | 274 } |
275 | 275 |
276 void LoaderImpl::BackgroundLoadBuildConfig( | 276 void LoaderImpl::BackgroundLoadBuildConfig( |
277 Settings* settings, | 277 Settings* settings, |
278 const Scope::KeyValueMap& toolchain_overrides, | 278 const Scope::KeyValueMap& toolchain_overrides, |
279 const ParseNode* root) { | 279 const ParseNode* root) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 record->settings.set_default_toolchain_label(label); | 364 record->settings.set_default_toolchain_label(label); |
365 | 365 |
366 // The settings object should have the toolchain label already set. | 366 // The settings object should have the toolchain label already set. |
367 DCHECK(!record->settings.toolchain_label().is_null()); | 367 DCHECK(!record->settings.toolchain_label().is_null()); |
368 | 368 |
369 // Update any stored invocations that refer to the empty toolchain label. | 369 // Update any stored invocations that refer to the empty toolchain label. |
370 // This will normally only be one, for the root build file, so brute-force | 370 // This will normally only be one, for the root build file, so brute-force |
371 // is OK. | 371 // is OK. |
372 LoadIDSet old_loads; | 372 LoadIDSet old_loads; |
373 invocations_.swap(old_loads); | 373 invocations_.swap(old_loads); |
374 for (LoadIDSet::iterator i = old_loads.begin(); | 374 for (const auto& load : old_loads) { |
375 i != old_loads.end(); ++i) { | 375 if (load.toolchain_name.is_null()) { |
376 if (i->toolchain_name.is_null()) { | |
377 // Fix up toolchain label | 376 // Fix up toolchain label |
378 invocations_.insert(LoadID(i->file, label)); | 377 invocations_.insert(LoadID(load.file, label)); |
379 } else { | 378 } else { |
380 // Can keep the old one. | 379 // Can keep the old one. |
381 invocations_.insert(*i); | 380 invocations_.insert(load); |
382 } | 381 } |
383 } | 382 } |
384 } else { | 383 } else { |
385 record = found_toolchain->second; | 384 record = found_toolchain->second; |
386 } | 385 } |
387 | 386 |
388 DCHECK(!record->is_config_loaded); | 387 DCHECK(!record->is_config_loaded); |
389 DCHECK(record->is_toolchain_loaded); | 388 DCHECK(record->is_toolchain_loaded); |
390 record->is_config_loaded = true; | 389 record->is_config_loaded = true; |
391 | 390 |
392 // Schedule all waiting file loads. | 391 // Schedule all waiting file loads. |
393 for (size_t i = 0; i < record->waiting_on_me.size(); i++) { | 392 for (const auto& waiting : record->waiting_on_me) |
394 ScheduleLoadFile(&record->settings, record->waiting_on_me[i].origin, | 393 ScheduleLoadFile(&record->settings, waiting.origin, waiting.file); |
395 record->waiting_on_me[i].file); | |
396 } | |
397 record->waiting_on_me.clear(); | 394 record->waiting_on_me.clear(); |
398 | 395 |
399 DecrementPendingLoads(); | 396 DecrementPendingLoads(); |
400 } | 397 } |
401 | 398 |
402 void LoaderImpl::DecrementPendingLoads() { | 399 void LoaderImpl::DecrementPendingLoads() { |
403 DCHECK(pending_loads_ > 0); | 400 DCHECK(pending_loads_ > 0); |
404 pending_loads_--; | 401 pending_loads_--; |
405 if (pending_loads_ == 0 && !complete_callback_.is_null()) | 402 if (pending_loads_ == 0 && !complete_callback_.is_null()) |
406 complete_callback_.Run(); | 403 complete_callback_.Run(); |
407 } | 404 } |
408 | 405 |
409 bool LoaderImpl::AsyncLoadFile( | 406 bool LoaderImpl::AsyncLoadFile( |
410 const LocationRange& origin, | 407 const LocationRange& origin, |
411 const BuildSettings* build_settings, | 408 const BuildSettings* build_settings, |
412 const SourceFile& file_name, | 409 const SourceFile& file_name, |
413 const base::Callback<void(const ParseNode*)>& callback, | 410 const base::Callback<void(const ParseNode*)>& callback, |
414 Err* err) { | 411 Err* err) { |
415 if (async_load_file_.is_null()) { | 412 if (async_load_file_.is_null()) { |
416 return g_scheduler->input_file_manager()->AsyncLoadFile( | 413 return g_scheduler->input_file_manager()->AsyncLoadFile( |
417 origin, build_settings, file_name, callback, err); | 414 origin, build_settings, file_name, callback, err); |
418 } | 415 } |
419 return async_load_file_.Run( | 416 return async_load_file_.Run( |
420 origin, build_settings, file_name, callback, err); | 417 origin, build_settings, file_name, callback, err); |
421 } | 418 } |
OLD | NEW |