OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "tools/gn/visual_studio_writer.h" | 5 #include "tools/gn/visual_studio_writer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
| 11 #include <queue> |
11 #include <set> | 12 #include <set> |
12 #include <string> | 13 #include <string> |
13 | 14 |
14 #include "base/logging.h" | 15 #include "base/logging.h" |
15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
17 #include "tools/gn/builder.h" | 18 #include "tools/gn/builder.h" |
18 #include "tools/gn/commands.h" | 19 #include "tools/gn/commands.h" |
19 #include "tools/gn/config.h" | 20 #include "tools/gn/config.h" |
20 #include "tools/gn/config_values_extractors.h" | 21 #include "tools/gn/config_values_extractors.h" |
| 22 #include "tools/gn/deps_iterator.h" |
21 #include "tools/gn/filesystem_utils.h" | 23 #include "tools/gn/filesystem_utils.h" |
22 #include "tools/gn/label_pattern.h" | 24 #include "tools/gn/label_pattern.h" |
23 #include "tools/gn/parse_tree.h" | 25 #include "tools/gn/parse_tree.h" |
24 #include "tools/gn/path_output.h" | 26 #include "tools/gn/path_output.h" |
25 #include "tools/gn/source_file_type.h" | 27 #include "tools/gn/source_file_type.h" |
26 #include "tools/gn/standard_out.h" | 28 #include "tools/gn/standard_out.h" |
27 #include "tools/gn/target.h" | 29 #include "tools/gn/target.h" |
28 #include "tools/gn/variables.h" | 30 #include "tools/gn/variables.h" |
29 #include "tools/gn/visual_studio_utils.h" | 31 #include "tools/gn/visual_studio_utils.h" |
30 #include "tools/gn/xml_element_writer.h" | 32 #include "tools/gn/xml_element_writer.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 // outlive the output. | 158 // outlive the output. |
157 base::StringPiece FindParentDir(const std::string* path) { | 159 base::StringPiece FindParentDir(const std::string* path) { |
158 DCHECK(path && !path->empty()); | 160 DCHECK(path && !path->empty()); |
159 for (int i = static_cast<int>(path->size()) - 2; i >= 0; --i) { | 161 for (int i = static_cast<int>(path->size()) - 2; i >= 0; --i) { |
160 if (IsSlash((*path)[i])) | 162 if (IsSlash((*path)[i])) |
161 return base::StringPiece(path->data(), i); | 163 return base::StringPiece(path->data(), i); |
162 } | 164 } |
163 return base::StringPiece(); | 165 return base::StringPiece(); |
164 } | 166 } |
165 | 167 |
| 168 bool FilterTargets(const BuildSettings* build_settings, |
| 169 Builder* builder, |
| 170 const std::string& dir_filters, |
| 171 std::vector<const Target*>* targets, |
| 172 Err* err) { |
| 173 if (dir_filters.empty()) { |
| 174 *targets = builder->GetAllResolvedTargets(); |
| 175 return true; |
| 176 } |
| 177 |
| 178 std::vector<LabelPattern> filters; |
| 179 if (!commands::FilterPatternsFromString(build_settings, dir_filters, &filters, |
| 180 err)) |
| 181 return false; |
| 182 |
| 183 commands::FilterTargetsByPatterns(builder->GetAllResolvedTargets(), filters, |
| 184 targets); |
| 185 |
| 186 std::set<Label> labels; |
| 187 std::queue<const Target*> to_process; |
| 188 for (const Target* target : *targets) { |
| 189 labels.insert(target->label()); |
| 190 to_process.push(target); |
| 191 } |
| 192 |
| 193 while (!to_process.empty()) { |
| 194 const Target* target = to_process.front(); |
| 195 to_process.pop(); |
| 196 for (const auto& pair : target->GetDeps(Target::DEPS_ALL)) { |
| 197 if (labels.find(pair.label) == labels.end()) { |
| 198 targets->push_back(pair.ptr); |
| 199 to_process.push(pair.ptr); |
| 200 labels.insert(pair.label); |
| 201 } |
| 202 } |
| 203 } |
| 204 |
| 205 return true; |
| 206 } |
| 207 |
166 } // namespace | 208 } // namespace |
167 | 209 |
168 VisualStudioWriter::SolutionEntry::SolutionEntry(const std::string& _name, | 210 VisualStudioWriter::SolutionEntry::SolutionEntry(const std::string& _name, |
169 const std::string& _path, | 211 const std::string& _path, |
170 const std::string& _guid) | 212 const std::string& _guid) |
171 : name(_name), path(_path), guid(_guid), parent_folder(nullptr) {} | 213 : name(_name), path(_path), guid(_guid), parent_folder(nullptr) {} |
172 | 214 |
173 VisualStudioWriter::SolutionEntry::~SolutionEntry() = default; | 215 VisualStudioWriter::SolutionEntry::~SolutionEntry() = default; |
174 | 216 |
175 VisualStudioWriter::SolutionProject::SolutionProject( | 217 VisualStudioWriter::SolutionProject::SolutionProject( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 } | 268 } |
227 | 269 |
228 // static | 270 // static |
229 bool VisualStudioWriter::RunAndWriteFiles(const BuildSettings* build_settings, | 271 bool VisualStudioWriter::RunAndWriteFiles(const BuildSettings* build_settings, |
230 Builder* builder, | 272 Builder* builder, |
231 Version version, | 273 Version version, |
232 const std::string& sln_name, | 274 const std::string& sln_name, |
233 const std::string& dir_filters, | 275 const std::string& dir_filters, |
234 Err* err) { | 276 Err* err) { |
235 std::vector<const Target*> targets; | 277 std::vector<const Target*> targets; |
236 if (dir_filters.empty()) { | 278 if (!FilterTargets(build_settings, builder, dir_filters, &targets, err)) |
237 targets = builder->GetAllResolvedTargets(); | 279 return false; |
238 } else { | |
239 std::vector<LabelPattern> filters; | |
240 if (!commands::FilterPatternsFromString(build_settings, dir_filters, | |
241 &filters, err)) { | |
242 return false; | |
243 } | |
244 | |
245 commands::FilterTargetsByPatterns(builder->GetAllResolvedTargets(), filters, | |
246 &targets); | |
247 } | |
248 | 280 |
249 const char* config_platform = "Win32"; | 281 const char* config_platform = "Win32"; |
250 | 282 |
251 // Assume the "target_cpu" variable does not change between different | 283 // Assume the "target_cpu" variable does not change between different |
252 // toolchains. | 284 // toolchains. |
253 if (!targets.empty()) { | 285 if (!targets.empty()) { |
254 const Scope* scope = targets.front()->settings()->base_config(); | 286 const Scope* scope = targets.front()->settings()->base_config(); |
255 const Value* target_cpu_value = scope->GetValue(variables::kTargetCpu); | 287 const Value* target_cpu_value = scope->GetValue(variables::kTargetCpu); |
256 if (target_cpu_value != nullptr && | 288 if (target_cpu_value != nullptr && |
257 target_cpu_value->string_value() == "x64") | 289 target_cpu_value->string_value() == "x64") |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 } | 832 } |
801 } | 833 } |
802 | 834 |
803 std::string VisualStudioWriter::GetNinjaTarget(const Target* target) { | 835 std::string VisualStudioWriter::GetNinjaTarget(const Target* target) { |
804 std::ostringstream ninja_target_out; | 836 std::ostringstream ninja_target_out; |
805 DCHECK(!target->dependency_output_file().value().empty()); | 837 DCHECK(!target->dependency_output_file().value().empty()); |
806 ninja_path_output_.WriteFile(ninja_target_out, | 838 ninja_path_output_.WriteFile(ninja_target_out, |
807 target->dependency_output_file()); | 839 target->dependency_output_file()); |
808 return ninja_target_out.str(); | 840 return ninja_target_out.str(); |
809 } | 841 } |
OLD | NEW |