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 <map> | 5 #include <map> |
6 #include <set> | 6 #include <set> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "tools/gn/commands.h" | 9 #include "tools/gn/commands.h" |
10 #include "tools/gn/deps_iterator.h" | 10 #include "tools/gn/deps_iterator.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 // Prints the targets which are the result of a query. This list is sorted | 41 // Prints the targets which are the result of a query. This list is sorted |
42 // and, if as_files is set, the unique filenames matching those targets will | 42 // and, if as_files is set, the unique filenames matching those targets will |
43 // be used. | 43 // be used. |
44 void OutputResultSet(const TargetSet& results, bool as_files) { | 44 void OutputResultSet(const TargetSet& results, bool as_files) { |
45 if (results.empty()) | 45 if (results.empty()) |
46 return; | 46 return; |
47 | 47 |
48 if (as_files) { | 48 if (as_files) { |
49 // Output the set of unique source files. | 49 // Output the set of unique source files. |
50 std::set<std::string> unique_files; | 50 std::set<std::string> unique_files; |
51 for (TargetSet::const_iterator iter = results.begin(); | 51 for (const auto& cur : results) |
52 iter != results.end(); ++iter) | 52 unique_files.insert(FilePathToUTF8(FilePathForItem(cur))); |
53 unique_files.insert(FilePathToUTF8(FilePathForItem(*iter))); | |
54 | 53 |
55 for (std::set<std::string>::const_iterator iter = unique_files.begin(); | 54 for (const auto& cur : unique_files) |
56 iter != unique_files.end(); ++iter) { | 55 OutputString(cur + "\n"); |
57 OutputString(*iter + "\n"); | |
58 } | |
59 } else { | 56 } else { |
60 // Output sorted and uniquified list of labels. The set will sort the | 57 // Output sorted and uniquified list of labels. The set will sort the |
61 // labels. | 58 // labels. |
62 std::set<Label> unique_labels; | 59 std::set<Label> unique_labels; |
63 for (TargetSet::const_iterator iter = results.begin(); | 60 for (const auto& cur : results) |
64 iter != results.end(); ++iter) | 61 unique_labels.insert(cur->label()); |
65 unique_labels.insert((*iter)->label()); | |
66 | 62 |
67 // Grab the label of the default toolchain from a random target. | 63 // Grab the label of the default toolchain from a random target. |
68 Label default_tc_label = | 64 Label default_tc_label = |
69 (*results.begin())->settings()->default_toolchain_label(); | 65 (*results.begin())->settings()->default_toolchain_label(); |
70 | 66 |
71 for (std::set<Label>::const_iterator iter = unique_labels.begin(); | 67 for (const auto& cur : unique_labels) { |
72 iter != unique_labels.end(); ++iter) { | |
73 // Print toolchain only for ones not in the default toolchain. | 68 // Print toolchain only for ones not in the default toolchain. |
74 OutputString(iter->GetUserVisibleName( | 69 OutputString(cur.GetUserVisibleName( |
75 iter->GetToolchainLabel() != default_tc_label)); | 70 cur.GetToolchainLabel() != default_tc_label)); |
76 OutputString("\n"); | 71 OutputString("\n"); |
77 } | 72 } |
78 } | 73 } |
79 } | 74 } |
80 | 75 |
81 // Prints refs of the given target (not the target itself). If the set is | 76 // Prints refs of the given target (not the target itself). If the set is |
82 // non-null, new targets encountered will be added to the set, and if a ref is | 77 // non-null, new targets encountered will be added to the set, and if a ref is |
83 // in the set already, it will not be recused into. When the set is null, all | 78 // in the set already, it will not be recused into. When the set is null, all |
84 // refs will be printed. | 79 // refs will be printed. |
85 void RecursivePrintTree(const DepMap& dep_map, | 80 void RecursivePrintTree(const DepMap& dep_map, |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 // Recursively print all targets. | 247 // Recursively print all targets. |
253 RecursivePrintTree(dep_map, query[0], NULL, 0); | 248 RecursivePrintTree(dep_map, query[0], NULL, 0); |
254 } else { | 249 } else { |
255 // Recursively print unique targets. | 250 // Recursively print unique targets. |
256 TargetSet seen_targets; | 251 TargetSet seen_targets; |
257 RecursivePrintTree(dep_map, query[0], &seen_targets, 0); | 252 RecursivePrintTree(dep_map, query[0], &seen_targets, 0); |
258 } | 253 } |
259 } else if (all) { | 254 } else if (all) { |
260 // Output recursive dependencies, uniquified and flattened. | 255 // Output recursive dependencies, uniquified and flattened. |
261 TargetSet results; | 256 TargetSet results; |
262 for (size_t query_i = 0; query_i < query.size(); query_i++) | 257 for (const auto& cur_query : query) |
263 RecursiveCollectChildRefs(dep_map, query[query_i], &results); | 258 RecursiveCollectChildRefs(dep_map, cur_query, &results); |
264 OutputResultSet(results, files); | 259 OutputResultSet(results, files); |
265 } else { | 260 } else { |
266 // Output direct references of everything in the query. | 261 // Output direct references of everything in the query. |
267 TargetSet results; | 262 TargetSet results; |
268 for (size_t query_i = 0; query_i < query.size(); query_i++) { | 263 for (const auto& cur_query : query) { |
269 DepMap::const_iterator dep_begin = dep_map.lower_bound(query[query_i]); | 264 DepMap::const_iterator dep_begin = dep_map.lower_bound(cur_query); |
270 DepMap::const_iterator dep_end = dep_map.upper_bound(query[query_i]); | 265 DepMap::const_iterator dep_end = dep_map.upper_bound(cur_query); |
271 for (DepMap::const_iterator cur_dep = dep_begin; | 266 for (DepMap::const_iterator cur_dep = dep_begin; |
272 cur_dep != dep_end; cur_dep++) | 267 cur_dep != dep_end; cur_dep++) |
273 results.insert(cur_dep->second); | 268 results.insert(cur_dep->second); |
274 } | 269 } |
275 OutputResultSet(results, files); | 270 OutputResultSet(results, files); |
276 } | 271 } |
277 | 272 |
278 return 0; | 273 return 0; |
279 } | 274 } |
280 | 275 |
281 } // namespace commands | 276 } // namespace commands |
OLD | NEW |