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 <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 ~SourceFileWriter() = default; | 57 ~SourceFileWriter() = default; |
58 | 58 |
59 void operator()(std::ostream& out) const { | 59 void operator()(std::ostream& out) const { |
60 path_output_.WriteFile(out, source_file_); | 60 path_output_.WriteFile(out, source_file_); |
61 } | 61 } |
62 | 62 |
63 PathOutput& path_output_; | 63 PathOutput& path_output_; |
64 const SourceFile& source_file_; | 64 const SourceFile& source_file_; |
65 }; | 65 }; |
66 | 66 |
67 const char kToolsetVersion[] = "v140"; // Visual Studio 2015 | 67 const char kToolsetVersionVs2013[] = "v120"; // Visual Studio 2013 |
68 const char kVisualStudioVersion[] = "14.0"; // Visual Studio 2015 | 68 const char kToolsetVersionVs2015[] = "v140"; // Visual Studio 2015 |
| 69 const char kProjectVersionVs2013[] = "12.0"; // Visual Studio 2013 |
| 70 const char kProjectVersionVs2015[] = "14.0"; // Visual Studio 2015 |
| 71 const char kVersionStringVs2013[] = "Visual Studio 2013"; // Visual Studio 2013 |
| 72 const char kVersionStringVs2015[] = "Visual Studio 2015"; // Visual Studio 2015 |
69 const char kWindowsKitsVersion[] = "10"; // Windows 10 SDK | 73 const char kWindowsKitsVersion[] = "10"; // Windows 10 SDK |
70 const char kWindowsKitsIncludeVersion[] = "10.0.10240.0"; // Windows 10 SDK | 74 const char kWindowsKitsIncludeVersion[] = "10.0.10240.0"; // Windows 10 SDK |
71 | 75 |
72 const char kGuidTypeProject[] = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}"; | 76 const char kGuidTypeProject[] = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}"; |
73 const char kGuidTypeFolder[] = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}"; | 77 const char kGuidTypeFolder[] = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}"; |
74 const char kGuidSeedProject[] = "project"; | 78 const char kGuidSeedProject[] = "project"; |
75 const char kGuidSeedFolder[] = "folder"; | 79 const char kGuidSeedFolder[] = "folder"; |
76 const char kGuidSeedFilter[] = "filter"; | 80 const char kGuidSeedFilter[] = "filter"; |
77 | 81 |
78 std::string GetWindowsKitsIncludeDirs() { | 82 std::string GetWindowsKitsIncludeDirs() { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 const std::string& _path, | 170 const std::string& _path, |
167 const std::string& _guid, | 171 const std::string& _guid, |
168 const std::string& _label_dir_path, | 172 const std::string& _label_dir_path, |
169 const std::string& _config_platform) | 173 const std::string& _config_platform) |
170 : SolutionEntry(_name, _path, _guid), | 174 : SolutionEntry(_name, _path, _guid), |
171 label_dir_path(_label_dir_path), | 175 label_dir_path(_label_dir_path), |
172 config_platform(_config_platform) {} | 176 config_platform(_config_platform) {} |
173 | 177 |
174 VisualStudioWriter::SolutionProject::~SolutionProject() = default; | 178 VisualStudioWriter::SolutionProject::~SolutionProject() = default; |
175 | 179 |
176 VisualStudioWriter::VisualStudioWriter(const BuildSettings* build_settings) | 180 VisualStudioWriter::VisualStudioWriter(const BuildSettings* build_settings, |
| 181 Version version) |
177 : build_settings_(build_settings) { | 182 : build_settings_(build_settings) { |
178 const Value* value = build_settings->build_args().GetArgOverride("is_debug"); | 183 const Value* value = build_settings->build_args().GetArgOverride("is_debug"); |
179 is_debug_config_ = value == nullptr || value->boolean_value(); | 184 is_debug_config_ = value == nullptr || value->boolean_value(); |
180 config_platform_ = "Win32"; | 185 config_platform_ = "Win32"; |
181 value = build_settings->build_args().GetArgOverride(variables::kTargetCpu); | 186 value = build_settings->build_args().GetArgOverride(variables::kTargetCpu); |
182 if (value != nullptr && value->string_value() == "x64") | 187 if (value != nullptr && value->string_value() == "x64") |
183 config_platform_ = "x64"; | 188 config_platform_ = "x64"; |
184 | 189 |
| 190 switch (version) { |
| 191 case Version::Vs2013: |
| 192 project_version_ = kProjectVersionVs2013; |
| 193 toolset_version_ = kToolsetVersionVs2013; |
| 194 version_string_ = kVersionStringVs2013; |
| 195 break; |
| 196 case Version::Vs2015: |
| 197 project_version_ = kProjectVersionVs2015; |
| 198 toolset_version_ = kToolsetVersionVs2015; |
| 199 version_string_ = kVersionStringVs2015; |
| 200 break; |
| 201 default: |
| 202 NOTREACHED() << "Not a valid Visual Studio Version: " << version; |
| 203 } |
| 204 |
185 windows_kits_include_dirs_ = GetWindowsKitsIncludeDirs(); | 205 windows_kits_include_dirs_ = GetWindowsKitsIncludeDirs(); |
186 } | 206 } |
187 | 207 |
188 VisualStudioWriter::~VisualStudioWriter() { | 208 VisualStudioWriter::~VisualStudioWriter() { |
189 STLDeleteContainerPointers(projects_.begin(), projects_.end()); | 209 STLDeleteContainerPointers(projects_.begin(), projects_.end()); |
190 STLDeleteContainerPointers(folders_.begin(), folders_.end()); | 210 STLDeleteContainerPointers(folders_.begin(), folders_.end()); |
191 } | 211 } |
192 | 212 |
193 // static | 213 // static |
194 bool VisualStudioWriter::RunAndWriteFiles(const BuildSettings* build_settings, | 214 bool VisualStudioWriter::RunAndWriteFiles(const BuildSettings* build_settings, |
195 Builder* builder, | 215 Builder* builder, |
| 216 Version version, |
196 Err* err) { | 217 Err* err) { |
197 std::vector<const Target*> targets = builder->GetAllResolvedTargets(); | 218 std::vector<const Target*> targets = builder->GetAllResolvedTargets(); |
198 | 219 |
199 VisualStudioWriter writer(build_settings); | 220 VisualStudioWriter writer(build_settings, version); |
200 writer.projects_.reserve(targets.size()); | 221 writer.projects_.reserve(targets.size()); |
201 writer.folders_.reserve(targets.size()); | 222 writer.folders_.reserve(targets.size()); |
202 | 223 |
203 for (const Target* target : targets) { | 224 for (const Target* target : targets) { |
204 // Skip actions and groups. | 225 // Skip actions and groups. |
205 if (target->output_type() == Target::GROUP || | 226 if (target->output_type() == Target::GROUP || |
206 target->output_type() == Target::COPY_FILES || | 227 target->output_type() == Target::COPY_FILES || |
207 target->output_type() == Target::ACTION || | 228 target->output_type() == Target::ACTION || |
208 target->output_type() == Target::ACTION_FOREACH) { | 229 target->output_type() == Target::ACTION_FOREACH) { |
209 continue; | 230 continue; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 const Target* target, | 304 const Target* target, |
284 Err* err) { | 305 Err* err) { |
285 PathOutput path_output(GetTargetOutputDir(target), | 306 PathOutput path_output(GetTargetOutputDir(target), |
286 build_settings_->root_path_utf8(), | 307 build_settings_->root_path_utf8(), |
287 EscapingMode::ESCAPE_NONE); | 308 EscapingMode::ESCAPE_NONE); |
288 | 309 |
289 out << "<?xml version=\"1.0\" encoding=\"utf-8\"?>" << std::endl; | 310 out << "<?xml version=\"1.0\" encoding=\"utf-8\"?>" << std::endl; |
290 XmlElementWriter project( | 311 XmlElementWriter project( |
291 out, "Project", | 312 out, "Project", |
292 XmlAttributes("DefaultTargets", "Build") | 313 XmlAttributes("DefaultTargets", "Build") |
293 .add("ToolsVersion", kVisualStudioVersion) | 314 .add("ToolsVersion", project_version_) |
294 .add("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003")); | 315 .add("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003")); |
295 | 316 |
296 { | 317 { |
297 scoped_ptr<XmlElementWriter> configurations = project.SubElement( | 318 scoped_ptr<XmlElementWriter> configurations = project.SubElement( |
298 "ItemGroup", XmlAttributes("Label", "ProjectConfigurations")); | 319 "ItemGroup", XmlAttributes("Label", "ProjectConfigurations")); |
299 std::string config_name = is_debug_config_ ? "Debug" : "Release"; | 320 std::string config_name = is_debug_config_ ? "Debug" : "Release"; |
300 scoped_ptr<XmlElementWriter> project_config = configurations->SubElement( | 321 scoped_ptr<XmlElementWriter> project_config = configurations->SubElement( |
301 "ProjectConfiguration", | 322 "ProjectConfiguration", |
302 XmlAttributes("Include", | 323 XmlAttributes("Include", |
303 config_name + '|' + solution_project.config_platform)); | 324 config_name + '|' + solution_project.config_platform)); |
(...skipping 22 matching lines...) Expand all Loading... |
326 configuration->SubElement("CharacterSet")->Text("Unicode"); | 347 configuration->SubElement("CharacterSet")->Text("Unicode"); |
327 std::string configuration_type = GetConfigurationType(target, err); | 348 std::string configuration_type = GetConfigurationType(target, err); |
328 if (configuration_type.empty()) | 349 if (configuration_type.empty()) |
329 return false; | 350 return false; |
330 configuration->SubElement("ConfigurationType")->Text(configuration_type); | 351 configuration->SubElement("ConfigurationType")->Text(configuration_type); |
331 } | 352 } |
332 | 353 |
333 { | 354 { |
334 scoped_ptr<XmlElementWriter> locals = | 355 scoped_ptr<XmlElementWriter> locals = |
335 project.SubElement("PropertyGroup", XmlAttributes("Label", "Locals")); | 356 project.SubElement("PropertyGroup", XmlAttributes("Label", "Locals")); |
336 locals->SubElement("PlatformToolset")->Text(kToolsetVersion); | 357 locals->SubElement("PlatformToolset")->Text(toolset_version_); |
337 } | 358 } |
338 | 359 |
339 project.SubElement( | 360 project.SubElement( |
340 "Import", | 361 "Import", |
341 XmlAttributes("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props")); | 362 XmlAttributes("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props")); |
342 project.SubElement( | 363 project.SubElement( |
343 "Import", | 364 "Import", |
344 XmlAttributes("Project", | 365 XmlAttributes("Project", |
345 "$(VCTargetsPath)\\BuildCustomizations\\masm.props")); | 366 "$(VCTargetsPath)\\BuildCustomizations\\masm.props")); |
346 project.SubElement("ImportGroup", | 367 project.SubElement("ImportGroup", |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 // both a performance optimization and more importantly, prevents | 594 // both a performance optimization and more importantly, prevents |
574 // Visual Studio from reloading the projects. | 595 // Visual Studio from reloading the projects. |
575 return WriteFileIfChanged(sln_path, string_out.str(), err); | 596 return WriteFileIfChanged(sln_path, string_out.str(), err); |
576 } | 597 } |
577 | 598 |
578 void VisualStudioWriter::WriteSolutionFileContents( | 599 void VisualStudioWriter::WriteSolutionFileContents( |
579 std::ostream& out, | 600 std::ostream& out, |
580 const base::FilePath& solution_dir_path) { | 601 const base::FilePath& solution_dir_path) { |
581 out << "Microsoft Visual Studio Solution File, Format Version 12.00" | 602 out << "Microsoft Visual Studio Solution File, Format Version 12.00" |
582 << std::endl; | 603 << std::endl; |
583 out << "# Visual Studio 2015" << std::endl; | 604 out << "# " << version_string_ << std::endl; |
584 | 605 |
585 SourceDir solution_dir(FilePathToUTF8(solution_dir_path)); | 606 SourceDir solution_dir(FilePathToUTF8(solution_dir_path)); |
586 for (const SolutionEntry* folder : folders_) { | 607 for (const SolutionEntry* folder : folders_) { |
587 out << "Project(\"" << kGuidTypeFolder << "\") = \"(" << folder->name | 608 out << "Project(\"" << kGuidTypeFolder << "\") = \"(" << folder->name |
588 << ")\", \"" << RebasePath(folder->path, solution_dir, "/") << "\", \"" | 609 << ")\", \"" << RebasePath(folder->path, solution_dir, "/") << "\", \"" |
589 << folder->guid << "\"" << std::endl; | 610 << folder->guid << "\"" << std::endl; |
590 out << "EndProject" << std::endl; | 611 out << "EndProject" << std::endl; |
591 } | 612 } |
592 | 613 |
593 for (const SolutionEntry* project : projects_) { | 614 for (const SolutionEntry* project : projects_) { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 base::CompareCase::SENSITIVE)) { | 744 base::CompareCase::SENSITIVE)) { |
724 folder->parent_folder = parents.back(); | 745 folder->parent_folder = parents.back(); |
725 break; | 746 break; |
726 } else { | 747 } else { |
727 parents.pop_back(); | 748 parents.pop_back(); |
728 } | 749 } |
729 } | 750 } |
730 parents.push_back(folder); | 751 parents.push_back(folder); |
731 } | 752 } |
732 } | 753 } |
OLD | NEW |