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

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

Issue 610043002: Convert GN's deps iterator to work with range-based for loops. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
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"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 void RecursiveCollectDeps(const Target* target, std::set<Label>* result) { 45 void RecursiveCollectDeps(const Target* target, std::set<Label>* result) {
46 if (result->find(target->label()) != result->end()) 46 if (result->find(target->label()) != result->end())
47 return; // Already did this target. 47 return; // Already did this target.
48 result->insert(target->label()); 48 result->insert(target->label());
49 49
50 RecursiveCollectChildDeps(target, result); 50 RecursiveCollectChildDeps(target, result);
51 } 51 }
52 52
53 void RecursiveCollectChildDeps(const Target* target, std::set<Label>* result) { 53 void RecursiveCollectChildDeps(const Target* target, std::set<Label>* result) {
54 for (DepsIterator iter(target); !iter.done(); iter.Advance()) 54 for (const auto& pair : target->GetDeps(Target::DEPS_ALL))
55 RecursiveCollectDeps(iter.target(), result); 55 RecursiveCollectDeps(pair.ptr, result);
56 } 56 }
57 57
58 // Prints dependencies of the given target (not the target itself). If the 58 // Prints dependencies of the given target (not the target itself). If the
59 // set is non-null, new targets encountered will be added to the set, and if 59 // set is non-null, new targets encountered will be added to the set, and if
60 // a dependency is in the set already, it will not be recused into. When the 60 // a dependency is in the set already, it will not be recused into. When the
61 // set is null, all dependencies will be printed. 61 // set is null, all dependencies will be printed.
62 void RecursivePrintDeps(const Target* target, 62 void RecursivePrintDeps(const Target* target,
63 const Label& default_toolchain, 63 const Label& default_toolchain,
64 std::set<const Target*>* seen_targets, 64 std::set<const Target*>* seen_targets,
65 int indent_level) { 65 int indent_level) {
66 // Combine all deps into one sorted list. 66 // Combine all deps into one sorted list.
67 std::vector<LabelTargetPair> sorted_deps; 67 std::vector<LabelTargetPair> sorted_deps;
68 for (DepsIterator iter(target); !iter.done(); iter.Advance()) 68 for (const auto& pair : target->GetDeps(Target::DEPS_ALL))
69 sorted_deps.push_back(iter.pair()); 69 sorted_deps.push_back(pair);
70 std::sort(sorted_deps.begin(), sorted_deps.end(), 70 std::sort(sorted_deps.begin(), sorted_deps.end(),
71 LabelPtrLabelLess<Target>()); 71 LabelPtrLabelLess<Target>());
72 72
73 std::string indent(indent_level * 2, ' '); 73 std::string indent(indent_level * 2, ' ');
74 for (size_t i = 0; i < sorted_deps.size(); i++) { 74 for (size_t i = 0; i < sorted_deps.size(); i++) {
75 const Target* cur_dep = sorted_deps[i].ptr; 75 const Target* cur_dep = sorted_deps[i].ptr;
76 76
77 OutputString(indent + 77 OutputString(indent +
78 cur_dep->label().GetUserVisibleName(default_toolchain)); 78 cur_dep->label().GetUserVisibleName(default_toolchain));
79 bool print_children = true; 79 bool print_children = true;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 for (std::set<Label>::iterator i = all_deps.begin(); 133 for (std::set<Label>::iterator i = all_deps.begin();
134 i != all_deps.end(); ++i) 134 i != all_deps.end(); ++i)
135 deps.push_back(*i); 135 deps.push_back(*i);
136 } else { 136 } else {
137 // Show direct dependencies only. 137 // Show direct dependencies only.
138 if (display_header) { 138 if (display_header) {
139 OutputString( 139 OutputString(
140 "\nDirect dependencies " 140 "\nDirect dependencies "
141 "(try also \"--all\", \"--tree\", or even \"--all --tree\"):\n"); 141 "(try also \"--all\", \"--tree\", or even \"--all --tree\"):\n");
142 } 142 }
143 for (DepsIterator iter(target); !iter.done(); iter.Advance()) 143 for (const auto& pair : target->GetDeps(Target::DEPS_ALL))
144 deps.push_back(iter.label()); 144 deps.push_back(pair.label);
145 } 145 }
146 146
147 std::sort(deps.begin(), deps.end()); 147 std::sort(deps.begin(), deps.end());
148 for (size_t i = 0; i < deps.size(); i++) 148 for (size_t i = 0; i < deps.size(); i++)
149 OutputString(" " + deps[i].GetUserVisibleName(toolchain_label) + "\n"); 149 OutputString(" " + deps[i].GetUserVisibleName(toolchain_label) + "\n");
150 } 150 }
151 151
152 void PrintForwardDependentConfigsFrom(const Target* target, 152 void PrintForwardDependentConfigsFrom(const Target* target,
153 bool display_header) { 153 bool display_header) {
154 if (target->forward_dependent_configs().empty()) 154 if (target->forward_dependent_configs().empty())
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 // so always display them, even for groups and such. 702 // so always display them, even for groups and such.
703 PrintLibs(target, true); 703 PrintLibs(target, true);
704 PrintLibDirs(target, true); 704 PrintLibDirs(target, true);
705 705
706 PrintDeps(target, true); 706 PrintDeps(target, true);
707 707
708 return 0; 708 return 0;
709 } 709 }
710 710
711 } // namespace commands 711 } // namespace commands
OLDNEW
« no previous file with comments | « tools/gn/builder.cc ('k') | tools/gn/command_refs.cc » ('j') | tools/gn/command_refs.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698