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

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

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

Powered by Google App Engine
This is Rietveld 408576698