| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <set> | 6 #include <set> |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "tools/gn/commands.h" | 10 #include "tools/gn/commands.h" |
| 11 #include "tools/gn/config.h" | 11 #include "tools/gn/config.h" |
| 12 #include "tools/gn/config_values_extractors.h" | 12 #include "tools/gn/config_values_extractors.h" |
| 13 #include "tools/gn/deps_iterator.h" |
| 13 #include "tools/gn/filesystem_utils.h" | 14 #include "tools/gn/filesystem_utils.h" |
| 14 #include "tools/gn/item.h" | 15 #include "tools/gn/item.h" |
| 15 #include "tools/gn/label.h" | 16 #include "tools/gn/label.h" |
| 16 #include "tools/gn/setup.h" | 17 #include "tools/gn/setup.h" |
| 17 #include "tools/gn/standard_out.h" | 18 #include "tools/gn/standard_out.h" |
| 18 #include "tools/gn/substitution_writer.h" | 19 #include "tools/gn/substitution_writer.h" |
| 19 #include "tools/gn/target.h" | 20 #include "tools/gn/target.h" |
| 20 #include "tools/gn/variables.h" | 21 #include "tools/gn/variables.h" |
| 21 | 22 |
| 22 namespace commands { | 23 namespace commands { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 43 | 44 |
| 44 void RecursiveCollectDeps(const Target* target, std::set<Label>* result) { | 45 void RecursiveCollectDeps(const Target* target, std::set<Label>* result) { |
| 45 if (result->find(target->label()) != result->end()) | 46 if (result->find(target->label()) != result->end()) |
| 46 return; // Already did this target. | 47 return; // Already did this target. |
| 47 result->insert(target->label()); | 48 result->insert(target->label()); |
| 48 | 49 |
| 49 RecursiveCollectChildDeps(target, result); | 50 RecursiveCollectChildDeps(target, result); |
| 50 } | 51 } |
| 51 | 52 |
| 52 void RecursiveCollectChildDeps(const Target* target, std::set<Label>* result) { | 53 void RecursiveCollectChildDeps(const Target* target, std::set<Label>* result) { |
| 53 const LabelTargetVector& deps = target->deps(); | 54 for (DepsIterator iter(target); !iter.done(); iter.Advance()) |
| 54 for (size_t i = 0; i < deps.size(); i++) | 55 RecursiveCollectDeps(iter.target(), result); |
| 55 RecursiveCollectDeps(deps[i].ptr, result); | |
| 56 | |
| 57 const LabelTargetVector& datadeps = target->datadeps(); | |
| 58 for (size_t i = 0; i < datadeps.size(); i++) | |
| 59 RecursiveCollectDeps(datadeps[i].ptr, result); | |
| 60 } | 56 } |
| 61 | 57 |
| 62 // Prints dependencies of the given target (not the target itself). If the | 58 // Prints dependencies of the given target (not the target itself). If the |
| 63 // set is non-null, new targets encountered will be added to the set, and if | 59 // set is non-null, new targets encountered will be added to the set, and if |
| 64 // a dependency is in the set already, it will not be recused into. When the | 60 // a dependency is in the set already, it will not be recused into. When the |
| 65 // set is null, all dependencies will be printed. | 61 // set is null, all dependencies will be printed. |
| 66 void RecursivePrintDeps(const Target* target, | 62 void RecursivePrintDeps(const Target* target, |
| 67 const Label& default_toolchain, | 63 const Label& default_toolchain, |
| 68 std::set<const Target*>* seen_targets, | 64 std::set<const Target*>* seen_targets, |
| 69 int indent_level) { | 65 int indent_level) { |
| 70 LabelTargetVector sorted_deps = target->deps(); | 66 // Combine all deps into one sorted list. |
| 71 const LabelTargetVector& datadeps = target->datadeps(); | 67 std::vector<LabelTargetPair> sorted_deps; |
| 72 sorted_deps.insert(sorted_deps.end(), datadeps.begin(), datadeps.end()); | 68 for (DepsIterator iter(target); !iter.done(); iter.Advance()) |
| 69 sorted_deps.push_back(iter.pair()); |
| 73 std::sort(sorted_deps.begin(), sorted_deps.end(), | 70 std::sort(sorted_deps.begin(), sorted_deps.end(), |
| 74 LabelPtrLabelLess<Target>()); | 71 LabelPtrLabelLess<Target>()); |
| 75 | 72 |
| 76 std::string indent(indent_level * 2, ' '); | 73 std::string indent(indent_level * 2, ' '); |
| 77 for (size_t i = 0; i < sorted_deps.size(); i++) { | 74 for (size_t i = 0; i < sorted_deps.size(); i++) { |
| 78 const Target* cur_dep = sorted_deps[i].ptr; | 75 const Target* cur_dep = sorted_deps[i].ptr; |
| 79 | 76 |
| 80 // Don't print groups. Groups are flattened such that the deps of the | |
| 81 // group are added directly to the target that depended on the group. | |
| 82 // Printing and recursing into groups here will cause such targets to be | |
| 83 // duplicated. | |
| 84 // | |
| 85 // It would be much more intuitive to do the opposite and not display the | |
| 86 // deps that were copied from the group to the target and instead display | |
| 87 // the group, but the source of those dependencies is not tracked. | |
| 88 if (cur_dep->output_type() == Target::GROUP) | |
| 89 continue; | |
| 90 | |
| 91 OutputString(indent + | 77 OutputString(indent + |
| 92 cur_dep->label().GetUserVisibleName(default_toolchain)); | 78 cur_dep->label().GetUserVisibleName(default_toolchain)); |
| 93 bool print_children = true; | 79 bool print_children = true; |
| 94 if (seen_targets) { | 80 if (seen_targets) { |
| 95 if (seen_targets->find(cur_dep) == seen_targets->end()) { | 81 if (seen_targets->find(cur_dep) == seen_targets->end()) { |
| 96 // New target, mark it visited. | 82 // New target, mark it visited. |
| 97 seen_targets->insert(cur_dep); | 83 seen_targets->insert(cur_dep); |
| 98 } else { | 84 } else { |
| 99 // Already seen. | 85 // Already seen. |
| 100 print_children = false; | 86 print_children = false; |
| 101 // Only print "..." if something is actually elided, which means that | 87 // Only print "..." if something is actually elided, which means that |
| 102 // the current target has children. | 88 // the current target has children. |
| 103 if (!cur_dep->deps().empty() || !cur_dep->datadeps().empty()) | 89 if (!cur_dep->public_deps().empty() || |
| 90 !cur_dep->private_deps().empty() || |
| 91 !cur_dep->data_deps().empty()) |
| 104 OutputString("..."); | 92 OutputString("..."); |
| 105 } | 93 } |
| 106 } | 94 } |
| 107 | 95 |
| 108 OutputString("\n"); | 96 OutputString("\n"); |
| 109 if (print_children) { | 97 if (print_children) { |
| 110 RecursivePrintDeps(cur_dep, default_toolchain, seen_targets, | 98 RecursivePrintDeps(cur_dep, default_toolchain, seen_targets, |
| 111 indent_level + 1); | 99 indent_level + 1); |
| 112 } | 100 } |
| 113 } | 101 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 129 // Don't recurse into duplicates. | 117 // Don't recurse into duplicates. |
| 130 std::set<const Target*> seen_targets; | 118 std::set<const Target*> seen_targets; |
| 131 RecursivePrintDeps(target, toolchain_label, &seen_targets, 1); | 119 RecursivePrintDeps(target, toolchain_label, &seen_targets, 1); |
| 132 } | 120 } |
| 133 return; | 121 return; |
| 134 } | 122 } |
| 135 | 123 |
| 136 // Collect the deps to display. | 124 // Collect the deps to display. |
| 137 std::vector<Label> deps; | 125 std::vector<Label> deps; |
| 138 if (cmdline->HasSwitch("all")) { | 126 if (cmdline->HasSwitch("all")) { |
| 127 // Show all dependencies. |
| 139 if (display_header) | 128 if (display_header) |
| 140 OutputString("\nAll recursive dependencies:\n"); | 129 OutputString("\nAll recursive dependencies:\n"); |
| 141 | 130 |
| 142 std::set<Label> all_deps; | 131 std::set<Label> all_deps; |
| 143 RecursiveCollectChildDeps(target, &all_deps); | 132 RecursiveCollectChildDeps(target, &all_deps); |
| 144 for (std::set<Label>::iterator i = all_deps.begin(); | 133 for (std::set<Label>::iterator i = all_deps.begin(); |
| 145 i != all_deps.end(); ++i) | 134 i != all_deps.end(); ++i) |
| 146 deps.push_back(*i); | 135 deps.push_back(*i); |
| 147 } else { | 136 } else { |
| 137 // Show direct dependencies only. |
| 148 if (display_header) { | 138 if (display_header) { |
| 149 OutputString( | 139 OutputString( |
| 150 "\nDirect dependencies " | 140 "\nDirect dependencies " |
| 151 "(try also \"--all\", \"--tree\", or even \"--all --tree\"):\n"); | 141 "(try also \"--all\", \"--tree\", or even \"--all --tree\"):\n"); |
| 152 } | 142 } |
| 153 | 143 for (DepsIterator iter(target); !iter.done(); iter.Advance()) |
| 154 const LabelTargetVector& target_deps = target->deps(); | 144 deps.push_back(iter.label()); |
| 155 for (size_t i = 0; i < target_deps.size(); i++) | |
| 156 deps.push_back(target_deps[i].label); | |
| 157 | |
| 158 const LabelTargetVector& target_datadeps = target->datadeps(); | |
| 159 for (size_t i = 0; i < target_datadeps.size(); i++) | |
| 160 deps.push_back(target_datadeps[i].label); | |
| 161 } | 145 } |
| 162 | 146 |
| 163 std::sort(deps.begin(), deps.end()); | 147 std::sort(deps.begin(), deps.end()); |
| 164 for (size_t i = 0; i < deps.size(); i++) | 148 for (size_t i = 0; i < deps.size(); i++) |
| 165 OutputString(" " + deps[i].GetUserVisibleName(toolchain_label) + "\n"); | 149 OutputString(" " + deps[i].GetUserVisibleName(toolchain_label) + "\n"); |
| 166 } | 150 } |
| 167 | 151 |
| 168 void PrintForwardDependentConfigsFrom(const Target* target, | 152 void PrintForwardDependentConfigsFrom(const Target* target, |
| 169 bool display_header) { | 153 bool display_header) { |
| 170 if (target->forward_dependent_configs().empty()) | 154 if (target->forward_dependent_configs().empty()) |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 OutputString(" " + | 282 OutputString(" " + |
| 299 configs[i].label.GetUserVisibleName(toolchain_label) + "\n"); | 283 configs[i].label.GetUserVisibleName(toolchain_label) + "\n"); |
| 300 } | 284 } |
| 301 } | 285 } |
| 302 | 286 |
| 303 void PrintConfigs(const Target* target, bool display_header) { | 287 void PrintConfigs(const Target* target, bool display_header) { |
| 304 PrintConfigsVector(target, target->configs().vector(), "configs", | 288 PrintConfigsVector(target, target->configs().vector(), "configs", |
| 305 display_header); | 289 display_header); |
| 306 } | 290 } |
| 307 | 291 |
| 308 void PrintDirectDependentConfigs(const Target* target, bool display_header) { | 292 void PrintPublicConfigs(const Target* target, bool display_header) { |
| 309 PrintConfigsVector(target, target->direct_dependent_configs(), | 293 PrintConfigsVector(target, target->public_configs(), |
| 310 "direct_dependent_configs", display_header); | 294 "public_configs", display_header); |
| 311 } | 295 } |
| 312 | 296 |
| 313 void PrintAllDependentConfigs(const Target* target, bool display_header) { | 297 void PrintAllDependentConfigs(const Target* target, bool display_header) { |
| 314 PrintConfigsVector(target, target->all_dependent_configs(), | 298 PrintConfigsVector(target, target->all_dependent_configs(), |
| 315 "all_dependent_configs", display_header); | 299 "all_dependent_configs", display_header); |
| 316 } | 300 } |
| 317 | 301 |
| 318 void PrintFileList(const Target::FileList& files, | 302 void PrintFileList(const Target::FileList& files, |
| 319 const std::string& header, | 303 const std::string& header, |
| 320 bool indent_extra, | 304 bool indent_extra, |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 " they're specified. This includes both configs specified in the\n" | 487 " they're specified. This includes both configs specified in the\n" |
| 504 " \"configs\" variable, as well as configs pushed onto this target\n" | 488 " \"configs\" variable, as well as configs pushed onto this target\n" |
| 505 " via dependencies specifying \"all\" or \"direct\" dependent\n" | 489 " via dependencies specifying \"all\" or \"direct\" dependent\n" |
| 506 " configs.\n" | 490 " configs.\n" |
| 507 "\n" | 491 "\n" |
| 508 " deps [--all | --tree]\n" | 492 " deps [--all | --tree]\n" |
| 509 " Show immediate (or, when \"--all\" or \"--tree\" is specified,\n" | 493 " Show immediate (or, when \"--all\" or \"--tree\" is specified,\n" |
| 510 " recursive) dependencies of the given target. \"--tree\" shows them\n" | 494 " recursive) dependencies of the given target. \"--tree\" shows them\n" |
| 511 " in a tree format with duplicates elided (noted by \"...\").\n" | 495 " in a tree format with duplicates elided (noted by \"...\").\n" |
| 512 " \"--all\" shows them sorted alphabetically. Using both flags will\n" | 496 " \"--all\" shows them sorted alphabetically. Using both flags will\n" |
| 513 " print a tree with no omissions. Both \"deps\" and \"datadeps\"\n" | 497 " print a tree with no omissions. The \"deps\", \"public_deps\", and\n" |
| 514 " will be included.\n" | 498 " \"data_deps\" will all be included.\n" |
| 515 "\n" | 499 "\n" |
| 516 " direct_dependent_configs\n" | 500 " public_configs\n" |
| 517 " all_dependent_configs\n" | 501 " all_dependent_configs\n" |
| 518 " Shows the labels of configs applied to targets that depend on this\n" | 502 " Shows the labels of configs applied to targets that depend on this\n" |
| 519 " one (either directly or all of them).\n" | 503 " one (either directly or all of them).\n" |
| 520 "\n" | 504 "\n" |
| 521 " forward_dependent_configs_from\n" | 505 " forward_dependent_configs_from\n" |
| 522 " Shows the labels of dependencies for which dependent configs will\n" | 506 " Shows the labels of dependencies for which dependent configs will\n" |
| 523 " be pushed to targets depending on the current one.\n" | 507 " be pushed to targets depending on the current one.\n" |
| 524 "\n" | 508 "\n" |
| 525 " script\n" | 509 " script\n" |
| 526 " args\n" | 510 " args\n" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 return 1; | 573 return 1; |
| 590 | 574 |
| 591 #define CONFIG_VALUE_HANDLER(name, type) \ | 575 #define CONFIG_VALUE_HANDLER(name, type) \ |
| 592 } else if (what == #name) { OUTPUT_CONFIG_VALUE(name, type) | 576 } else if (what == #name) { OUTPUT_CONFIG_VALUE(name, type) |
| 593 | 577 |
| 594 if (args.size() == 3) { | 578 if (args.size() == 3) { |
| 595 // User specified one thing to display. | 579 // User specified one thing to display. |
| 596 const std::string& what = args[2]; | 580 const std::string& what = args[2]; |
| 597 if (what == variables::kConfigs) { | 581 if (what == variables::kConfigs) { |
| 598 PrintConfigs(target, false); | 582 PrintConfigs(target, false); |
| 599 } else if (what == variables::kDirectDependentConfigs) { | 583 } else if (what == variables::kPublicConfigs) { |
| 600 PrintDirectDependentConfigs(target, false); | 584 PrintPublicConfigs(target, false); |
| 601 } else if (what == variables::kAllDependentConfigs) { | 585 } else if (what == variables::kAllDependentConfigs) { |
| 602 PrintAllDependentConfigs(target, false); | 586 PrintAllDependentConfigs(target, false); |
| 603 } else if (what == variables::kForwardDependentConfigsFrom) { | 587 } else if (what == variables::kForwardDependentConfigsFrom) { |
| 604 PrintForwardDependentConfigsFrom(target, false); | 588 PrintForwardDependentConfigsFrom(target, false); |
| 605 } else if (what == variables::kSources) { | 589 } else if (what == variables::kSources) { |
| 606 PrintSources(target, false); | 590 PrintSources(target, false); |
| 607 } else if (what == variables::kPublic) { | 591 } else if (what == variables::kPublic) { |
| 608 PrintPublic(target, false); | 592 PrintPublic(target, false); |
| 609 } else if (what == variables::kCheckIncludes) { | 593 } else if (what == variables::kCheckIncludes) { |
| 610 PrintCheckIncludes(target, false); | 594 PrintCheckIncludes(target, false); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 PrintPublic(target, true); | 661 PrintPublic(target, true); |
| 678 PrintCheckIncludes(target, true); | 662 PrintCheckIncludes(target, true); |
| 679 PrintAllowCircularIncludesFrom(target, true); | 663 PrintAllowCircularIncludesFrom(target, true); |
| 680 } | 664 } |
| 681 PrintVisibility(target, true); | 665 PrintVisibility(target, true); |
| 682 if (is_binary_output) { | 666 if (is_binary_output) { |
| 683 PrintTestonly(target, true); | 667 PrintTestonly(target, true); |
| 684 PrintConfigs(target, true); | 668 PrintConfigs(target, true); |
| 685 } | 669 } |
| 686 | 670 |
| 687 PrintDirectDependentConfigs(target, true); | 671 PrintPublicConfigs(target, true); |
| 688 PrintAllDependentConfigs(target, true); | 672 PrintAllDependentConfigs(target, true); |
| 689 PrintForwardDependentConfigsFrom(target, true); | 673 PrintForwardDependentConfigsFrom(target, true); |
| 690 | 674 |
| 691 PrintInputs(target, true); | 675 PrintInputs(target, true); |
| 692 | 676 |
| 693 if (is_binary_output) { | 677 if (is_binary_output) { |
| 694 OUTPUT_CONFIG_VALUE(defines, std::string) | 678 OUTPUT_CONFIG_VALUE(defines, std::string) |
| 695 OUTPUT_CONFIG_VALUE(include_dirs, SourceDir) | 679 OUTPUT_CONFIG_VALUE(include_dirs, SourceDir) |
| 696 OUTPUT_CONFIG_VALUE(cflags, std::string) | 680 OUTPUT_CONFIG_VALUE(cflags, std::string) |
| 697 OUTPUT_CONFIG_VALUE(cflags_c, std::string) | 681 OUTPUT_CONFIG_VALUE(cflags_c, std::string) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 718 // so always display them, even for groups and such. | 702 // so always display them, even for groups and such. |
| 719 PrintLibs(target, true); | 703 PrintLibs(target, true); |
| 720 PrintLibDirs(target, true); | 704 PrintLibDirs(target, true); |
| 721 | 705 |
| 722 PrintDeps(target, true); | 706 PrintDeps(target, true); |
| 723 | 707 |
| 724 return 0; | 708 return 0; |
| 725 } | 709 } |
| 726 | 710 |
| 727 } // namespace commands | 711 } // namespace commands |
| OLD | NEW |