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/builder.h" | 5 #include "tools/gn/builder.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "tools/gn/config.h" | 10 #include "tools/gn/config.h" |
11 #include "tools/gn/deps_iterator.h" | 11 #include "tools/gn/deps_iterator.h" |
12 #include "tools/gn/err.h" | 12 #include "tools/gn/err.h" |
13 #include "tools/gn/loader.h" | 13 #include "tools/gn/loader.h" |
| 14 #include "tools/gn/pool.h" |
14 #include "tools/gn/scheduler.h" | 15 #include "tools/gn/scheduler.h" |
15 #include "tools/gn/settings.h" | 16 #include "tools/gn/settings.h" |
16 #include "tools/gn/target.h" | 17 #include "tools/gn/target.h" |
17 #include "tools/gn/trace.h" | 18 #include "tools/gn/trace.h" |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 typedef BuilderRecord::BuilderRecordSet BuilderRecordSet; | 22 typedef BuilderRecord::BuilderRecordSet BuilderRecordSet; |
22 | 23 |
23 // Recursively looks in the tree for a given node, returning true if it | 24 // Recursively looks in the tree for a given node, returning true if it |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 | 257 |
257 return true; | 258 return true; |
258 } | 259 } |
259 | 260 |
260 bool Builder::ToolchainDefined(BuilderRecord* record, Err* err) { | 261 bool Builder::ToolchainDefined(BuilderRecord* record, Err* err) { |
261 Toolchain* toolchain = record->item()->AsToolchain(); | 262 Toolchain* toolchain = record->item()->AsToolchain(); |
262 | 263 |
263 if (!AddDeps(record, toolchain->deps(), err)) | 264 if (!AddDeps(record, toolchain->deps(), err)) |
264 return false; | 265 return false; |
265 | 266 |
| 267 for (int i = Toolchain::TYPE_NONE + 1; i < Toolchain::TYPE_NUMTYPES; i++) { |
| 268 Toolchain::ToolType tool_type = static_cast<Toolchain::ToolType>(i); |
| 269 Tool* tool = toolchain->GetTool(tool_type); |
| 270 if (!tool || tool->pool().label.is_null()) |
| 271 continue; |
| 272 |
| 273 BuilderRecord* dep_record = GetOrCreateRecordOfType( |
| 274 tool->pool().label, tool->pool().origin, BuilderRecord::ITEM_POOL, err); |
| 275 if (!dep_record) |
| 276 return false; |
| 277 record->AddDep(dep_record); |
| 278 } |
| 279 |
266 // The default toolchain gets generated by default. Also propogate the | 280 // The default toolchain gets generated by default. Also propogate the |
267 // generate flag if it depends on items in a non-default toolchain. | 281 // generate flag if it depends on items in a non-default toolchain. |
268 if (record->should_generate() || | 282 if (record->should_generate() || |
269 toolchain->settings()->default_toolchain_label() == toolchain->label()) | 283 toolchain->settings()->default_toolchain_label() == toolchain->label()) |
270 RecursiveSetShouldGenerate(record, true); | 284 RecursiveSetShouldGenerate(record, true); |
271 | 285 |
272 loader_->ToolchainLoaded(toolchain); | 286 loader_->ToolchainLoaded(toolchain); |
273 return true; | 287 return true; |
274 } | 288 } |
275 | 289 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 !ResolveToolchain(target, err)) | 436 !ResolveToolchain(target, err)) |
423 return false; | 437 return false; |
424 } else if (record->type() == BuilderRecord::ITEM_CONFIG) { | 438 } else if (record->type() == BuilderRecord::ITEM_CONFIG) { |
425 Config* config = record->item()->AsConfig(); | 439 Config* config = record->item()->AsConfig(); |
426 if (!ResolveConfigs(&config->configs(), err)) | 440 if (!ResolveConfigs(&config->configs(), err)) |
427 return false; | 441 return false; |
428 } else if (record->type() == BuilderRecord::ITEM_TOOLCHAIN) { | 442 } else if (record->type() == BuilderRecord::ITEM_TOOLCHAIN) { |
429 Toolchain* toolchain = record->item()->AsToolchain(); | 443 Toolchain* toolchain = record->item()->AsToolchain(); |
430 if (!ResolveDeps(&toolchain->deps(), err)) | 444 if (!ResolveDeps(&toolchain->deps(), err)) |
431 return false; | 445 return false; |
| 446 if (!ResolvePools(toolchain, err)) |
| 447 return false; |
432 } | 448 } |
433 | 449 |
434 record->set_resolved(true); | 450 record->set_resolved(true); |
435 | 451 |
436 if (!record->item()->OnResolved(err)) | 452 if (!record->item()->OnResolved(err)) |
437 return false; | 453 return false; |
438 if (!resolved_callback_.is_null()) | 454 if (!resolved_callback_.is_null()) |
439 resolved_callback_.Run(record); | 455 resolved_callback_.Run(record); |
440 | 456 |
441 // Recursively update everybody waiting on this item to be resolved. | 457 // Recursively update everybody waiting on this item to be resolved. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 target->settings()->toolchain_label().GetUserVisibleName(false)); | 506 target->settings()->toolchain_label().GetUserVisibleName(false)); |
491 return false; | 507 return false; |
492 } | 508 } |
493 | 509 |
494 if (!target->SetToolchain(record->item()->AsToolchain(), err)) | 510 if (!target->SetToolchain(record->item()->AsToolchain(), err)) |
495 return false; | 511 return false; |
496 | 512 |
497 return true; | 513 return true; |
498 } | 514 } |
499 | 515 |
| 516 bool Builder::ResolvePools(Toolchain* toolchain, Err* err) { |
| 517 for (int i = Toolchain::TYPE_NONE + 1; i < Toolchain::TYPE_NUMTYPES; i++) { |
| 518 Toolchain::ToolType tool_type = static_cast<Toolchain::ToolType>(i); |
| 519 Tool* tool = toolchain->GetTool(tool_type); |
| 520 if (!tool || tool->pool().label.is_null()) |
| 521 continue; |
| 522 |
| 523 BuilderRecord* record = |
| 524 GetResolvedRecordOfType(tool->pool().label, toolchain->defined_from(), |
| 525 BuilderRecord::ITEM_POOL, err); |
| 526 if (!record) { |
| 527 *err = Err(tool->pool().origin, "Pool for tool not defined.", |
| 528 "I was hoping to find a pool " + |
| 529 tool->pool().label.GetUserVisibleName(false)); |
| 530 return false; |
| 531 } |
| 532 |
| 533 tool->set_pool(LabelPtrPair<Pool>(record->item()->AsPool())); |
| 534 } |
| 535 |
| 536 return true; |
| 537 } |
| 538 |
500 std::string Builder::CheckForCircularDependencies( | 539 std::string Builder::CheckForCircularDependencies( |
501 const std::vector<const BuilderRecord*>& bad_records) const { | 540 const std::vector<const BuilderRecord*>& bad_records) const { |
502 std::vector<const BuilderRecord*> cycle; | 541 std::vector<const BuilderRecord*> cycle; |
503 if (!RecursiveFindCycle(bad_records[0], &cycle)) | 542 if (!RecursiveFindCycle(bad_records[0], &cycle)) |
504 return std::string(); // Didn't find a cycle, something else is wrong. | 543 return std::string(); // Didn't find a cycle, something else is wrong. |
505 | 544 |
506 std::string ret; | 545 std::string ret; |
507 for (size_t i = 0; i < cycle.size(); i++) { | 546 for (size_t i = 0; i < cycle.size(); i++) { |
508 ret += " " + cycle[i]->label().GetUserVisibleName(false); | 547 ret += " " + cycle[i]->label().GetUserVisibleName(false); |
509 if (i != cycle.size() - 1) | 548 if (i != cycle.size() - 1) |
510 ret += " ->"; | 549 ret += " ->"; |
511 ret += "\n"; | 550 ret += "\n"; |
512 } | 551 } |
513 | 552 |
514 return ret; | 553 return ret; |
515 } | 554 } |
OLD | NEW |