Commit c1e5ca86 authored by brettw@chromium.org's avatar brettw@chromium.org

Minor improvements to GN's "desc" output.

Adds the public headers and visibility to the desc command.

Improve formatting of visibility printing.

Don't duplicate group deps in the tree output of "desc"

R=scottmg@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274324 0039d316-1c4b-4281-b951-d872f2087c98
parent dc9066e0
...@@ -69,6 +69,17 @@ void RecursivePrintDeps(const Target* target, ...@@ -69,6 +69,17 @@ 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++) {
// 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.
// Printing and recursing into groups here will cause such targets to be
// duplicated.
//
// 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
// the group, but the source of those dependencies is not tracked.
if (sorted_deps[i].ptr->output_type() == Target::GROUP)
continue;
OutputString(indent + OutputString(indent +
sorted_deps[i].label.GetUserVisibleName(default_toolchain) + "\n"); sorted_deps[i].label.GetUserVisibleName(default_toolchain) + "\n");
RecursivePrintDeps(sorted_deps[i].ptr, default_toolchain, indent_level + 1); RecursivePrintDeps(sorted_deps[i].ptr, default_toolchain, indent_level + 1);
...@@ -145,6 +156,28 @@ void PrintLibs(const Target* target, bool display_header) { ...@@ -145,6 +156,28 @@ void PrintLibs(const Target* target, bool display_header) {
OutputString(" " + libs[i] + "\n"); OutputString(" " + libs[i] + "\n");
} }
void PrintPublic(const Target* target, bool display_header) {
if (display_header)
OutputString("\npublic\n");
if (target->all_headers_public()) {
OutputString(" [All headers listed in the sources are public.]\n");
return;
}
Target::FileList public_headers = target->public_headers();
std::sort(public_headers.begin(), public_headers.end());
for (size_t i = 0; i < public_headers.size(); i++)
OutputString(" " + public_headers[i].value() + "\n");
}
void PrintVisibility(const Target* target, bool display_header) {
if (display_header)
OutputString("\nvisibility\n");
OutputString(target->visibility().Describe(2, false));
}
void PrintConfigs(const Target* target, bool display_header) { void PrintConfigs(const Target* target, bool display_header) {
// Configs (don't sort since the order determines how things are processed). // Configs (don't sort since the order determines how things are processed).
if (display_header) if (display_header)
...@@ -247,6 +280,12 @@ const char kDesc_Help[] = ...@@ -247,6 +280,12 @@ const char kDesc_Help[] =
" sources\n" " sources\n"
" Source files.\n" " Source files.\n"
"\n" "\n"
" public\n"
" Public header files.\n"
"\n"
" visibility\n"
" Prints which targets can depend on this one.\n"
"\n"
" configs\n" " configs\n"
" Shows configs applied to the given target, sorted in the order\n" " Shows configs applied to the given target, sorted in the order\n"
" they're specified. This includes both configs specified in the\n" " they're specified. This includes both configs specified in the\n"
...@@ -320,6 +359,10 @@ int RunDesc(const std::vector<std::string>& args) { ...@@ -320,6 +359,10 @@ int RunDesc(const std::vector<std::string>& args) {
PrintConfigs(target, false); PrintConfigs(target, false);
} else if (what == "sources") { } else if (what == "sources") {
PrintSources(target, false); PrintSources(target, false);
} else if (what == "public") {
PrintPublic(target, false);
} else if (what == "visibility") {
PrintVisibility(target, false);
} else if (what == "deps") { } else if (what == "deps") {
PrintDeps(target, false); PrintDeps(target, false);
} else if (what == "lib_dirs") { } else if (what == "lib_dirs") {
...@@ -362,6 +405,8 @@ int RunDesc(const std::vector<std::string>& args) { ...@@ -362,6 +405,8 @@ int RunDesc(const std::vector<std::string>& args) {
OutputString(target_toolchain.GetUserVisibleName(false) + "\n"); OutputString(target_toolchain.GetUserVisibleName(false) + "\n");
PrintSources(target, true); PrintSources(target, true);
PrintPublic(target, true);
PrintVisibility(target, true);
PrintConfigs(target, true); PrintConfigs(target, true);
OUTPUT_CONFIG_VALUE(defines, std::string) OUTPUT_CONFIG_VALUE(defines, std::string)
......
...@@ -97,28 +97,40 @@ bool Visibility::CanSeeMe(const Label& label) const { ...@@ -97,28 +97,40 @@ bool Visibility::CanSeeMe(const Label& label) const {
return false; return false;
} }
std::string Visibility::Describe() const { std::string Visibility::Describe(int indent, bool include_brackets) const {
std::string outer_indent_string(indent, ' ');
if (patterns_.empty()) if (patterns_.empty())
return std::string("[] (no visibility)"); return outer_indent_string + "[] (no visibility)\n";
std::string result = "[\n";
std::string result;
std::string inner_indent_string = outer_indent_string;
if (include_brackets) {
result += outer_indent_string + "[\n";
// Indent the insides more if brackets are requested.
inner_indent_string += " ";
}
for (size_t i = 0; i < patterns_.size(); i++) { for (size_t i = 0; i < patterns_.size(); i++) {
switch (patterns_[i].type()) { switch (patterns_[i].type()) {
case VisPattern::MATCH: case VisPattern::MATCH:
result += " " + patterns_[i].dir().value() + ":" + result += inner_indent_string +
DirectoryWithNoLastSlash(patterns_[i].dir()) + ":" +
patterns_[i].name() + "\n"; patterns_[i].name() + "\n";
break; break;
case VisPattern::DIRECTORY: case VisPattern::DIRECTORY:
result += " " + DirectoryWithNoLastSlash(patterns_[i].dir()) + result += inner_indent_string +
":*\n"; DirectoryWithNoLastSlash(patterns_[i].dir()) + ":*\n";
break; break;
case VisPattern::RECURSIVE_DIRECTORY: case VisPattern::RECURSIVE_DIRECTORY:
result += " " + patterns_[i].dir().value() + "*\n"; result += inner_indent_string + patterns_[i].dir().value() + "*\n";
break; break;
} }
} }
result += "]"; if (include_brackets)
result += outer_indent_string + "]\n";
return result; return result;
} }
...@@ -244,7 +256,7 @@ bool Visibility::CheckItemVisibility(const Item* from, ...@@ -244,7 +256,7 @@ bool Visibility::CheckItemVisibility(const Item* from,
"The item " + from->label().GetUserVisibleName(false) + "\n" "The item " + from->label().GetUserVisibleName(false) + "\n"
"can not depend on " + to_label + "\n" "can not depend on " + to_label + "\n"
"because it is not in " + to_label + "'s visibility list: " + "because it is not in " + to_label + "'s visibility list: " +
to->visibility().Describe()); to->visibility().Describe(0, true));
return false; return false;
} }
return true; return true;
......
...@@ -68,8 +68,11 @@ class Visibility { ...@@ -68,8 +68,11 @@ class Visibility {
// current visibility. // current visibility.
bool CanSeeMe(const Label& label) const; bool CanSeeMe(const Label& label) const;
// Returns a string listing the visibility. // Returns a string listing the visibility. |indent| number of spaces will
std::string Describe() const; // be added on the left side of the output. If |include_brackets| is set, the
// result will be wrapped in "[ ]" and the contents further indented. The
// result will end in a newline.
std::string Describe(int indent, bool include_brackets) const;
// Converts the given input string to a pattern. This does special stuff // Converts the given input string to a pattern. This does special stuff
// to treat the pattern as a label. Sets the error on failure. // to treat the pattern as a label. Sets the error on failure.
......
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