Commit 9019e16c authored by brettw@chromium.org's avatar brettw@chromium.org

Elide gn desc --tree output by default.

When gn's desc command is used with --tree, it prints a dependency tree. But recursively printing the dependency tree of a high-level target in Chrome prints too much output to be useful because it's printing, e.g. base and it's deps over and over (//chrome/browser-s --tree is 3210166 lines).

With this patch, a target will be recursed into the first time it's printed, but subsequent times the children will be elided with "..." This brings down //chrome/browser to 2050 lines. The previous behavior is still available (it could be useful in certain cases) via "--tree --all".

This also updates an optimization comment in the the optimization setup (optimize_max isn't just Windows-only).

R=dalecurtis@chromium.org

Review URL: https://codereview.chromium.org/437033002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287424 0039d316-1c4b-4281-b951-d872f2087c98
parent c8fe8387
...@@ -849,9 +849,9 @@ config("no_optimize") { ...@@ -849,9 +849,9 @@ config("no_optimize") {
} }
} }
# On Windows, turns up the optimization level. This implies whole program # Turns up the optimization level. On Windows, this implies whole program
# optimization and link-time code generation which is very expensive and should # optimization and link-time code generation which is very expensive and should
# be used sparingly. For non-Windows, this is the same as "optimize". # be used sparingly.
config("optimize_max") { config("optimize_max") {
cflags = common_optimize_on_cflags cflags = common_optimize_on_cflags
ldflags = common_optimize_on_ldflags ldflags = common_optimize_on_ldflags
......
...@@ -58,9 +58,13 @@ void RecursiveCollectChildDeps(const Target* target, std::set<Label>* result) { ...@@ -58,9 +58,13 @@ void RecursiveCollectChildDeps(const Target* target, std::set<Label>* result) {
RecursiveCollectDeps(datadeps[i].ptr, result); RecursiveCollectDeps(datadeps[i].ptr, result);
} }
// Prints dependencies of the given target (not the target itself). // Prints dependencies of the given target (not the target itself). If the
// set is non-null, new targets encountered will be added to the set, and if
// a dependency is in the set already, it will not be recused into. When the
// set is null, all dependencies will be printed.
void RecursivePrintDeps(const Target* target, void RecursivePrintDeps(const Target* target,
const Label& default_toolchain, const Label& default_toolchain,
std::set<const Target*>* seen_targets,
int indent_level) { int indent_level) {
LabelTargetVector sorted_deps = target->deps(); LabelTargetVector sorted_deps = target->deps();
const LabelTargetVector& datadeps = target->datadeps(); const LabelTargetVector& datadeps = target->datadeps();
...@@ -70,6 +74,8 @@ void RecursivePrintDeps(const Target* target, ...@@ -70,6 +74,8 @@ void RecursivePrintDeps(const Target* target,
std::string indent(indent_level * 2, ' '); std::string indent(indent_level * 2, ' ');
for (size_t i = 0; i < sorted_deps.size(); i++) { for (size_t i = 0; i < sorted_deps.size(); i++) {
const Target* cur_dep = sorted_deps[i].ptr;
// Don't print groups. Groups are flattened such that the deps of the // Don't print groups. Groups are flattened such that the deps of the
// group are added directly to the target that depended on the group. // group are added directly to the target that depended on the group.
// Printing and recursing into groups here will cause such targets to be // Printing and recursing into groups here will cause such targets to be
...@@ -78,12 +84,31 @@ void RecursivePrintDeps(const Target* target, ...@@ -78,12 +84,31 @@ void RecursivePrintDeps(const Target* target,
// It would be much more intuitive to do the opposite and not display the // It would be much more intuitive to do the opposite and not display the
// deps that were copied from the group to the target and instead display // deps that were copied from the group to the target and instead display
// the group, but the source of those dependencies is not tracked. // the group, but the source of those dependencies is not tracked.
if (sorted_deps[i].ptr->output_type() == Target::GROUP) if (cur_dep->output_type() == Target::GROUP)
continue; continue;
OutputString(indent + OutputString(indent +
sorted_deps[i].label.GetUserVisibleName(default_toolchain) + "\n"); cur_dep->label().GetUserVisibleName(default_toolchain));
RecursivePrintDeps(sorted_deps[i].ptr, default_toolchain, indent_level + 1); bool print_children = true;
if (seen_targets) {
if (seen_targets->find(cur_dep) == seen_targets->end()) {
// New target, mark it visited.
seen_targets->insert(cur_dep);
} else {
// Already seen.
print_children = false;
// Only print "..." if something is actually elided, which means that
// the current target has children.
if (!cur_dep->deps().empty() || !cur_dep->datadeps().empty())
OutputString("...");
}
}
OutputString("\n");
if (print_children) {
RecursivePrintDeps(cur_dep, default_toolchain, seen_targets,
indent_level + 1);
}
} }
} }
...@@ -95,7 +120,15 @@ void PrintDeps(const Target* target, bool display_header) { ...@@ -95,7 +120,15 @@ void PrintDeps(const Target* target, bool display_header) {
if (cmdline->HasSwitch("tree")) { if (cmdline->HasSwitch("tree")) {
if (display_header) if (display_header)
OutputString("\nDependency tree:\n"); OutputString("\nDependency tree:\n");
RecursivePrintDeps(target, toolchain_label, 1);
if (cmdline->HasSwitch("all")) {
// Show all tree deps with no eliding.
RecursivePrintDeps(target, toolchain_label, NULL, 1);
} else {
// Don't recurse into duplicates.
std::set<const Target*> seen_targets;
RecursivePrintDeps(target, toolchain_label, &seen_targets, 1);
}
return; return;
} }
...@@ -112,8 +145,9 @@ void PrintDeps(const Target* target, bool display_header) { ...@@ -112,8 +145,9 @@ void PrintDeps(const Target* target, bool display_header) {
deps.push_back(*i); deps.push_back(*i);
} else { } else {
if (display_header) { if (display_header) {
OutputString("\nDirect dependencies " OutputString(
"(try also \"--all\" and \"--tree\"):\n"); "\nDirect dependencies "
"(try also \"--all\", \"--tree\", or even \"--all --tree\"):\n");
} }
const LabelTargetVector& target_deps = target->deps(); const LabelTargetVector& target_deps = target->deps();
...@@ -420,8 +454,10 @@ const char kDesc_Help[] = ...@@ -420,8 +454,10 @@ const char kDesc_Help[] =
" deps [--all | --tree]\n" " deps [--all | --tree]\n"
" Show immediate (or, when \"--all\" or \"--tree\" is specified,\n" " Show immediate (or, when \"--all\" or \"--tree\" is specified,\n"
" recursive) dependencies of the given target. \"--tree\" shows them\n" " recursive) dependencies of the given target. \"--tree\" shows them\n"
" in a tree format. Otherwise, they will be sorted alphabetically.\n" " in a tree format with duplicates elided (noted by \"...\").\n"
" Both \"deps\" and \"datadeps\" will be included.\n" " \"--all\" shows them sorted alphabetically. Using both flags will\n"
" print a tree with no omissions. Both \"deps\" and \"datadeps\"\n"
" will be included.\n"
"\n" "\n"
" direct_dependent_configs\n" " direct_dependent_configs\n"
" all_dependent_configs\n" " all_dependent_configs\n"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment