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 <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/filesystem_utils.h" |
13 #include "tools/gn/item.h" | 14 #include "tools/gn/item.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 // Prints the given directory in a nice way for the user to view. |
| 25 std::string FormatSourceDir(const SourceDir& dir) { |
| 26 #if defined(OS_WIN) |
| 27 // On Windows we fix up system absolute paths to look like native ones. |
| 28 // Internally, they'll look like "/C:\foo\bar/" |
| 29 if (dir.is_system_absolute()) { |
| 30 std::string buf = dir.value(); |
| 31 if (buf.size() > 3 && buf[2] == ':') { |
| 32 buf.erase(buf.begin()); // Erase beginning slash. |
| 33 ConvertPathToSystem(&buf); // Convert to backslashes. |
| 34 return buf; |
| 35 } |
| 36 } |
| 37 #endif |
| 38 return dir.value(); |
| 39 } |
| 40 |
24 void RecursiveCollectChildDeps(const Target* target, std::set<Label>* result); | 41 void RecursiveCollectChildDeps(const Target* target, std::set<Label>* result); |
25 | 42 |
26 void RecursiveCollectDeps(const Target* target, std::set<Label>* result) { | 43 void RecursiveCollectDeps(const Target* target, std::set<Label>* result) { |
27 if (result->find(target->label()) != result->end()) | 44 if (result->find(target->label()) != result->end()) |
28 return; // Already did this target. | 45 return; // Already did this target. |
29 result->insert(target->label()); | 46 result->insert(target->label()); |
30 | 47 |
31 RecursiveCollectChildDeps(target, result); | 48 RecursiveCollectChildDeps(target, result); |
32 } | 49 } |
33 | 50 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 // this difficult. | 124 // this difficult. |
108 void PrintLibDirs(const Target* target, bool display_header) { | 125 void PrintLibDirs(const Target* target, bool display_header) { |
109 const OrderedSet<SourceDir>& lib_dirs = target->all_lib_dirs(); | 126 const OrderedSet<SourceDir>& lib_dirs = target->all_lib_dirs(); |
110 if (lib_dirs.empty()) | 127 if (lib_dirs.empty()) |
111 return; | 128 return; |
112 | 129 |
113 if (display_header) | 130 if (display_header) |
114 OutputString("\nlib_dirs\n"); | 131 OutputString("\nlib_dirs\n"); |
115 | 132 |
116 for (size_t i = 0; i < lib_dirs.size(); i++) | 133 for (size_t i = 0; i < lib_dirs.size(); i++) |
117 OutputString(" " + lib_dirs[i].value() + "\n"); | 134 OutputString(" " + FormatSourceDir(lib_dirs[i]) + "\n"); |
118 } | 135 } |
119 | 136 |
120 void PrintLibs(const Target* target, bool display_header) { | 137 void PrintLibs(const Target* target, bool display_header) { |
121 const OrderedSet<std::string>& libs = target->all_libs(); | 138 const OrderedSet<std::string>& libs = target->all_libs(); |
122 if (libs.empty()) | 139 if (libs.empty()) |
123 return; | 140 return; |
124 | 141 |
125 if (display_header) | 142 if (display_header) |
126 OutputString("\nlibs\n"); | 143 OutputString("\nlibs\n"); |
127 | 144 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 out << " " << str << "\n"; | 186 out << " " << str << "\n"; |
170 } | 187 } |
171 }; | 188 }; |
172 template<> struct DescValueWriter<SourceFile> { | 189 template<> struct DescValueWriter<SourceFile> { |
173 void operator()(const SourceFile& file, std::ostream& out) const { | 190 void operator()(const SourceFile& file, std::ostream& out) const { |
174 out << " " << file.value() << "\n"; | 191 out << " " << file.value() << "\n"; |
175 } | 192 } |
176 }; | 193 }; |
177 template<> struct DescValueWriter<SourceDir> { | 194 template<> struct DescValueWriter<SourceDir> { |
178 void operator()(const SourceDir& dir, std::ostream& out) const { | 195 void operator()(const SourceDir& dir, std::ostream& out) const { |
179 out << " " << dir.value() << "\n"; | 196 out << " " << FormatSourceDir(dir) << "\n"; |
180 } | 197 } |
181 }; | 198 }; |
182 | 199 |
183 // Writes a given config value type to the string, optionally with attribution. | 200 // Writes a given config value type to the string, optionally with attribution. |
184 // This should match RecursiveTargetConfigToStream in the order it traverses. | 201 // This should match RecursiveTargetConfigToStream in the order it traverses. |
185 template<typename T> void OutputRecursiveTargetConfig( | 202 template<typename T> void OutputRecursiveTargetConfig( |
186 const Target* target, | 203 const Target* target, |
187 const char* header_name, | 204 const char* header_name, |
188 const std::vector<T>& (ConfigValues::* getter)() const) { | 205 const std::vector<T>& (ConfigValues::* getter)() const) { |
189 bool display_blame = CommandLine::ForCurrentProcess()->HasSwitch("blame"); | 206 bool display_blame = CommandLine::ForCurrentProcess()->HasSwitch("blame"); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 OUTPUT_CONFIG_VALUE(ldflags, std::string) | 380 OUTPUT_CONFIG_VALUE(ldflags, std::string) |
364 PrintLibs(target, true); | 381 PrintLibs(target, true); |
365 PrintLibDirs(target, true); | 382 PrintLibDirs(target, true); |
366 | 383 |
367 PrintDeps(target, true); | 384 PrintDeps(target, true); |
368 | 385 |
369 return 0; | 386 return 0; |
370 } | 387 } |
371 | 388 |
372 } // namespace commands | 389 } // namespace commands |
OLD | NEW |