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

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

Issue 1494883002: GN: Makes GN output deterministic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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"
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/pointer_set.h"
17 #include "tools/gn/runtime_deps.h" 18 #include "tools/gn/runtime_deps.h"
18 #include "tools/gn/setup.h" 19 #include "tools/gn/setup.h"
19 #include "tools/gn/standard_out.h" 20 #include "tools/gn/standard_out.h"
20 #include "tools/gn/substitution_writer.h" 21 #include "tools/gn/substitution_writer.h"
21 #include "tools/gn/target.h" 22 #include "tools/gn/target.h"
22 #include "tools/gn/variables.h" 23 #include "tools/gn/variables.h"
23 24
24 namespace commands { 25 namespace commands {
25 26
26 namespace { 27 namespace {
(...skipping 12 matching lines...) Expand all
39 if (buf.size() > 3 && buf[2] == ':') { 40 if (buf.size() > 3 && buf[2] == ':') {
40 buf.erase(buf.begin()); // Erase beginning slash. 41 buf.erase(buf.begin()); // Erase beginning slash.
41 return buf; 42 return buf;
42 } 43 }
43 } 44 }
44 #endif 45 #endif
45 return dir.value(); 46 return dir.value();
46 } 47 }
47 48
48 void RecursiveCollectChildDeps(const Target* target, 49 void RecursiveCollectChildDeps(const Target* target,
49 std::set<const Target*>* result); 50 PointerSet<const Target>* result);
50 51
51 void RecursiveCollectDeps(const Target* target, 52 void RecursiveCollectDeps(const Target* target,
52 std::set<const Target*>* result) { 53 PointerSet<const Target>* result) {
53 if (result->find(target) != result->end()) 54 if (result->find(target) != result->end())
54 return; // Already did this target. 55 return; // Already did this target.
55 result->insert(target); 56 result->insert(target);
56 57
57 RecursiveCollectChildDeps(target, result); 58 RecursiveCollectChildDeps(target, result);
58 } 59 }
59 60
60 void RecursiveCollectChildDeps(const Target* target, 61 void RecursiveCollectChildDeps(const Target* target,
61 std::set<const Target*>* result) { 62 PointerSet<const Target>* result) {
62 for (const auto& pair : target->GetDeps(Target::DEPS_ALL)) 63 for (const auto& pair : target->GetDeps(Target::DEPS_ALL))
63 RecursiveCollectDeps(pair.ptr, result); 64 RecursiveCollectDeps(pair.ptr, result);
64 } 65 }
65 66
66 // Prints dependencies of the given target (not the target itself). If the 67 // Prints dependencies of the given target (not the target itself). If the
67 // set is non-null, new targets encountered will be added to the set, and if 68 // set is non-null, new targets encountered will be added to the set, and if
68 // a dependency is in the set already, it will not be recused into. When the 69 // a dependency is in the set already, it will not be recused into. When the
69 // set is null, all dependencies will be printed. 70 // set is null, all dependencies will be printed.
70 void RecursivePrintDeps(const Target* target, 71 void RecursivePrintDeps(const Target* target,
71 const Label& default_toolchain, 72 const Label& default_toolchain,
72 std::set<const Target*>* seen_targets, 73 PointerSet<const Target>* seen_targets,
73 int indent_level) { 74 int indent_level) {
74 // Combine all deps into one sorted list. 75 // Combine all deps into one sorted list.
75 std::vector<LabelTargetPair> sorted_deps; 76 std::vector<LabelTargetPair> sorted_deps;
76 for (const auto& pair : target->GetDeps(Target::DEPS_ALL)) 77 for (const auto& pair : target->GetDeps(Target::DEPS_ALL))
77 sorted_deps.push_back(pair); 78 sorted_deps.push_back(pair);
78 std::sort(sorted_deps.begin(), sorted_deps.end(), 79 std::sort(sorted_deps.begin(), sorted_deps.end(),
79 LabelPtrLabelLess<Target>()); 80 LabelPtrLabelLess<Target>());
80 81
81 std::string indent(indent_level * 2, ' '); 82 std::string indent(indent_level * 2, ' ');
82 for (const auto& pair : sorted_deps) { 83 for (const auto& pair : sorted_deps) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // Tree mode is separate. 117 // Tree mode is separate.
117 if (cmdline->HasSwitch(kTree)) { 118 if (cmdline->HasSwitch(kTree)) {
118 if (display_header) 119 if (display_header)
119 OutputString("\nDependency tree:\n"); 120 OutputString("\nDependency tree:\n");
120 121
121 if (cmdline->HasSwitch("all")) { 122 if (cmdline->HasSwitch("all")) {
122 // Show all tree deps with no eliding. 123 // Show all tree deps with no eliding.
123 RecursivePrintDeps(target, toolchain_label, nullptr, 1); 124 RecursivePrintDeps(target, toolchain_label, nullptr, 1);
124 } else { 125 } else {
125 // Don't recurse into duplicates. 126 // Don't recurse into duplicates.
126 std::set<const Target*> seen_targets; 127 PointerSet<const Target> seen_targets;
127 RecursivePrintDeps(target, toolchain_label, &seen_targets, 1); 128 RecursivePrintDeps(target, toolchain_label, &seen_targets, 1);
128 } 129 }
129 return; 130 return;
130 } 131 }
131 132
132 // Collect the deps to display. 133 // Collect the deps to display.
133 if (cmdline->HasSwitch("all")) { 134 if (cmdline->HasSwitch("all")) {
134 // Show all dependencies. 135 // Show all dependencies.
135 if (display_header) 136 if (display_header)
136 OutputString("\nAll recursive dependencies:\n"); 137 OutputString("\nAll recursive dependencies:\n");
137 138
138 std::set<const Target*> all_deps; 139 PointerSet<const Target> all_deps;
139 RecursiveCollectChildDeps(target, &all_deps); 140 RecursiveCollectChildDeps(target, &all_deps);
140 FilterAndPrintTargetSet(display_header, all_deps); 141 FilterAndPrintTargetSet(display_header, all_deps);
141 } else { 142 } else {
142 std::vector<const Target*> deps; 143 std::vector<const Target*> deps;
143 // Show direct dependencies only. 144 // Show direct dependencies only.
144 if (display_header) { 145 if (display_header) {
145 OutputString( 146 OutputString(
146 "\nDirect dependencies " 147 "\nDirect dependencies "
147 "(try also \"--all\", \"--tree\", or even \"--all --tree\"):\n"); 148 "(try also \"--all\", \"--tree\", or even \"--all --tree\"):\n");
148 } 149 }
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 // so always display them, even for groups and such. 744 // so always display them, even for groups and such.
744 PrintLibs(target, true); 745 PrintLibs(target, true);
745 PrintLibDirs(target, true); 746 PrintLibDirs(target, true);
746 747
747 PrintDeps(target, true); 748 PrintDeps(target, true);
748 749
749 return 0; 750 return 0;
750 } 751 }
751 752
752 } // namespace commands 753 } // namespace commands
OLDNEW
« no previous file with comments | « tools/gn/BUILD.gn ('k') | tools/gn/command_refs.cc » ('j') | tools/gn/ninja_build_writer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698