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

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

Issue 937003002: Enhance GN introspection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 5 years, 10 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
« no previous file with comments | « tools/gn/command_check.cc ('k') | tools/gn/command_ls.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 22 matching lines...) Expand all
33 std::string buf = dir.value(); 33 std::string buf = dir.value();
34 if (buf.size() > 3 && buf[2] == ':') { 34 if (buf.size() > 3 && buf[2] == ':') {
35 buf.erase(buf.begin()); // Erase beginning slash. 35 buf.erase(buf.begin()); // Erase beginning slash.
36 return buf; 36 return buf;
37 } 37 }
38 } 38 }
39 #endif 39 #endif
40 return dir.value(); 40 return dir.value();
41 } 41 }
42 42
43 void RecursiveCollectChildDeps(const Target* target, std::set<Label>* result); 43 void RecursiveCollectChildDeps(const Target* target,
44 std::set<const Target*>* result);
44 45
45 void RecursiveCollectDeps(const Target* target, std::set<Label>* result) { 46 void RecursiveCollectDeps(const Target* target,
46 if (result->find(target->label()) != result->end()) 47 std::set<const Target*>* result) {
48 if (result->find(target) != result->end())
47 return; // Already did this target. 49 return; // Already did this target.
48 result->insert(target->label()); 50 result->insert(target);
49 51
50 RecursiveCollectChildDeps(target, result); 52 RecursiveCollectChildDeps(target, result);
51 } 53 }
52 54
53 void RecursiveCollectChildDeps(const Target* target, std::set<Label>* result) { 55 void RecursiveCollectChildDeps(const Target* target,
56 std::set<const Target*>* result) {
54 for (const auto& pair : target->GetDeps(Target::DEPS_ALL)) 57 for (const auto& pair : target->GetDeps(Target::DEPS_ALL))
55 RecursiveCollectDeps(pair.ptr, result); 58 RecursiveCollectDeps(pair.ptr, result);
56 } 59 }
57 60
58 // Prints dependencies of the given target (not the target itself). If the 61 // Prints dependencies of the given target (not the target itself). If the
59 // set is non-null, new targets encountered will be added to the set, and if 62 // set is non-null, new targets encountered will be added to the set, and if
60 // a dependency is in the set already, it will not be recused into. When the 63 // a dependency is in the set already, it will not be recused into. When the
61 // set is null, all dependencies will be printed. 64 // set is null, all dependencies will be printed.
62 void RecursivePrintDeps(const Target* target, 65 void RecursivePrintDeps(const Target* target,
63 const Label& default_toolchain, 66 const Label& default_toolchain,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 RecursivePrintDeps(target, toolchain_label, nullptr, 1); 118 RecursivePrintDeps(target, toolchain_label, nullptr, 1);
116 } else { 119 } else {
117 // Don't recurse into duplicates. 120 // Don't recurse into duplicates.
118 std::set<const Target*> seen_targets; 121 std::set<const Target*> seen_targets;
119 RecursivePrintDeps(target, toolchain_label, &seen_targets, 1); 122 RecursivePrintDeps(target, toolchain_label, &seen_targets, 1);
120 } 123 }
121 return; 124 return;
122 } 125 }
123 126
124 // Collect the deps to display. 127 // Collect the deps to display.
125 std::vector<Label> deps;
126 if (cmdline->HasSwitch("all")) { 128 if (cmdline->HasSwitch("all")) {
127 // Show all dependencies. 129 // Show all dependencies.
128 if (display_header) 130 if (display_header)
129 OutputString("\nAll recursive dependencies:\n"); 131 OutputString("\nAll recursive dependencies:\n");
130 132
131 std::set<Label> all_deps; 133 std::set<const Target*> all_deps;
132 RecursiveCollectChildDeps(target, &all_deps); 134 RecursiveCollectChildDeps(target, &all_deps);
133 for (const auto& dep : all_deps) 135 FilterAndPrintTargetSet(display_header, all_deps);
134 deps.push_back(dep);
135 } else { 136 } else {
137 std::vector<const Target*> deps;
136 // Show direct dependencies only. 138 // Show direct dependencies only.
137 if (display_header) { 139 if (display_header) {
138 OutputString( 140 OutputString(
139 "\nDirect dependencies " 141 "\nDirect dependencies "
140 "(try also \"--all\", \"--tree\", or even \"--all --tree\"):\n"); 142 "(try also \"--all\", \"--tree\", or even \"--all --tree\"):\n");
141 } 143 }
142 for (const auto& pair : target->GetDeps(Target::DEPS_ALL)) 144 for (const auto& pair : target->GetDeps(Target::DEPS_ALL))
143 deps.push_back(pair.label); 145 deps.push_back(pair.ptr);
146 std::sort(deps.begin(), deps.end());
147 FilterAndPrintTargets(display_header, &deps);
144 } 148 }
145
146 std::sort(deps.begin(), deps.end());
147 for (const auto& dep : deps)
148 OutputString(" " + dep.GetUserVisibleName(toolchain_label) + "\n");
149 } 149 }
150 150
151 void PrintForwardDependentConfigsFrom(const Target* target, 151 void PrintForwardDependentConfigsFrom(const Target* target,
152 bool display_header) { 152 bool display_header) {
153 if (target->forward_dependent_configs().empty()) 153 if (target->forward_dependent_configs().empty())
154 return; 154 return;
155 155
156 if (display_header) 156 if (display_header)
157 OutputString("\nforward_dependent_configs_from:\n"); 157 OutputString("\nforward_dependent_configs_from:\n");
158 158
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 } 442 }
443 443
444 } // namespace 444 } // namespace
445 445
446 // desc ------------------------------------------------------------------------ 446 // desc ------------------------------------------------------------------------
447 447
448 const char kDesc[] = "desc"; 448 const char kDesc[] = "desc";
449 const char kDesc_HelpShort[] = 449 const char kDesc_HelpShort[] =
450 "desc: Show lots of insightful information about a target."; 450 "desc: Show lots of insightful information about a target.";
451 const char kDesc_Help[] = 451 const char kDesc_Help[] =
452 "gn desc <out_dir> <target label> [<what to show>]\n" 452 "gn desc <out_dir> <target label> [<what to show>] [--blame]\n"
453 " [--blame] [--all | --tree]\n"
454 "\n" 453 "\n"
455 " Displays information about a given labeled target for the given build.\n" 454 " Displays information about a given labeled target for the given build.\n"
456 " The build parameters will be taken for the build in the given\n" 455 " The build parameters will be taken for the build in the given\n"
457 " <out_dir>.\n" 456 " <out_dir>.\n"
458 "\n" 457 "\n"
459 "Possibilities for <what to show>:\n" 458 "Possibilities for <what to show>\n"
460 " (If unspecified an overall summary will be displayed.)\n" 459 " (If unspecified an overall summary will be displayed.)\n"
461 "\n" 460 "\n"
462 " sources\n" 461 " sources\n"
463 " Source files.\n" 462 " Source files.\n"
464 "\n" 463 "\n"
465 " inputs\n" 464 " inputs\n"
466 " Additional input dependencies.\n" 465 " Additional input dependencies.\n"
467 "\n" 466 "\n"
468 " public\n" 467 " public\n"
469 " Public header files.\n" 468 " Public header files.\n"
(...skipping 10 matching lines...) Expand all
480 " testonly\n" 479 " testonly\n"
481 " Whether this target may only be used in tests.\n" 480 " Whether this target may only be used in tests.\n"
482 "\n" 481 "\n"
483 " configs\n" 482 " configs\n"
484 " Shows configs applied to the given target, sorted in the order\n" 483 " Shows configs applied to the given target, sorted in the order\n"
485 " they're specified. This includes both configs specified in the\n" 484 " they're specified. This includes both configs specified in the\n"
486 " \"configs\" variable, as well as configs pushed onto this target\n" 485 " \"configs\" variable, as well as configs pushed onto this target\n"
487 " via dependencies specifying \"all\" or \"direct\" dependent\n" 486 " via dependencies specifying \"all\" or \"direct\" dependent\n"
488 " configs.\n" 487 " configs.\n"
489 "\n" 488 "\n"
490 " deps [--all | --tree]\n" 489 " deps\n"
491 " Show immediate (or, when \"--all\" or \"--tree\" is specified,\n" 490 " Show immediate or recursive dependencies. See below for flags that\n"
492 " recursive) dependencies of the given target. \"--tree\" shows them\n" 491 " control deps printing.\n"
493 " in a tree format with duplicates elided (noted by \"...\").\n"
494 " \"--all\" shows them sorted alphabetically. Using both flags will\n"
495 " print a tree with no omissions. The \"deps\", \"public_deps\", and\n"
496 " \"data_deps\" will all be included.\n"
497 "\n" 492 "\n"
498 " public_configs\n" 493 " public_configs\n"
499 " all_dependent_configs\n" 494 " all_dependent_configs\n"
500 " Shows the labels of configs applied to targets that depend on this\n" 495 " Shows the labels of configs applied to targets that depend on this\n"
501 " one (either directly or all of them).\n" 496 " one (either directly or all of them).\n"
502 "\n" 497 "\n"
503 " forward_dependent_configs_from\n" 498 " forward_dependent_configs_from\n"
504 " Shows the labels of dependencies for which dependent configs will\n" 499 " Shows the labels of dependencies for which dependent configs will\n"
505 " be pushed to targets depending on the current one.\n" 500 " be pushed to targets depending on the current one.\n"
506 "\n" 501 "\n"
(...skipping 15 matching lines...) Expand all
522 " libs\n" 517 " libs\n"
523 " Shows the given values taken from the target and all configs\n" 518 " Shows the given values taken from the target and all configs\n"
524 " applying. See \"--blame\" below.\n" 519 " applying. See \"--blame\" below.\n"
525 "\n" 520 "\n"
526 " --blame\n" 521 " --blame\n"
527 " Used with any value specified by a config, this will name\n" 522 " Used with any value specified by a config, this will name\n"
528 " the config that specified the value. This doesn't currently work\n" 523 " the config that specified the value. This doesn't currently work\n"
529 " for libs and lib_dirs because those are inherited and are more\n" 524 " for libs and lib_dirs because those are inherited and are more\n"
530 " complicated to figure out the blame (patches welcome).\n" 525 " complicated to figure out the blame (patches welcome).\n"
531 "\n" 526 "\n"
532 "Note:\n" 527 "Flags that control how deps are printed\n"
528 "\n"
529 " --all\n"
530 " Collects all recursive dependencies and prints a sorted flat list.\n"
531 " Also usable with --tree (see below).\n"
532 "\n"
533 TARGET_PRINTING_MODE_COMMAND_LINE_HELP
534 "\n"
535 TARGET_TESTONLY_FILTER_COMMAND_LINE_HELP
536 "\n"
537 " --tree\n"
538 " Print a dependency tree. By default, duplicates will be elided\n"
539 " with \"...\" but when --all and -tree are used together, no\n"
540 " eliding will be performed.\n"
541 "\n"
542 " The \"deps\", \"public_deps\", and \"data_deps\" will all be\n"
543 " included in the tree.\n"
544 "\n"
545 " Tree output can not be used with the filtering or output flags:\n"
546 " --as, --type, --testonly.\n"
547 "\n"
548 TARGET_TYPE_FILTER_COMMAND_LINE_HELP
549 "\n"
550 "Note\n"
551 "\n"
533 " This command will show the full name of directories and source files,\n" 552 " This command will show the full name of directories and source files,\n"
534 " but when directories and source paths are written to the build file,\n" 553 " but when directories and source paths are written to the build file,\n"
535 " they will be adjusted to be relative to the build directory. So the\n" 554 " they will be adjusted to be relative to the build directory. So the\n"
536 " values for paths displayed by this command won't match (but should\n" 555 " values for paths displayed by this command won't match (but should\n"
537 " mean the same thing).\n" 556 " mean the same thing).\n"
538 "\n" 557 "\n"
539 "Examples:\n" 558 "Examples\n"
559 "\n"
540 " gn desc out/Debug //base:base\n" 560 " gn desc out/Debug //base:base\n"
541 " Summarizes the given target.\n" 561 " Summarizes the given target.\n"
542 "\n" 562 "\n"
543 " gn desc out/Foo :base_unittests deps --tree\n" 563 " gn desc out/Foo :base_unittests deps --tree\n"
544 " Shows a dependency tree of the \"base_unittests\" project in\n" 564 " Shows a dependency tree of the \"base_unittests\" project in\n"
545 " the current directory.\n" 565 " the current directory.\n"
546 "\n" 566 "\n"
547 " gn desc out/Debug //base defines --blame\n" 567 " gn desc out/Debug //base defines --blame\n"
548 " Shows defines set for the //base:base target, annotated by where\n" 568 " Shows defines set for the //base:base target, annotated by where\n"
549 " each one was set from.\n"; 569 " each one was set from.\n";
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 // so always display them, even for groups and such. 720 // so always display them, even for groups and such.
701 PrintLibs(target, true); 721 PrintLibs(target, true);
702 PrintLibDirs(target, true); 722 PrintLibDirs(target, true);
703 723
704 PrintDeps(target, true); 724 PrintDeps(target, true);
705 725
706 return 0; 726 return 0;
707 } 727 }
708 728
709 } // namespace commands 729 } // namespace commands
OLDNEW
« no previous file with comments | « tools/gn/command_check.cc ('k') | tools/gn/command_ls.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698