blob: db2f3eab077c1a9ab888c8ed810eee62ec021656 [file] [log] [blame]
tmoniuszko050f20692016-01-29 16:15:361// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef TOOLS_GN_VISUAL_STUDIO_WRITER_H_
6#define TOOLS_GN_VISUAL_STUDIO_WRITER_H_
7
8#include <iosfwd>
jbroman31500012016-04-18 21:22:189#include <memory>
tmoniuszko050f20692016-01-29 16:15:3610#include <string>
11#include <vector>
12
13#include "base/gtest_prod_util.h"
14#include "base/macros.h"
nggd8d1d8e72016-02-24 13:05:4415#include "tools/gn/path_output.h"
tmoniuszko050f20692016-01-29 16:15:3616
17namespace base {
18class FilePath;
19}
20
21class Builder;
22class BuildSettings;
23class Err;
ngg3dbc8132016-04-25 10:37:1424class SourceFile;
tmoniuszko050f20692016-01-29 16:15:3625class Target;
26
27class VisualStudioWriter {
28 public:
nggd0bc0fa2016-02-22 23:18:4829 enum Version {
30 Vs2013 = 1, // Visual Studio 2013
alexis.menardc20ee8682017-03-13 18:40:5431 Vs2015, // Visual Studio 2015
32 Vs2017 // Visual Studio 2017
nggd0bc0fa2016-02-22 23:18:4833 };
34
tmoniuszko014e81d2016-02-26 12:24:5135 // Writes Visual Studio project and solution files. |sln_name| is the optional
tmoniuszko64edbcf2016-08-03 11:34:1736 // solution file name ("all" is used if not specified). |filters| is optional
37 // semicolon-separated list of label patterns used to limit the set of
38 // generated projects. Only matching targets and their dependencies (unless
39 // |no_deps| is true) will be included to the solution. On failure will
Andrew Boyarshin8480d8662017-06-17 14:34:3040 // populate |err| and will return false. |win_sdk| is the Windows SDK version
41 // which will be used by Visual Studio IntelliSense.
tmoniuszko050f20692016-01-29 16:15:3642 static bool RunAndWriteFiles(const BuildSettings* build_settings,
brettw8293c352016-07-26 20:38:3743 const Builder& builder,
nggd0bc0fa2016-02-22 23:18:4844 Version version,
tmoniuszko014e81d2016-02-26 12:24:5145 const std::string& sln_name,
tmoniuszko64edbcf2016-08-03 11:34:1746 const std::string& filters,
Andrew Boyarshin8480d8662017-06-17 14:34:3047 const std::string& win_sdk,
tmoniuszko64edbcf2016-08-03 11:34:1748 bool no_deps,
tmoniuszko050f20692016-01-29 16:15:3649 Err* err);
50
51 private:
52 FRIEND_TEST_ALL_PREFIXES(VisualStudioWriterTest, ResolveSolutionFolders);
53 FRIEND_TEST_ALL_PREFIXES(VisualStudioWriterTest,
54 ResolveSolutionFolders_AbsPath);
55
56 // Solution project or folder.
57 struct SolutionEntry {
58 SolutionEntry(const std::string& name,
59 const std::string& path,
60 const std::string& guid);
tmoniuszkobc312ac42016-02-04 10:53:3361 virtual ~SolutionEntry();
tmoniuszko050f20692016-01-29 16:15:3662
63 // Entry name. For projects must be unique in the solution.
64 std::string name;
65 // Absolute project file or folder directory path.
66 std::string path;
tmoniuszko050f20692016-01-29 16:15:3667 // GUID-like string.
68 std::string guid;
69 // Pointer to parent folder. nullptr if entry has no parent.
70 SolutionEntry* parent_folder;
71 };
72
tmoniuszkobc312ac42016-02-04 10:53:3373 struct SolutionProject : public SolutionEntry {
74 SolutionProject(const std::string& name,
75 const std::string& path,
76 const std::string& guid,
77 const std::string& label_dir_path,
78 const std::string& config_platform);
79 ~SolutionProject() override;
80
81 // Absolute label dir path.
82 std::string label_dir_path;
83 // Configuration platform. May be different than solution config platform.
84 std::string config_platform;
85 };
86
ngg3dbc8132016-04-25 10:37:1487 struct SourceFileCompileTypePair {
88 SourceFileCompileTypePair(const SourceFile* file, const char* compile_type);
89 ~SourceFileCompileTypePair();
90
91 // Source file.
92 const SourceFile* file;
93 // Compile type string.
94 const char* compile_type;
95 };
96
jbroman31500012016-04-18 21:22:1897 using SolutionProjects = std::vector<std::unique_ptr<SolutionProject>>;
98 using SolutionFolders = std::vector<std::unique_ptr<SolutionEntry>>;
ngg3dbc8132016-04-25 10:37:1499 using SourceFileCompileTypePairs = std::vector<SourceFileCompileTypePair>;
tmoniuszko050f20692016-01-29 16:15:36100
tmoniuszko014e81d2016-02-26 12:24:51101 VisualStudioWriter(const BuildSettings* build_settings,
102 const char* config_platform,
Andrew Boyarshin8480d8662017-06-17 14:34:30103 Version version,
104 const std::string& win_kit);
tmoniuszko050f20692016-01-29 16:15:36105 ~VisualStudioWriter();
106
107 bool WriteProjectFiles(const Target* target, Err* err);
108 bool WriteProjectFileContents(std::ostream& out,
tmoniuszkobc312ac42016-02-04 10:53:33109 const SolutionProject& solution_project,
tmoniuszko050f20692016-01-29 16:15:36110 const Target* target,
ngg3dbc8132016-04-25 10:37:14111 SourceFileCompileTypePairs* source_types,
tmoniuszko050f20692016-01-29 16:15:36112 Err* err);
ngg3dbc8132016-04-25 10:37:14113 void WriteFiltersFileContents(std::ostream& out,
114 const Target* target,
115 const SourceFileCompileTypePairs& source_types);
tmoniuszko014e81d2016-02-26 12:24:51116 bool WriteSolutionFile(const std::string& sln_name, Err* err);
tmoniuszko050f20692016-01-29 16:15:36117 void WriteSolutionFileContents(std::ostream& out,
118 const base::FilePath& solution_dir_path);
119
120 // Resolves all solution folders (parent folders for projects) into |folders_|
121 // and updates |root_folder_dir_|. Also sets |parent_folder| for |projects_|.
122 void ResolveSolutionFolders();
123
nggd8d1d8e72016-02-24 13:05:44124 std::string GetNinjaTarget(const Target* target);
125
tmoniuszko050f20692016-01-29 16:15:36126 const BuildSettings* build_settings_;
127
nggd0bc0fa2016-02-22 23:18:48128 // Toolset version.
129 const char* toolset_version_;
130
131 // Project version.
132 const char* project_version_;
133
134 // Visual Studio version string.
135 const char* version_string_;
136
tmoniuszkobc312ac42016-02-04 10:53:33137 // Platform for solution configuration (Win32, x64). Some projects may be
138 // configured for different platform.
ngg5dd34fc2016-02-25 14:51:58139 const char* config_platform_;
tmoniuszko050f20692016-01-29 16:15:36140
141 // All projects contained by solution.
tmoniuszkobc312ac42016-02-04 10:53:33142 SolutionProjects projects_;
tmoniuszko050f20692016-01-29 16:15:36143
144 // Absolute root solution folder path.
145 std::string root_folder_path_;
146
147 // Folders for all solution projects.
tmoniuszkobc312ac42016-02-04 10:53:33148 SolutionFolders folders_;
tmoniuszko050f20692016-01-29 16:15:36149
150 // Semicolon-separated Windows SDK include directories.
151 std::string windows_kits_include_dirs_;
152
nggd8d1d8e72016-02-24 13:05:44153 // Path formatter for ninja targets.
154 PathOutput ninja_path_output_;
155
Andrew Boyarshin8480d8662017-06-17 14:34:30156 // Windows 10 SDK version string (e.g. 10.0.14393.0)
157 std::string windows_sdk_version_;
158
tmoniuszko050f20692016-01-29 16:15:36159 DISALLOW_COPY_AND_ASSIGN(VisualStudioWriter);
160};
161
162#endif // TOOLS_GN_VISUAL_STUDIO_WRITER_H_