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

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

Issue 610293003: Replace more for loops in GN (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review 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
« no previous file with comments | « tools/gn/command_args.cc ('k') | tools/gn/command_help.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"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 (const auto& pair : target->GetDeps(Target::DEPS_ALL)) 68 for (const auto& pair : target->GetDeps(Target::DEPS_ALL))
69 sorted_deps.push_back(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 (const auto& pair : sorted_deps) {
75 const Target* cur_dep = sorted_deps[i].ptr; 75 const Target* cur_dep = pair.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;
80 if (seen_targets) { 80 if (seen_targets) {
81 if (seen_targets->find(cur_dep) == seen_targets->end()) { 81 if (seen_targets->find(cur_dep) == seen_targets->end()) {
82 // New target, mark it visited. 82 // New target, mark it visited.
83 seen_targets->insert(cur_dep); 83 seen_targets->insert(cur_dep);
84 } else { 84 } else {
85 // Already seen. 85 // Already seen.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 123
124 // Collect the deps to display. 124 // Collect the deps to display.
125 std::vector<Label> deps; 125 std::vector<Label> deps;
126 if (cmdline->HasSwitch("all")) { 126 if (cmdline->HasSwitch("all")) {
127 // Show all dependencies. 127 // Show all dependencies.
128 if (display_header) 128 if (display_header)
129 OutputString("\nAll recursive dependencies:\n"); 129 OutputString("\nAll recursive dependencies:\n");
130 130
131 std::set<Label> all_deps; 131 std::set<Label> all_deps;
132 RecursiveCollectChildDeps(target, &all_deps); 132 RecursiveCollectChildDeps(target, &all_deps);
133 for (std::set<Label>::iterator i = all_deps.begin(); 133 for (const auto& dep : all_deps)
134 i != all_deps.end(); ++i) 134 deps.push_back(dep);
135 deps.push_back(*i);
136 } else { 135 } else {
137 // Show direct dependencies only. 136 // Show direct dependencies only.
138 if (display_header) { 137 if (display_header) {
139 OutputString( 138 OutputString(
140 "\nDirect dependencies " 139 "\nDirect dependencies "
141 "(try also \"--all\", \"--tree\", or even \"--all --tree\"):\n"); 140 "(try also \"--all\", \"--tree\", or even \"--all --tree\"):\n");
142 } 141 }
143 for (const auto& pair : target->GetDeps(Target::DEPS_ALL)) 142 for (const auto& pair : target->GetDeps(Target::DEPS_ALL))
144 deps.push_back(pair.label); 143 deps.push_back(pair.label);
145 } 144 }
146 145
147 std::sort(deps.begin(), deps.end()); 146 std::sort(deps.begin(), deps.end());
148 for (size_t i = 0; i < deps.size(); i++) 147 for (const auto& dep : deps)
149 OutputString(" " + deps[i].GetUserVisibleName(toolchain_label) + "\n"); 148 OutputString(" " + dep.GetUserVisibleName(toolchain_label) + "\n");
150 } 149 }
151 150
152 void PrintForwardDependentConfigsFrom(const Target* target, 151 void PrintForwardDependentConfigsFrom(const Target* target,
153 bool display_header) { 152 bool display_header) {
154 if (target->forward_dependent_configs().empty()) 153 if (target->forward_dependent_configs().empty())
155 return; 154 return;
156 155
157 if (display_header) 156 if (display_header)
158 OutputString("\nforward_dependent_configs_from:\n"); 157 OutputString("\nforward_dependent_configs_from:\n");
159 158
160 // Collect the sorted list of deps. 159 // Collect the sorted list of deps.
161 std::vector<Label> forward; 160 std::vector<Label> forward;
162 for (size_t i = 0; i < target->forward_dependent_configs().size(); i++) 161 for (const auto& pair : target->forward_dependent_configs())
163 forward.push_back(target->forward_dependent_configs()[i].label); 162 forward.push_back(pair.label);
164 std::sort(forward.begin(), forward.end()); 163 std::sort(forward.begin(), forward.end());
165 164
166 Label toolchain_label = target->label().GetToolchainLabel(); 165 Label toolchain_label = target->label().GetToolchainLabel();
167 for (size_t i = 0; i < forward.size(); i++) 166 for (const auto& fwd : forward)
168 OutputString(" " + forward[i].GetUserVisibleName(toolchain_label) + "\n"); 167 OutputString(" " + fwd.GetUserVisibleName(toolchain_label) + "\n");
169 } 168 }
170 169
171 // libs and lib_dirs are special in that they're inherited. We don't currently 170 // libs and lib_dirs are special in that they're inherited. We don't currently
172 // implement a blame feature for this since the bottom-up inheritance makes 171 // implement a blame feature for this since the bottom-up inheritance makes
173 // this difficult. 172 // this difficult.
174 void PrintLibDirs(const Target* target, bool display_header) { 173 void PrintLibDirs(const Target* target, bool display_header) {
175 const OrderedSet<SourceDir>& lib_dirs = target->all_lib_dirs(); 174 const OrderedSet<SourceDir>& lib_dirs = target->all_lib_dirs();
176 if (lib_dirs.empty()) 175 if (lib_dirs.empty())
177 return; 176 return;
178 177
(...skipping 20 matching lines...) Expand all
199 if (display_header) 198 if (display_header)
200 OutputString("\npublic:\n"); 199 OutputString("\npublic:\n");
201 200
202 if (target->all_headers_public()) { 201 if (target->all_headers_public()) {
203 OutputString(" [All headers listed in the sources are public.]\n"); 202 OutputString(" [All headers listed in the sources are public.]\n");
204 return; 203 return;
205 } 204 }
206 205
207 Target::FileList public_headers = target->public_headers(); 206 Target::FileList public_headers = target->public_headers();
208 std::sort(public_headers.begin(), public_headers.end()); 207 std::sort(public_headers.begin(), public_headers.end());
209 for (size_t i = 0; i < public_headers.size(); i++) 208 for (const auto& hdr : public_headers)
210 OutputString(" " + public_headers[i].value() + "\n"); 209 OutputString(" " + hdr.value() + "\n");
211 } 210 }
212 211
213 void PrintCheckIncludes(const Target* target, bool display_header) { 212 void PrintCheckIncludes(const Target* target, bool display_header) {
214 if (display_header) 213 if (display_header)
215 OutputString("\ncheck_includes:\n"); 214 OutputString("\ncheck_includes:\n");
216 215
217 if (target->check_includes()) 216 if (target->check_includes())
218 OutputString(" true\n"); 217 OutputString(" true\n");
219 else 218 else
220 OutputString(" false\n"); 219 OutputString(" false\n");
221 } 220 }
222 221
223 void PrintAllowCircularIncludesFrom(const Target* target, bool display_header) { 222 void PrintAllowCircularIncludesFrom(const Target* target, bool display_header) {
224 if (display_header) 223 if (display_header)
225 OutputString("\nallow_circular_includes_from:\n"); 224 OutputString("\nallow_circular_includes_from:\n");
226 225
227 Label toolchain_label = target->label().GetToolchainLabel(); 226 Label toolchain_label = target->label().GetToolchainLabel();
228 const std::set<Label>& allow = target->allow_circular_includes_from(); 227 for (const auto& cur : target->allow_circular_includes_from())
229 for (std::set<Label>::const_iterator iter = allow.begin(); 228 OutputString(" " + cur.GetUserVisibleName(toolchain_label) + "\n");
230 iter != allow.end(); ++iter)
231 OutputString(" " + iter->GetUserVisibleName(toolchain_label) + "\n");
232 } 229 }
233 230
234 void PrintVisibility(const Target* target, bool display_header) { 231 void PrintVisibility(const Target* target, bool display_header) {
235 if (display_header) 232 if (display_header)
236 OutputString("\nvisibility:\n"); 233 OutputString("\nvisibility:\n");
237 234
238 OutputString(target->visibility().Describe(2, false)); 235 OutputString(target->visibility().Describe(2, false));
239 } 236 }
240 237
241 void PrintTestonly(const Target* target, bool display_header) { 238 void PrintTestonly(const Target* target, bool display_header) {
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 // so always display them, even for groups and such. 699 // so always display them, even for groups and such.
703 PrintLibs(target, true); 700 PrintLibs(target, true);
704 PrintLibDirs(target, true); 701 PrintLibDirs(target, true);
705 702
706 PrintDeps(target, true); 703 PrintDeps(target, true);
707 704
708 return 0; 705 return 0;
709 } 706 }
710 707
711 } // namespace commands 708 } // namespace commands
OLDNEW
« no previous file with comments | « tools/gn/command_args.cc ('k') | tools/gn/command_help.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698