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

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

Issue 1733023002: GN: Fix CPU detection in Visual Studio generator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 const std::string& _guid, 171 const std::string& _guid,
172 const std::string& _label_dir_path, 172 const std::string& _label_dir_path,
173 const std::string& _config_platform) 173 const std::string& _config_platform)
174 : SolutionEntry(_name, _path, _guid), 174 : SolutionEntry(_name, _path, _guid),
175 label_dir_path(_label_dir_path), 175 label_dir_path(_label_dir_path),
176 config_platform(_config_platform) {} 176 config_platform(_config_platform) {}
177 177
178 VisualStudioWriter::SolutionProject::~SolutionProject() = default; 178 VisualStudioWriter::SolutionProject::~SolutionProject() = default;
179 179
180 VisualStudioWriter::VisualStudioWriter(const BuildSettings* build_settings, 180 VisualStudioWriter::VisualStudioWriter(const BuildSettings* build_settings,
181 bool is_debug_config,
182 const char* config_platform,
181 Version version) 183 Version version)
182 : build_settings_(build_settings), 184 : build_settings_(build_settings),
185 is_debug_config_(is_debug_config),
186 config_platform_(config_platform),
183 ninja_path_output_(build_settings->build_dir(), 187 ninja_path_output_(build_settings->build_dir(),
184 build_settings->root_path_utf8(), 188 build_settings->root_path_utf8(),
185 EscapingMode::ESCAPE_NINJA_COMMAND) { 189 EscapingMode::ESCAPE_NINJA_COMMAND) {
186 const Value* value = build_settings->build_args().GetArgOverride("is_debug");
187 is_debug_config_ = value == nullptr || value->boolean_value();
188 config_platform_ = "Win32";
189 value = build_settings->build_args().GetArgOverride(variables::kTargetCpu);
190 if (value != nullptr && value->string_value() == "x64")
191 config_platform_ = "x64";
192
193 switch (version) { 190 switch (version) {
194 case Version::Vs2013: 191 case Version::Vs2013:
195 project_version_ = kProjectVersionVs2013; 192 project_version_ = kProjectVersionVs2013;
196 toolset_version_ = kToolsetVersionVs2013; 193 toolset_version_ = kToolsetVersionVs2013;
197 version_string_ = kVersionStringVs2013; 194 version_string_ = kVersionStringVs2013;
198 break; 195 break;
199 case Version::Vs2015: 196 case Version::Vs2015:
200 project_version_ = kProjectVersionVs2015; 197 project_version_ = kProjectVersionVs2015;
201 toolset_version_ = kToolsetVersionVs2015; 198 toolset_version_ = kToolsetVersionVs2015;
202 version_string_ = kVersionStringVs2015; 199 version_string_ = kVersionStringVs2015;
(...skipping 10 matching lines...) Expand all
213 STLDeleteContainerPointers(folders_.begin(), folders_.end()); 210 STLDeleteContainerPointers(folders_.begin(), folders_.end());
214 } 211 }
215 212
216 // static 213 // static
217 bool VisualStudioWriter::RunAndWriteFiles(const BuildSettings* build_settings, 214 bool VisualStudioWriter::RunAndWriteFiles(const BuildSettings* build_settings,
218 Builder* builder, 215 Builder* builder,
219 Version version, 216 Version version,
220 Err* err) { 217 Err* err) {
221 std::vector<const Target*> targets = builder->GetAllResolvedTargets(); 218 std::vector<const Target*> targets = builder->GetAllResolvedTargets();
222 219
223 VisualStudioWriter writer(build_settings, version); 220 bool is_debug_config = true;
221 const char* config_platform = "Win32";
222
223 // Assume the "is_debug" and "target_cpu" variables do not change
224 // between different toolchains.
brettw 2016/02/24 21:51:48 This is not the case (CPU does change between tool
NGG 2016/02/24 22:19:15 Cross-compiles work with this if only the "current
brettw 2016/02/24 23:38:15 Oh, I missed "target" and I thought you were talki
225 if (!targets.empty()) {
226 const Scope* scope = targets.front()->settings()->base_config();
227 const Value* is_debug_value = scope->GetValue("is_debug");
brettw 2016/02/24 21:51:48 "is_debug" is a variable in the Chrome build, not
NGG 2016/02/24 22:19:15 +1 for this. It could be called "GN". I don't know
Tomasz Moniuszko 2016/02/25 11:06:14 Visual Studio allows to rename configuration to an
228 is_debug_config =
229 is_debug_value == nullptr || is_debug_value->boolean_value();
230 const Value* target_cpu_value = scope->GetValue(variables::kTargetCpu);
231 if (target_cpu_value != nullptr &&
232 target_cpu_value->string_value() == "x64")
233 config_platform = "x64";
234 }
235
236 VisualStudioWriter writer(build_settings, is_debug_config, config_platform,
237 version);
224 writer.projects_.reserve(targets.size()); 238 writer.projects_.reserve(targets.size());
225 writer.folders_.reserve(targets.size()); 239 writer.folders_.reserve(targets.size());
226 240
227 for (const Target* target : targets) { 241 for (const Target* target : targets) {
228 // Skip actions and groups. 242 // Skip actions and groups.
229 if (target->output_type() == Target::GROUP || 243 if (target->output_type() == Target::GROUP ||
230 target->output_type() == Target::COPY_FILES || 244 target->output_type() == Target::COPY_FILES ||
231 target->output_type() == Target::ACTION || 245 target->output_type() == Target::ACTION ||
232 target->output_type() == Target::ACTION_FOREACH) { 246 target->output_type() == Target::ACTION_FOREACH) {
233 continue; 247 continue;
(...skipping 14 matching lines...) Expand all
248 [](const SolutionEntry* a, const SolutionEntry* b) { 262 [](const SolutionEntry* a, const SolutionEntry* b) {
249 return a->path < b->path; 263 return a->path < b->path;
250 }); 264 });
251 265
252 writer.ResolveSolutionFolders(); 266 writer.ResolveSolutionFolders();
253 return writer.WriteSolutionFile(err); 267 return writer.WriteSolutionFile(err);
254 } 268 }
255 269
256 bool VisualStudioWriter::WriteProjectFiles(const Target* target, Err* err) { 270 bool VisualStudioWriter::WriteProjectFiles(const Target* target, Err* err) {
257 std::string project_name = target->label().name(); 271 std::string project_name = target->label().name();
258 std::string project_config_platform = config_platform_; 272 const char* project_config_platform = config_platform_;
259 if (!target->settings()->is_default()) { 273 if (!target->settings()->is_default()) {
260 project_name += "_" + target->toolchain()->label().name(); 274 project_name += "_" + target->toolchain()->label().name();
261 project_config_platform = target->toolchain() 275 const Value* value =
262 ->settings() 276 target->settings()->base_config()->GetValue(variables::kCurrentCpu);
263 ->build_settings() 277 if (value != nullptr && value->string_value() == "x64")
264 ->build_args() 278 project_config_platform = "x64";
265 .GetArgOverride(variables::kCurrentCpu) 279 else
266 ->string_value();
267 if (project_config_platform == "x86")
268 project_config_platform = "Win32"; 280 project_config_platform = "Win32";
269 } 281 }
270 282
271 SourceFile target_file = GetTargetOutputDir(target).ResolveRelativeFile( 283 SourceFile target_file = GetTargetOutputDir(target).ResolveRelativeFile(
272 Value(nullptr, project_name + ".vcxproj"), err); 284 Value(nullptr, project_name + ".vcxproj"), err);
273 if (target_file.is_null()) 285 if (target_file.is_null())
274 return false; 286 return false;
275 287
276 base::FilePath vcxproj_path = build_settings_->GetFullPath(target_file); 288 base::FilePath vcxproj_path = build_settings_->GetFullPath(target_file);
277 std::string vcxproj_path_str = FilePathToUTF8(vcxproj_path); 289 std::string vcxproj_path_str = FilePathToUTF8(vcxproj_path);
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 } 769 }
758 } 770 }
759 771
760 std::string VisualStudioWriter::GetNinjaTarget(const Target* target) { 772 std::string VisualStudioWriter::GetNinjaTarget(const Target* target) {
761 std::ostringstream ninja_target_out; 773 std::ostringstream ninja_target_out;
762 DCHECK(!target->dependency_output_file().value().empty()); 774 DCHECK(!target->dependency_output_file().value().empty());
763 ninja_path_output_.WriteFile(ninja_target_out, 775 ninja_path_output_.WriteFile(ninja_target_out,
764 target->dependency_output_file()); 776 target->dependency_output_file());
765 return ninja_target_out.str(); 777 return ninja_target_out.str();
766 } 778 }
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