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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 Settings settings; | 72 Settings settings; |
73 | 73 |
74 bool is_toolchain_loaded; | 74 bool is_toolchain_loaded; |
75 bool is_config_loaded; | 75 bool is_config_loaded; |
76 | 76 |
77 std::vector<SourceFileAndOrigin> waiting_on_me; | 77 std::vector<SourceFileAndOrigin> waiting_on_me; |
78 }; | 78 }; |
79 | 79 |
80 // ----------------------------------------------------------------------------- | 80 // ----------------------------------------------------------------------------- |
81 | 81 |
82 const void* Loader::kDefaultToolchainKey = &kDefaultToolchainKey; | 82 const void* const Loader::kDefaultToolchainKey = &kDefaultToolchainKey; |
83 | 83 |
84 Loader::Loader() { | 84 Loader::Loader() { |
85 } | 85 } |
86 | 86 |
87 Loader::~Loader() { | 87 Loader::~Loader() { |
88 } | 88 } |
89 | 89 |
90 void Loader::Load(const Label& label, const LocationRange& origin) { | 90 void Loader::Load(const Label& label, const LocationRange& origin) { |
91 Load(BuildFileForLabel(label), origin, label.GetToolchainLabel()); | 91 Load(BuildFileForLabel(label), origin, label.GetToolchainLabel()); |
92 } | 92 } |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 // Do not return early, we must call DecrementPendingLoads() at the bottom. | 343 // Do not return early, we must call DecrementPendingLoads() at the bottom. |
344 | 344 |
345 ToolchainRecordMap::iterator found_toolchain = toolchain_records_.find(label); | 345 ToolchainRecordMap::iterator found_toolchain = toolchain_records_.find(label); |
346 ToolchainRecord* record = nullptr; | 346 ToolchainRecord* record = nullptr; |
347 if (found_toolchain == toolchain_records_.end()) { | 347 if (found_toolchain == toolchain_records_.end()) { |
348 // When loading the default build config, we'll insert it into the record | 348 // When loading the default build config, we'll insert it into the record |
349 // map with an empty label since we don't yet know what to call it. | 349 // map with an empty label since we don't yet know what to call it. |
350 // | 350 // |
351 // In this case, we should have exactly one entry in the map with an empty | 351 // In this case, we should have exactly one entry in the map with an empty |
352 // label. We now need to fix up the naming so it refers to the "real" one. | 352 // label. We now need to fix up the naming so it refers to the "real" one. |
353 CHECK(toolchain_records_.size() == 1); | 353 CHECK_EQ(1U, toolchain_records_.size()); |
354 ToolchainRecordMap::iterator empty_label = toolchain_records_.find(Label()); | 354 ToolchainRecordMap::iterator empty_label = toolchain_records_.find(Label()); |
355 CHECK(empty_label != toolchain_records_.end()); | 355 CHECK(empty_label != toolchain_records_.end()); |
356 | 356 |
357 // Fix up the toolchain record. | 357 // Fix up the toolchain record. |
358 record = empty_label->second; | 358 record = empty_label->second; |
359 toolchain_records_[label] = record; | 359 toolchain_records_[label] = record; |
360 toolchain_records_.erase(empty_label); | 360 toolchain_records_.erase(empty_label); |
361 | 361 |
362 // Save the default toolchain label. | 362 // Save the default toolchain label. |
363 default_toolchain_label_ = label; | 363 default_toolchain_label_ = label; |
(...skipping 27 matching lines...) Expand all Loading... |
391 | 391 |
392 // Schedule all waiting file loads. | 392 // Schedule all waiting file loads. |
393 for (const auto& waiting : record->waiting_on_me) | 393 for (const auto& waiting : record->waiting_on_me) |
394 ScheduleLoadFile(&record->settings, waiting.origin, waiting.file); | 394 ScheduleLoadFile(&record->settings, waiting.origin, waiting.file); |
395 record->waiting_on_me.clear(); | 395 record->waiting_on_me.clear(); |
396 | 396 |
397 DecrementPendingLoads(); | 397 DecrementPendingLoads(); |
398 } | 398 } |
399 | 399 |
400 void LoaderImpl::DecrementPendingLoads() { | 400 void LoaderImpl::DecrementPendingLoads() { |
401 DCHECK(pending_loads_ > 0); | 401 DCHECK_GT(pending_loads_, 0); |
402 pending_loads_--; | 402 pending_loads_--; |
403 if (pending_loads_ == 0 && !complete_callback_.is_null()) | 403 if (pending_loads_ == 0 && !complete_callback_.is_null()) |
404 complete_callback_.Run(); | 404 complete_callback_.Run(); |
405 } | 405 } |
406 | 406 |
407 bool LoaderImpl::AsyncLoadFile( | 407 bool LoaderImpl::AsyncLoadFile( |
408 const LocationRange& origin, | 408 const LocationRange& origin, |
409 const BuildSettings* build_settings, | 409 const BuildSettings* build_settings, |
410 const SourceFile& file_name, | 410 const SourceFile& file_name, |
411 const base::Callback<void(const ParseNode*)>& callback, | 411 const base::Callback<void(const ParseNode*)>& callback, |
412 Err* err) { | 412 Err* err) { |
413 if (async_load_file_.is_null()) { | 413 if (async_load_file_.is_null()) { |
414 return g_scheduler->input_file_manager()->AsyncLoadFile( | 414 return g_scheduler->input_file_manager()->AsyncLoadFile( |
415 origin, build_settings, file_name, callback, err); | 415 origin, build_settings, file_name, callback, err); |
416 } | 416 } |
417 return async_load_file_.Run( | 417 return async_load_file_.Run( |
418 origin, build_settings, file_name, callback, err); | 418 origin, build_settings, file_name, callback, err); |
419 } | 419 } |
OLD | NEW |