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

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

Issue 1734083002: GN: Visual Studio generator does not depend on is_debug variable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment fix Created 4 years, 9 months 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
« no previous file with comments | « tools/gn/visual_studio_writer.h ('k') | tools/gn/visual_studio_writer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 const char kVersionStringVs2015[] = "Visual Studio 2015"; // Visual Studio 2015 72 const char kVersionStringVs2015[] = "Visual Studio 2015"; // Visual Studio 2015
73 const char kWindowsKitsVersion[] = "10"; // Windows 10 SDK 73 const char kWindowsKitsVersion[] = "10"; // Windows 10 SDK
74 const char kWindowsKitsIncludeVersion[] = "10.0.10586.0"; // Windows 10 SDK 74 const char kWindowsKitsIncludeVersion[] = "10.0.10586.0"; // Windows 10 SDK
75 75
76 const char kGuidTypeProject[] = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}"; 76 const char kGuidTypeProject[] = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}";
77 const char kGuidTypeFolder[] = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}"; 77 const char kGuidTypeFolder[] = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}";
78 const char kGuidSeedProject[] = "project"; 78 const char kGuidSeedProject[] = "project";
79 const char kGuidSeedFolder[] = "folder"; 79 const char kGuidSeedFolder[] = "folder";
80 const char kGuidSeedFilter[] = "filter"; 80 const char kGuidSeedFilter[] = "filter";
81 81
82 const char kConfigurationName[] = "GN";
83
82 std::string GetWindowsKitsIncludeDirs() { 84 std::string GetWindowsKitsIncludeDirs() {
83 std::string kits_path; 85 std::string kits_path;
84 86
85 #if defined(OS_WIN) 87 #if defined(OS_WIN)
86 const base::char16* const subkeys[] = { 88 const base::char16* const subkeys[] = {
87 L"SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots", 89 L"SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots",
88 L"SOFTWARE\\Wow6432Node\\Microsoft\\Windows Kits\\Installed Roots"}; 90 L"SOFTWARE\\Wow6432Node\\Microsoft\\Windows Kits\\Installed Roots"};
89 91
90 base::string16 value_name = 92 base::string16 value_name =
91 base::ASCIIToUTF16("KitsRoot") + base::ASCIIToUTF16(kWindowsKitsVersion); 93 base::ASCIIToUTF16("KitsRoot") + base::ASCIIToUTF16(kWindowsKitsVersion);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 const std::string& _guid, 173 const std::string& _guid,
172 const std::string& _label_dir_path, 174 const std::string& _label_dir_path,
173 const std::string& _config_platform) 175 const std::string& _config_platform)
174 : SolutionEntry(_name, _path, _guid), 176 : SolutionEntry(_name, _path, _guid),
175 label_dir_path(_label_dir_path), 177 label_dir_path(_label_dir_path),
176 config_platform(_config_platform) {} 178 config_platform(_config_platform) {}
177 179
178 VisualStudioWriter::SolutionProject::~SolutionProject() = default; 180 VisualStudioWriter::SolutionProject::~SolutionProject() = default;
179 181
180 VisualStudioWriter::VisualStudioWriter(const BuildSettings* build_settings, 182 VisualStudioWriter::VisualStudioWriter(const BuildSettings* build_settings,
181 bool is_debug_config,
182 const char* config_platform, 183 const char* config_platform,
183 Version version) 184 Version version)
184 : build_settings_(build_settings), 185 : build_settings_(build_settings),
185 is_debug_config_(is_debug_config),
186 config_platform_(config_platform), 186 config_platform_(config_platform),
187 ninja_path_output_(build_settings->build_dir(), 187 ninja_path_output_(build_settings->build_dir(),
188 build_settings->root_path_utf8(), 188 build_settings->root_path_utf8(),
189 EscapingMode::ESCAPE_NINJA_COMMAND) { 189 EscapingMode::ESCAPE_NINJA_COMMAND) {
190 switch (version) { 190 switch (version) {
191 case Version::Vs2013: 191 case Version::Vs2013:
192 project_version_ = kProjectVersionVs2013; 192 project_version_ = kProjectVersionVs2013;
193 toolset_version_ = kToolsetVersionVs2013; 193 toolset_version_ = kToolsetVersionVs2013;
194 version_string_ = kVersionStringVs2013; 194 version_string_ = kVersionStringVs2013;
195 break; 195 break;
(...skipping 14 matching lines...) Expand all
210 STLDeleteContainerPointers(folders_.begin(), folders_.end()); 210 STLDeleteContainerPointers(folders_.begin(), folders_.end());
211 } 211 }
212 212
213 // static 213 // static
214 bool VisualStudioWriter::RunAndWriteFiles(const BuildSettings* build_settings, 214 bool VisualStudioWriter::RunAndWriteFiles(const BuildSettings* build_settings,
215 Builder* builder, 215 Builder* builder,
216 Version version, 216 Version version,
217 Err* err) { 217 Err* err) {
218 std::vector<const Target*> targets = builder->GetAllResolvedTargets(); 218 std::vector<const Target*> targets = builder->GetAllResolvedTargets();
219 219
220 bool is_debug_config = true;
221 const char* config_platform = "Win32"; 220 const char* config_platform = "Win32";
222 221
223 // Assume the "is_debug" and "target_cpu" variables do not change 222 // Assume the "target_cpu" variable does not change between different
224 // between different toolchains. 223 // toolchains.
225 if (!targets.empty()) { 224 if (!targets.empty()) {
226 const Scope* scope = targets.front()->settings()->base_config(); 225 const Scope* scope = targets.front()->settings()->base_config();
227 const Value* is_debug_value = scope->GetValue("is_debug");
228 is_debug_config =
229 is_debug_value == nullptr || is_debug_value->boolean_value();
230 const Value* target_cpu_value = scope->GetValue(variables::kTargetCpu); 226 const Value* target_cpu_value = scope->GetValue(variables::kTargetCpu);
231 if (target_cpu_value != nullptr && 227 if (target_cpu_value != nullptr &&
232 target_cpu_value->string_value() == "x64") 228 target_cpu_value->string_value() == "x64")
233 config_platform = "x64"; 229 config_platform = "x64";
234 } 230 }
235 231
236 VisualStudioWriter writer(build_settings, is_debug_config, config_platform, 232 VisualStudioWriter writer(build_settings, config_platform, version);
237 version);
238 writer.projects_.reserve(targets.size()); 233 writer.projects_.reserve(targets.size());
239 writer.folders_.reserve(targets.size()); 234 writer.folders_.reserve(targets.size());
240 235
241 for (const Target* target : targets) { 236 for (const Target* target : targets) {
242 // Skip actions and groups. 237 // Skip actions and groups.
243 if (target->output_type() == Target::GROUP || 238 if (target->output_type() == Target::GROUP ||
244 target->output_type() == Target::COPY_FILES || 239 target->output_type() == Target::COPY_FILES ||
245 target->output_type() == Target::ACTION || 240 target->output_type() == Target::ACTION ||
246 target->output_type() == Target::ACTION_FOREACH) { 241 target->output_type() == Target::ACTION_FOREACH) {
247 continue; 242 continue;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 out << "<?xml version=\"1.0\" encoding=\"utf-8\"?>" << std::endl; 320 out << "<?xml version=\"1.0\" encoding=\"utf-8\"?>" << std::endl;
326 XmlElementWriter project( 321 XmlElementWriter project(
327 out, "Project", 322 out, "Project",
328 XmlAttributes("DefaultTargets", "Build") 323 XmlAttributes("DefaultTargets", "Build")
329 .add("ToolsVersion", project_version_) 324 .add("ToolsVersion", project_version_)
330 .add("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003")); 325 .add("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003"));
331 326
332 { 327 {
333 scoped_ptr<XmlElementWriter> configurations = project.SubElement( 328 scoped_ptr<XmlElementWriter> configurations = project.SubElement(
334 "ItemGroup", XmlAttributes("Label", "ProjectConfigurations")); 329 "ItemGroup", XmlAttributes("Label", "ProjectConfigurations"));
335 std::string config_name = is_debug_config_ ? "Debug" : "Release";
336 scoped_ptr<XmlElementWriter> project_config = configurations->SubElement( 330 scoped_ptr<XmlElementWriter> project_config = configurations->SubElement(
337 "ProjectConfiguration", 331 "ProjectConfiguration",
338 XmlAttributes("Include", 332 XmlAttributes("Include", std::string(kConfigurationName) + '|' +
339 config_name + '|' + solution_project.config_platform)); 333 solution_project.config_platform));
340 project_config->SubElement("Configuration")->Text(config_name); 334 project_config->SubElement("Configuration")->Text(kConfigurationName);
341 project_config->SubElement("Platform") 335 project_config->SubElement("Platform")
342 ->Text(solution_project.config_platform); 336 ->Text(solution_project.config_platform);
343 } 337 }
344 338
345 { 339 {
346 scoped_ptr<XmlElementWriter> globals = 340 scoped_ptr<XmlElementWriter> globals =
347 project.SubElement("PropertyGroup", XmlAttributes("Label", "Globals")); 341 project.SubElement("PropertyGroup", XmlAttributes("Label", "Globals"));
348 globals->SubElement("ProjectGuid")->Text(solution_project.guid); 342 globals->SubElement("ProjectGuid")->Text(solution_project.guid);
349 globals->SubElement("Keyword")->Text("Win32Proj"); 343 globals->SubElement("Keyword")->Text("Win32Proj");
350 globals->SubElement("RootNamespace")->Text(target->label().name()); 344 globals->SubElement("RootNamespace")->Text(target->label().name());
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 out << "Project(\"" << kGuidTypeProject << "\") = \"" << project->name 626 out << "Project(\"" << kGuidTypeProject << "\") = \"" << project->name
633 << "\", \"" << RebasePath(project->path, solution_dir) << "\", \"" 627 << "\", \"" << RebasePath(project->path, solution_dir) << "\", \""
634 << project->guid << "\"" << std::endl; 628 << project->guid << "\"" << std::endl;
635 out << "EndProject" << std::endl; 629 out << "EndProject" << std::endl;
636 } 630 }
637 631
638 out << "Global" << std::endl; 632 out << "Global" << std::endl;
639 633
640 out << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution" 634 out << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution"
641 << std::endl; 635 << std::endl;
642 const std::string config_mode_prefix = 636 const std::string config_mode_prefix = std::string(kConfigurationName) + '|';
643 std::string(is_debug_config_ ? "Debug" : "Release") + '|';
644 const std::string config_mode = config_mode_prefix + config_platform_; 637 const std::string config_mode = config_mode_prefix + config_platform_;
645 out << "\t\t" << config_mode << " = " << config_mode << std::endl; 638 out << "\t\t" << config_mode << " = " << config_mode << std::endl;
646 out << "\tEndGlobalSection" << std::endl; 639 out << "\tEndGlobalSection" << std::endl;
647 640
648 out << "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution" 641 out << "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution"
649 << std::endl; 642 << std::endl;
650 for (const SolutionProject* project : projects_) { 643 for (const SolutionProject* project : projects_) {
651 const std::string project_config_mode = 644 const std::string project_config_mode =
652 config_mode_prefix + project->config_platform; 645 config_mode_prefix + project->config_platform;
653 out << "\t\t" << project->guid << '.' << config_mode 646 out << "\t\t" << project->guid << '.' << config_mode
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 } 762 }
770 } 763 }
771 764
772 std::string VisualStudioWriter::GetNinjaTarget(const Target* target) { 765 std::string VisualStudioWriter::GetNinjaTarget(const Target* target) {
773 std::ostringstream ninja_target_out; 766 std::ostringstream ninja_target_out;
774 DCHECK(!target->dependency_output_file().value().empty()); 767 DCHECK(!target->dependency_output_file().value().empty());
775 ninja_path_output_.WriteFile(ninja_target_out, 768 ninja_path_output_.WriteFile(ninja_target_out,
776 target->dependency_output_file()); 769 target->dependency_output_file());
777 return ninja_target_out.str(); 770 return ninja_target_out.str();
778 } 771 }
OLDNEW
« no previous file with comments | « tools/gn/visual_studio_writer.h ('k') | tools/gn/visual_studio_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698