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" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 const Label& default_toolchain, | 62 const Label& default_toolchain, |
63 int indent_level) { | 63 int indent_level) { |
64 LabelTargetVector sorted_deps = target->deps(); | 64 LabelTargetVector sorted_deps = target->deps(); |
65 const LabelTargetVector& datadeps = target->datadeps(); | 65 const LabelTargetVector& datadeps = target->datadeps(); |
66 sorted_deps.insert(sorted_deps.end(), datadeps.begin(), datadeps.end()); | 66 sorted_deps.insert(sorted_deps.end(), datadeps.begin(), datadeps.end()); |
67 std::sort(sorted_deps.begin(), sorted_deps.end(), | 67 std::sort(sorted_deps.begin(), sorted_deps.end(), |
68 LabelPtrLabelLess<Target>()); | 68 LabelPtrLabelLess<Target>()); |
69 | 69 |
70 std::string indent(indent_level * 2, ' '); | 70 std::string indent(indent_level * 2, ' '); |
71 for (size_t i = 0; i < sorted_deps.size(); i++) { | 71 for (size_t i = 0; i < sorted_deps.size(); i++) { |
| 72 // Don't print groups. Groups are flattened such that the deps of the |
| 73 // group are added directly to the target that depended on the group. |
| 74 // Printing and recursing into groups here will cause such targets to be |
| 75 // duplicated. |
| 76 // |
| 77 // It would be much more intuitive to do the opposite and not display the |
| 78 // deps that were copied from the group to the target and instead display |
| 79 // the group, but the source of those dependencies is not tracked. |
| 80 if (sorted_deps[i].ptr->output_type() == Target::GROUP) |
| 81 continue; |
| 82 |
72 OutputString(indent + | 83 OutputString(indent + |
73 sorted_deps[i].label.GetUserVisibleName(default_toolchain) + "\n"); | 84 sorted_deps[i].label.GetUserVisibleName(default_toolchain) + "\n"); |
74 RecursivePrintDeps(sorted_deps[i].ptr, default_toolchain, indent_level + 1); | 85 RecursivePrintDeps(sorted_deps[i].ptr, default_toolchain, indent_level + 1); |
75 } | 86 } |
76 } | 87 } |
77 | 88 |
78 void PrintDeps(const Target* target, bool display_header) { | 89 void PrintDeps(const Target* target, bool display_header) { |
79 const CommandLine* cmdline = CommandLine::ForCurrentProcess(); | 90 const CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
80 Label toolchain_label = target->label().GetToolchainLabel(); | 91 Label toolchain_label = target->label().GetToolchainLabel(); |
81 | 92 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 if (libs.empty()) | 149 if (libs.empty()) |
139 return; | 150 return; |
140 | 151 |
141 if (display_header) | 152 if (display_header) |
142 OutputString("\nlibs\n"); | 153 OutputString("\nlibs\n"); |
143 | 154 |
144 for (size_t i = 0; i < libs.size(); i++) | 155 for (size_t i = 0; i < libs.size(); i++) |
145 OutputString(" " + libs[i] + "\n"); | 156 OutputString(" " + libs[i] + "\n"); |
146 } | 157 } |
147 | 158 |
| 159 void PrintPublic(const Target* target, bool display_header) { |
| 160 if (display_header) |
| 161 OutputString("\npublic\n"); |
| 162 |
| 163 if (target->all_headers_public()) { |
| 164 OutputString(" [All headers listed in the sources are public.]\n"); |
| 165 return; |
| 166 } |
| 167 |
| 168 Target::FileList public_headers = target->public_headers(); |
| 169 std::sort(public_headers.begin(), public_headers.end()); |
| 170 for (size_t i = 0; i < public_headers.size(); i++) |
| 171 OutputString(" " + public_headers[i].value() + "\n"); |
| 172 } |
| 173 |
| 174 void PrintVisibility(const Target* target, bool display_header) { |
| 175 if (display_header) |
| 176 OutputString("\nvisibility\n"); |
| 177 |
| 178 OutputString(target->visibility().Describe(2, false)); |
| 179 } |
| 180 |
148 void PrintConfigs(const Target* target, bool display_header) { | 181 void PrintConfigs(const Target* target, bool display_header) { |
149 // Configs (don't sort since the order determines how things are processed). | 182 // Configs (don't sort since the order determines how things are processed). |
150 if (display_header) | 183 if (display_header) |
151 OutputString("\nConfigs (in order applying):\n"); | 184 OutputString("\nConfigs (in order applying):\n"); |
152 | 185 |
153 Label toolchain_label = target->label().GetToolchainLabel(); | 186 Label toolchain_label = target->label().GetToolchainLabel(); |
154 const LabelConfigVector& configs = target->configs(); | 187 const LabelConfigVector& configs = target->configs(); |
155 for (size_t i = 0; i < configs.size(); i++) { | 188 for (size_t i = 0; i < configs.size(); i++) { |
156 OutputString(" " + | 189 OutputString(" " + |
157 configs[i].label.GetUserVisibleName(toolchain_label) + "\n"); | 190 configs[i].label.GetUserVisibleName(toolchain_label) + "\n"); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 const char kDesc_Help[] = | 273 const char kDesc_Help[] = |
241 "gn desc <target label> [<what to show>] [--blame] [--all | --tree]\n" | 274 "gn desc <target label> [<what to show>] [--blame] [--all | --tree]\n" |
242 " Displays information about a given labeled target.\n" | 275 " Displays information about a given labeled target.\n" |
243 "\n" | 276 "\n" |
244 "Possibilities for <what to show>:\n" | 277 "Possibilities for <what to show>:\n" |
245 " (If unspecified an overall summary will be displayed.)\n" | 278 " (If unspecified an overall summary will be displayed.)\n" |
246 "\n" | 279 "\n" |
247 " sources\n" | 280 " sources\n" |
248 " Source files.\n" | 281 " Source files.\n" |
249 "\n" | 282 "\n" |
| 283 " public\n" |
| 284 " Public header files.\n" |
| 285 "\n" |
| 286 " visibility\n" |
| 287 " Prints which targets can depend on this one.\n" |
| 288 "\n" |
250 " configs\n" | 289 " configs\n" |
251 " Shows configs applied to the given target, sorted in the order\n" | 290 " Shows configs applied to the given target, sorted in the order\n" |
252 " they're specified. This includes both configs specified in the\n" | 291 " they're specified. This includes both configs specified in the\n" |
253 " \"configs\" variable, as well as configs pushed onto this target\n" | 292 " \"configs\" variable, as well as configs pushed onto this target\n" |
254 " via dependencies specifying \"all\" or \"direct\" dependent\n" | 293 " via dependencies specifying \"all\" or \"direct\" dependent\n" |
255 " configs.\n" | 294 " configs.\n" |
256 "\n" | 295 "\n" |
257 " deps [--all | --tree]\n" | 296 " deps [--all | --tree]\n" |
258 " Show immediate (or, when \"--all\" or \"--tree\" is specified,\n" | 297 " Show immediate (or, when \"--all\" or \"--tree\" is specified,\n" |
259 " recursive) dependencies of the given target. \"--tree\" shows them\n" | 298 " recursive) dependencies of the given target. \"--tree\" shows them\n" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 #define CONFIG_VALUE_HANDLER(name, type) \ | 352 #define CONFIG_VALUE_HANDLER(name, type) \ |
314 } else if (what == #name) { OUTPUT_CONFIG_VALUE(name, type) | 353 } else if (what == #name) { OUTPUT_CONFIG_VALUE(name, type) |
315 | 354 |
316 if (args.size() == 2) { | 355 if (args.size() == 2) { |
317 // User specified one thing to display. | 356 // User specified one thing to display. |
318 const std::string& what = args[1]; | 357 const std::string& what = args[1]; |
319 if (what == "configs") { | 358 if (what == "configs") { |
320 PrintConfigs(target, false); | 359 PrintConfigs(target, false); |
321 } else if (what == "sources") { | 360 } else if (what == "sources") { |
322 PrintSources(target, false); | 361 PrintSources(target, false); |
| 362 } else if (what == "public") { |
| 363 PrintPublic(target, false); |
| 364 } else if (what == "visibility") { |
| 365 PrintVisibility(target, false); |
323 } else if (what == "deps") { | 366 } else if (what == "deps") { |
324 PrintDeps(target, false); | 367 PrintDeps(target, false); |
325 } else if (what == "lib_dirs") { | 368 } else if (what == "lib_dirs") { |
326 PrintLibDirs(target, false); | 369 PrintLibDirs(target, false); |
327 } else if (what == "libs") { | 370 } else if (what == "libs") { |
328 PrintLibs(target, false); | 371 PrintLibs(target, false); |
329 | 372 |
330 CONFIG_VALUE_HANDLER(defines, std::string) | 373 CONFIG_VALUE_HANDLER(defines, std::string) |
331 CONFIG_VALUE_HANDLER(include_dirs, SourceDir) | 374 CONFIG_VALUE_HANDLER(include_dirs, SourceDir) |
332 CONFIG_VALUE_HANDLER(cflags, std::string) | 375 CONFIG_VALUE_HANDLER(cflags, std::string) |
(...skipping 22 matching lines...) Expand all Loading... |
355 // Header. | 398 // Header. |
356 OutputString("Target: ", DECORATION_YELLOW); | 399 OutputString("Target: ", DECORATION_YELLOW); |
357 OutputString(target->label().GetUserVisibleName(false) + "\n"); | 400 OutputString(target->label().GetUserVisibleName(false) + "\n"); |
358 OutputString("Type: ", DECORATION_YELLOW); | 401 OutputString("Type: ", DECORATION_YELLOW); |
359 OutputString(std::string( | 402 OutputString(std::string( |
360 Target::GetStringForOutputType(target->output_type())) + "\n"); | 403 Target::GetStringForOutputType(target->output_type())) + "\n"); |
361 OutputString("Toolchain: ", DECORATION_YELLOW); | 404 OutputString("Toolchain: ", DECORATION_YELLOW); |
362 OutputString(target_toolchain.GetUserVisibleName(false) + "\n"); | 405 OutputString(target_toolchain.GetUserVisibleName(false) + "\n"); |
363 | 406 |
364 PrintSources(target, true); | 407 PrintSources(target, true); |
| 408 PrintPublic(target, true); |
| 409 PrintVisibility(target, true); |
365 PrintConfigs(target, true); | 410 PrintConfigs(target, true); |
366 | 411 |
367 OUTPUT_CONFIG_VALUE(defines, std::string) | 412 OUTPUT_CONFIG_VALUE(defines, std::string) |
368 OUTPUT_CONFIG_VALUE(include_dirs, SourceDir) | 413 OUTPUT_CONFIG_VALUE(include_dirs, SourceDir) |
369 OUTPUT_CONFIG_VALUE(cflags, std::string) | 414 OUTPUT_CONFIG_VALUE(cflags, std::string) |
370 OUTPUT_CONFIG_VALUE(cflags_c, std::string) | 415 OUTPUT_CONFIG_VALUE(cflags_c, std::string) |
371 OUTPUT_CONFIG_VALUE(cflags_cc, std::string) | 416 OUTPUT_CONFIG_VALUE(cflags_cc, std::string) |
372 OUTPUT_CONFIG_VALUE(cflags_objc, std::string) | 417 OUTPUT_CONFIG_VALUE(cflags_objc, std::string) |
373 OUTPUT_CONFIG_VALUE(cflags_objcc, std::string) | 418 OUTPUT_CONFIG_VALUE(cflags_objcc, std::string) |
374 OUTPUT_CONFIG_VALUE(ldflags, std::string) | 419 OUTPUT_CONFIG_VALUE(ldflags, std::string) |
375 PrintLibs(target, true); | 420 PrintLibs(target, true); |
376 PrintLibDirs(target, true); | 421 PrintLibDirs(target, true); |
377 | 422 |
378 PrintDeps(target, true); | 423 PrintDeps(target, true); |
379 | 424 |
380 return 0; | 425 return 0; |
381 } | 426 } |
382 | 427 |
383 } // namespace commands | 428 } // namespace commands |
OLD | NEW |