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

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

Issue 22290010: Add support for data deps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clarify deps documentation. Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « tools/gn/BUILD.gn ('k') | tools/gn/command_gen.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"
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/item.h" 13 #include "tools/gn/item.h"
14 #include "tools/gn/item_node.h" 14 #include "tools/gn/item_node.h"
15 #include "tools/gn/label.h" 15 #include "tools/gn/label.h"
16 #include "tools/gn/setup.h" 16 #include "tools/gn/setup.h"
17 #include "tools/gn/standard_out.h" 17 #include "tools/gn/standard_out.h"
18 #include "tools/gn/target.h" 18 #include "tools/gn/target.h"
19 19
20 namespace commands { 20 namespace commands {
21 21
22 namespace { 22 namespace {
23 23
24 const char kIncludeDataDeps[] = "include-datadeps";
25
24 struct CompareTargetLabel { 26 struct CompareTargetLabel {
25 bool operator()(const Target* a, const Target* b) const { 27 bool operator()(const Target* a, const Target* b) const {
26 return a->label() < b->label(); 28 return a->label() < b->label();
27 } 29 }
28 }; 30 };
29 31
30 void RecursiveCollectDeps(const Target* target, std::set<Label>* result) { 32 void RecursiveCollectDeps(const Target* target, std::set<Label>* result) {
31 if (result->find(target->label()) != result->end()) 33 if (result->find(target->label()) != result->end())
32 return; // Already did this target. 34 return; // Already did this target.
33 result->insert(target->label()); 35 result->insert(target->label());
34 36
35 const std::vector<const Target*>& deps = target->deps(); 37 const std::vector<const Target*>& deps = target->deps();
36 for (size_t i = 0; i < deps.size(); i++) 38 for (size_t i = 0; i < deps.size(); i++)
37 RecursiveCollectDeps(deps[i], result); 39 RecursiveCollectDeps(deps[i], result);
40
41 if (CommandLine::ForCurrentProcess()->HasSwitch(kIncludeDataDeps)) {
42 const std::vector<const Target*>& datadeps = target->datadeps();
43 for (size_t i = 0; i < datadeps.size(); i++)
44 RecursiveCollectDeps(datadeps[i], result);
45 }
38 } 46 }
39 47
40 // Prints dependencies of the given target (not the target itself). 48 // Prints dependencies of the given target (not the target itself).
41 void RecursivePrintDeps(const Target* target, 49 void RecursivePrintDeps(const Target* target,
42 const Label& default_toolchain, 50 const Label& default_toolchain,
43 int indent_level) { 51 int indent_level) {
44 std::vector<const Target*> sorted_deps = target->deps(); 52 std::vector<const Target*> sorted_deps = target->deps();
53 if (CommandLine::ForCurrentProcess()->HasSwitch(kIncludeDataDeps)) {
54 const std::vector<const Target*> datadeps = target->datadeps();
55 for (size_t i = 0; i < datadeps.size(); i++)
56 sorted_deps.push_back(datadeps[i]);
57 }
58
45 std::sort(sorted_deps.begin(), sorted_deps.end(), CompareTargetLabel()); 59 std::sort(sorted_deps.begin(), sorted_deps.end(), CompareTargetLabel());
46 60
47 std::string indent(indent_level * 2, ' '); 61 std::string indent(indent_level * 2, ' ');
48 for (size_t i = 0; i < sorted_deps.size(); i++) { 62 for (size_t i = 0; i < sorted_deps.size(); i++) {
49 OutputString(indent + 63 OutputString(indent +
50 sorted_deps[i]->label().GetUserVisibleName(default_toolchain) + "\n"); 64 sorted_deps[i]->label().GetUserVisibleName(default_toolchain) + "\n");
51 RecursivePrintDeps(sorted_deps[i], default_toolchain, indent_level + 1); 65 RecursivePrintDeps(sorted_deps[i], default_toolchain, indent_level + 1);
52 } 66 }
53 } 67 }
54 68
55 void PrintDeps(const Target* target, bool display_header) { 69 void PrintDeps(const Target* target, bool display_header) {
70 const CommandLine* cmdline = CommandLine::ForCurrentProcess();
56 Label toolchain_label = target->label().GetToolchainLabel(); 71 Label toolchain_label = target->label().GetToolchainLabel();
57 72
58 // Tree mode is separate. 73 // Tree mode is separate.
59 if (CommandLine::ForCurrentProcess()->HasSwitch("tree")) { 74 if (cmdline->HasSwitch("tree")) {
60 if (display_header) 75 if (display_header)
61 OutputString("\nDependency tree:\n"); 76 OutputString("\nDependency tree:\n");
62 RecursivePrintDeps(target, toolchain_label, 1); 77 RecursivePrintDeps(target, toolchain_label, 1);
63 return; 78 return;
64 } 79 }
65 80
66 // Collect the deps to display. 81 // Collect the deps to display.
67 std::vector<Label> deps; 82 std::vector<Label> deps;
68 if (CommandLine::ForCurrentProcess()->HasSwitch("all")) { 83 if (cmdline->HasSwitch("all")) {
69 if (display_header) 84 if (display_header)
70 OutputString("\nAll recursive dependencies:\n"); 85 OutputString("\nAll recursive dependencies:\n");
71 86
72 std::set<Label> all_deps; 87 std::set<Label> all_deps;
73 RecursiveCollectDeps(target, &all_deps); 88 RecursiveCollectDeps(target, &all_deps);
74 for (std::set<Label>::iterator i = all_deps.begin(); 89 for (std::set<Label>::iterator i = all_deps.begin();
75 i != all_deps.end(); ++i) 90 i != all_deps.end(); ++i)
76 deps.push_back(*i); 91 deps.push_back(*i);
77 } else { 92 } else {
78 if (display_header) { 93 if (display_header) {
79 OutputString("\nDirect dependencies " 94 OutputString("\nDirect dependencies "
80 "(try also \"--all\" and \"--tree\"):\n"); 95 "(try also \"--all\" and \"--tree\"):\n");
81 } 96 }
82 97
83 const std::vector<const Target*>& target_deps = target->deps(); 98 const std::vector<const Target*>& target_deps = target->deps();
84 for (size_t i = 0; i < target_deps.size(); i++) 99 for (size_t i = 0; i < target_deps.size(); i++)
85 deps.push_back(target_deps[i]->label()); 100 deps.push_back(target_deps[i]->label());
101
102 // Optionally include data deps.
103 if (cmdline->HasSwitch(kIncludeDataDeps)) {
scottmg 2013/08/06 20:27:58 i feel like you probably always want to see these,
brettw 2013/08/06 21:10:22 Okay, I removed this and included them all the tim
104 const std::vector<const Target*>& target_datadeps = target->datadeps();
105 for (size_t i = 0; i < target_datadeps.size(); i++)
106 deps.push_back(target_datadeps[i]->label());
107 }
86 } 108 }
87 109
88 std::sort(deps.begin(), deps.end()); 110 std::sort(deps.begin(), deps.end());
89 for (size_t i = 0; i < deps.size(); i++) 111 for (size_t i = 0; i < deps.size(); i++)
90 OutputString(" " + deps[i].GetUserVisibleName(toolchain_label) + "\n"); 112 OutputString(" " + deps[i].GetUserVisibleName(toolchain_label) + "\n");
91 } 113 }
92 114
93 void PrintConfigs(const Target* target, bool display_header) { 115 void PrintConfigs(const Target* target, bool display_header) {
94 // Configs (don't sort since the order determines how things are processed). 116 // Configs (don't sort since the order determines how things are processed).
95 if (display_header) 117 if (display_header)
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 " sources\n" 238 " sources\n"
217 " Source files.\n" 239 " Source files.\n"
218 "\n" 240 "\n"
219 " configs\n" 241 " configs\n"
220 " Shows configs applied to the given target, sorted in the order\n" 242 " Shows configs applied to the given target, sorted in the order\n"
221 " they're specified. This includes both configs specified in the\n" 243 " they're specified. This includes both configs specified in the\n"
222 " \"configs\" variable, as well as configs pushed onto this target\n" 244 " \"configs\" variable, as well as configs pushed onto this target\n"
223 " via dependencies specifying \"all\" or \"direct\" dependent\n" 245 " via dependencies specifying \"all\" or \"direct\" dependent\n"
224 " configs.\n" 246 " configs.\n"
225 "\n" 247 "\n"
226 " deps [--all | --tree]\n" 248 " deps [--all | --tree] [--include-datadeps]\n"
227 " Show immediate (or, when \"--all\" or \"--tree\" is specified,\n" 249 " Show immediate (or, when \"--all\" or \"--tree\" is specified,\n"
228 " recursive) dependencies of the given target. \"--tree\" shows them\n" 250 " recursive) dependencies of the given target. \"--tree\" shows them\n"
229 " in a tree format. Otherwise, they will be sorted alphabetically.\n" 251 " in a tree format. Otherwise, they will be sorted alphabetically.\n"
230 "\n" 252 "\n"
253 " If \"--include-datadeps\" is specified, the datadeps will be shown\n"
254 " mixed in with the regular dependendencies.\n"
255 "\n"
231 " defines [--blame]\n" 256 " defines [--blame]\n"
232 " includes [--blame]\n" 257 " includes [--blame]\n"
233 " cflags [--blame]\n" 258 " cflags [--blame]\n"
234 " cflags_cc [--blame]\n" 259 " cflags_cc [--blame]\n"
235 " cflags_cxx [--blame]\n" 260 " cflags_cxx [--blame]\n"
236 " ldflags [--blame]\n" 261 " ldflags [--blame]\n"
237 " Shows the given values taken from the target and all configs\n" 262 " Shows the given values taken from the target and all configs\n"
238 " applying. See \"--blame\" below.\n" 263 " applying. See \"--blame\" below.\n"
239 "\n" 264 "\n"
240 " --blame\n" 265 " --blame\n"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 PrintConfigs(target, true); 347 PrintConfigs(target, true);
323 OutputString("\n (Use \"gn desc <label> <thing you want to see>\" to show " 348 OutputString("\n (Use \"gn desc <label> <thing you want to see>\" to show "
324 "the actual values\n applied by the different configs. " 349 "the actual values\n applied by the different configs. "
325 "See \"gn help desc\" for more.)\n"); 350 "See \"gn help desc\" for more.)\n");
326 PrintDeps(target, true); 351 PrintDeps(target, true);
327 352
328 return 0; 353 return 0;
329 } 354 }
330 355
331 } // namespace commands 356 } // namespace commands
OLDNEW
« no previous file with comments | « tools/gn/BUILD.gn ('k') | tools/gn/command_gen.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698