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" |
11 #include "tools/gn/config.h" | 11 #include "tools/gn/config.h" |
12 #include "tools/gn/config_values_extractors.h" | 12 #include "tools/gn/config_values_extractors.h" |
13 #include "tools/gn/deps_iterator.h" | 13 #include "tools/gn/deps_iterator.h" |
14 #include "tools/gn/filesystem_utils.h" | 14 #include "tools/gn/filesystem_utils.h" |
15 #include "tools/gn/item.h" | 15 #include "tools/gn/item.h" |
16 #include "tools/gn/label.h" | 16 #include "tools/gn/label.h" |
17 #include "tools/gn/runtime_deps.h" | 17 #include "tools/gn/runtime_deps.h" |
18 #include "tools/gn/setup.h" | 18 #include "tools/gn/setup.h" |
19 #include "tools/gn/standard_out.h" | 19 #include "tools/gn/standard_out.h" |
20 #include "tools/gn/substitution_writer.h" | 20 #include "tools/gn/substitution_writer.h" |
21 #include "tools/gn/target.h" | 21 #include "tools/gn/target.h" |
22 #include "tools/gn/variables.h" | 22 #include "tools/gn/variables.h" |
23 | 23 |
24 namespace commands { | 24 namespace commands { |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 // The switch for displaying blame. | 28 // Desc-specific command line switches. |
29 const char kBlame[] = "blame"; | 29 const char kBlame[] = "blame"; |
| 30 const char kTree[] = "tree"; |
30 | 31 |
31 // Prints the given directory in a nice way for the user to view. | 32 // Prints the given directory in a nice way for the user to view. |
32 std::string FormatSourceDir(const SourceDir& dir) { | 33 std::string FormatSourceDir(const SourceDir& dir) { |
33 #if defined(OS_WIN) | 34 #if defined(OS_WIN) |
34 // On Windows we fix up system absolute paths to look like native ones. | 35 // On Windows we fix up system absolute paths to look like native ones. |
35 // Internally, they'll look like "/C:\foo\bar/" | 36 // Internally, they'll look like "/C:\foo\bar/" |
36 if (dir.is_system_absolute()) { | 37 if (dir.is_system_absolute()) { |
37 std::string buf = dir.value(); | 38 std::string buf = dir.value(); |
38 if (buf.size() > 3 && buf[2] == ':') { | 39 if (buf.size() > 3 && buf[2] == ':') { |
39 buf.erase(buf.begin()); // Erase beginning slash. | 40 buf.erase(buf.begin()); // Erase beginning slash. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 indent_level + 1); | 107 indent_level + 1); |
107 } | 108 } |
108 } | 109 } |
109 } | 110 } |
110 | 111 |
111 void PrintDeps(const Target* target, bool display_header) { | 112 void PrintDeps(const Target* target, bool display_header) { |
112 const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); | 113 const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); |
113 Label toolchain_label = target->label().GetToolchainLabel(); | 114 Label toolchain_label = target->label().GetToolchainLabel(); |
114 | 115 |
115 // Tree mode is separate. | 116 // Tree mode is separate. |
116 if (cmdline->HasSwitch("tree")) { | 117 if (cmdline->HasSwitch(kTree)) { |
117 if (display_header) | 118 if (display_header) |
118 OutputString("\nDependency tree:\n"); | 119 OutputString("\nDependency tree:\n"); |
119 | 120 |
120 if (cmdline->HasSwitch("all")) { | 121 if (cmdline->HasSwitch("all")) { |
121 // Show all tree deps with no eliding. | 122 // Show all tree deps with no eliding. |
122 RecursivePrintDeps(target, toolchain_label, nullptr, 1); | 123 RecursivePrintDeps(target, toolchain_label, nullptr, 1); |
123 } else { | 124 } else { |
124 // Don't recurse into duplicates. | 125 // Don't recurse into duplicates. |
125 std::set<const Target*> seen_targets; | 126 std::set<const Target*> seen_targets; |
126 RecursivePrintDeps(target, toolchain_label, &seen_targets, 1); | 127 RecursivePrintDeps(target, toolchain_label, &seen_targets, 1); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 void PrintTestonly(const Target* target, bool display_header) { | 243 void PrintTestonly(const Target* target, bool display_header) { |
243 if (display_header) | 244 if (display_header) |
244 OutputString("\ntestonly:\n"); | 245 OutputString("\ntestonly:\n"); |
245 | 246 |
246 if (target->testonly()) | 247 if (target->testonly()) |
247 OutputString(" true\n"); | 248 OutputString(" true\n"); |
248 else | 249 else |
249 OutputString(" false\n"); | 250 OutputString(" false\n"); |
250 } | 251 } |
251 | 252 |
| 253 // Recursively prints subconfigs of a config. |
| 254 void PrintSubConfigs(const Config* config, int indent_level) { |
| 255 if (config->configs().empty()) |
| 256 return; |
| 257 |
| 258 std::string indent(indent_level * 2, ' '); |
| 259 Label toolchain_label = config->label().GetToolchainLabel(); |
| 260 for (const auto& pair : config->configs()) { |
| 261 OutputString( |
| 262 indent + pair.label.GetUserVisibleName(toolchain_label) + "\n"); |
| 263 PrintSubConfigs(pair.ptr, indent_level + 1); |
| 264 } |
| 265 } |
| 266 |
| 267 // This allows configs stored as either std::vector<LabelConfigPair> or |
| 268 // UniqueVector<LabelConfigPair> to be printed. |
| 269 template <class VectorType> |
252 void PrintConfigsVector(const Target* target, | 270 void PrintConfigsVector(const Target* target, |
253 const LabelConfigVector& configs, | 271 const VectorType& configs, |
254 const std::string& heading, | 272 const std::string& heading, |
255 bool display_header) { | 273 bool display_header) { |
256 if (configs.empty()) | 274 if (configs.empty()) |
257 return; | 275 return; |
258 | 276 |
| 277 bool tree = base::CommandLine::ForCurrentProcess()->HasSwitch(kTree); |
| 278 |
259 // Don't sort since the order determines how things are processed. | 279 // Don't sort since the order determines how things are processed. |
260 if (display_header) | 280 if (display_header) { |
261 OutputString("\n" + heading + " (in order applying):\n"); | 281 if (tree) |
| 282 OutputString("\n" + heading + " tree (in order applying):\n"); |
| 283 else |
| 284 OutputString("\n" + heading + " (in order applying, try also --tree):\n"); |
| 285 } |
262 | 286 |
263 Label toolchain_label = target->label().GetToolchainLabel(); | 287 Label toolchain_label = target->label().GetToolchainLabel(); |
264 for (const auto& config : configs) { | 288 for (const auto& config : configs) { |
265 OutputString(" " + config.label.GetUserVisibleName(toolchain_label) + | 289 OutputString(" " + config.label.GetUserVisibleName(toolchain_label) + |
266 "\n"); | 290 "\n"); |
| 291 if (tree) |
| 292 PrintSubConfigs(config.ptr, 2); // 2 = start with double-indent. |
267 } | 293 } |
268 } | 294 } |
269 | 295 |
270 void PrintConfigsVector(const Target* target, | |
271 const UniqueVector<LabelConfigPair>& configs, | |
272 const std::string& heading, | |
273 bool display_header) { | |
274 if (configs.empty()) | |
275 return; | |
276 | |
277 // Don't sort since the order determines how things are processed. | |
278 if (display_header) | |
279 OutputString("\n" + heading + " (in order applying):\n"); | |
280 | |
281 Label toolchain_label = target->label().GetToolchainLabel(); | |
282 for (const auto& config : configs) { | |
283 OutputString(" " + config.label.GetUserVisibleName(toolchain_label) + | |
284 "\n"); | |
285 } | |
286 } | |
287 | |
288 void PrintConfigs(const Target* target, bool display_header) { | 296 void PrintConfigs(const Target* target, bool display_header) { |
289 PrintConfigsVector(target, target->configs().vector(), "configs", | 297 PrintConfigsVector(target, target->configs().vector(), "configs", |
290 display_header); | 298 display_header); |
291 } | 299 } |
292 | 300 |
293 void PrintPublicConfigs(const Target* target, bool display_header) { | 301 void PrintPublicConfigs(const Target* target, bool display_header) { |
294 PrintConfigsVector(target, target->public_configs(), | 302 PrintConfigsVector(target, target->public_configs(), |
295 "public_configs", display_header); | 303 "public_configs", display_header); |
296 } | 304 } |
297 | 305 |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 // so always display them, even for groups and such. | 767 // so always display them, even for groups and such. |
760 PrintLibs(target, true); | 768 PrintLibs(target, true); |
761 PrintLibDirs(target, true); | 769 PrintLibDirs(target, true); |
762 | 770 |
763 PrintDeps(target, true); | 771 PrintDeps(target, true); |
764 | 772 |
765 return 0; | 773 return 0; |
766 } | 774 } |
767 | 775 |
768 } // namespace commands | 776 } // namespace commands |
OLD | NEW |