tmoniuszko | 050f2069 | 2016-01-29 16:15:36 | [diff] [blame] | 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 |
| 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> |
jbroman | 3150001 | 2016-04-18 21:22:18 | [diff] [blame] | 9 | #include <memory> |
tmoniuszko | 050f2069 | 2016-01-29 16:15:36 | [diff] [blame] | 10 | #include <string> |
| 11 | #include <vector> |
| 12 | |
| 13 | #include "base/gtest_prod_util.h" |
| 14 | #include "base/macros.h" |
ngg | d8d1d8e7 | 2016-02-24 13:05:44 | [diff] [blame] | 15 | #include "tools/gn/path_output.h" |
tmoniuszko | 050f2069 | 2016-01-29 16:15:36 | [diff] [blame] | 16 | |
| 17 | namespace base { |
| 18 | class FilePath; |
| 19 | } |
| 20 | |
| 21 | class Builder; |
| 22 | class BuildSettings; |
| 23 | class Err; |
ngg | 3dbc813 | 2016-04-25 10:37:14 | [diff] [blame] | 24 | class SourceFile; |
tmoniuszko | 050f2069 | 2016-01-29 16:15:36 | [diff] [blame] | 25 | class Target; |
| 26 | |
| 27 | class VisualStudioWriter { |
| 28 | public: |
ngg | d0bc0fa | 2016-02-22 23:18:48 | [diff] [blame] | 29 | enum Version { |
| 30 | Vs2013 = 1, // Visual Studio 2013 |
| 31 | Vs2015 // Visual Studio 2015 |
| 32 | }; |
| 33 | |
tmoniuszko | 014e81d | 2016-02-26 12:24:51 | [diff] [blame] | 34 | // Writes Visual Studio project and solution files. |sln_name| is the optional |
tmoniuszko | 64edbcf | 2016-08-03 11:34:17 | [diff] [blame] | 35 | // solution file name ("all" is used if not specified). |filters| is optional |
| 36 | // semicolon-separated list of label patterns used to limit the set of |
| 37 | // generated projects. Only matching targets and their dependencies (unless |
| 38 | // |no_deps| is true) will be included to the solution. On failure will |
| 39 | // populate |err| and will return false. |
tmoniuszko | 050f2069 | 2016-01-29 16:15:36 | [diff] [blame] | 40 | static bool RunAndWriteFiles(const BuildSettings* build_settings, |
brettw | 8293c35 | 2016-07-26 20:38:37 | [diff] [blame] | 41 | const Builder& builder, |
ngg | d0bc0fa | 2016-02-22 23:18:48 | [diff] [blame] | 42 | Version version, |
tmoniuszko | 014e81d | 2016-02-26 12:24:51 | [diff] [blame] | 43 | const std::string& sln_name, |
tmoniuszko | 64edbcf | 2016-08-03 11:34:17 | [diff] [blame] | 44 | const std::string& filters, |
| 45 | bool no_deps, |
tmoniuszko | 050f2069 | 2016-01-29 16:15:36 | [diff] [blame] | 46 | Err* err); |
| 47 | |
| 48 | private: |
| 49 | FRIEND_TEST_ALL_PREFIXES(VisualStudioWriterTest, ResolveSolutionFolders); |
| 50 | FRIEND_TEST_ALL_PREFIXES(VisualStudioWriterTest, |
| 51 | ResolveSolutionFolders_AbsPath); |
| 52 | |
| 53 | // Solution project or folder. |
| 54 | struct SolutionEntry { |
| 55 | SolutionEntry(const std::string& name, |
| 56 | const std::string& path, |
| 57 | const std::string& guid); |
tmoniuszko | bc312ac4 | 2016-02-04 10:53:33 | [diff] [blame] | 58 | virtual ~SolutionEntry(); |
tmoniuszko | 050f2069 | 2016-01-29 16:15:36 | [diff] [blame] | 59 | |
| 60 | // Entry name. For projects must be unique in the solution. |
| 61 | std::string name; |
| 62 | // Absolute project file or folder directory path. |
| 63 | std::string path; |
tmoniuszko | 050f2069 | 2016-01-29 16:15:36 | [diff] [blame] | 64 | // GUID-like string. |
| 65 | std::string guid; |
| 66 | // Pointer to parent folder. nullptr if entry has no parent. |
| 67 | SolutionEntry* parent_folder; |
| 68 | }; |
| 69 | |
tmoniuszko | bc312ac4 | 2016-02-04 10:53:33 | [diff] [blame] | 70 | struct SolutionProject : public SolutionEntry { |
| 71 | SolutionProject(const std::string& name, |
| 72 | const std::string& path, |
| 73 | const std::string& guid, |
| 74 | const std::string& label_dir_path, |
| 75 | const std::string& config_platform); |
| 76 | ~SolutionProject() override; |
| 77 | |
| 78 | // Absolute label dir path. |
| 79 | std::string label_dir_path; |
| 80 | // Configuration platform. May be different than solution config platform. |
| 81 | std::string config_platform; |
| 82 | }; |
| 83 | |
ngg | 3dbc813 | 2016-04-25 10:37:14 | [diff] [blame] | 84 | struct SourceFileCompileTypePair { |
| 85 | SourceFileCompileTypePair(const SourceFile* file, const char* compile_type); |
| 86 | ~SourceFileCompileTypePair(); |
| 87 | |
| 88 | // Source file. |
| 89 | const SourceFile* file; |
| 90 | // Compile type string. |
| 91 | const char* compile_type; |
| 92 | }; |
| 93 | |
jbroman | 3150001 | 2016-04-18 21:22:18 | [diff] [blame] | 94 | using SolutionProjects = std::vector<std::unique_ptr<SolutionProject>>; |
| 95 | using SolutionFolders = std::vector<std::unique_ptr<SolutionEntry>>; |
ngg | 3dbc813 | 2016-04-25 10:37:14 | [diff] [blame] | 96 | using SourceFileCompileTypePairs = std::vector<SourceFileCompileTypePair>; |
tmoniuszko | 050f2069 | 2016-01-29 16:15:36 | [diff] [blame] | 97 | |
tmoniuszko | 014e81d | 2016-02-26 12:24:51 | [diff] [blame] | 98 | VisualStudioWriter(const BuildSettings* build_settings, |
| 99 | const char* config_platform, |
| 100 | Version version); |
tmoniuszko | 050f2069 | 2016-01-29 16:15:36 | [diff] [blame] | 101 | ~VisualStudioWriter(); |
| 102 | |
| 103 | bool WriteProjectFiles(const Target* target, Err* err); |
| 104 | bool WriteProjectFileContents(std::ostream& out, |
tmoniuszko | bc312ac4 | 2016-02-04 10:53:33 | [diff] [blame] | 105 | const SolutionProject& solution_project, |
tmoniuszko | 050f2069 | 2016-01-29 16:15:36 | [diff] [blame] | 106 | const Target* target, |
ngg | 3dbc813 | 2016-04-25 10:37:14 | [diff] [blame] | 107 | SourceFileCompileTypePairs* source_types, |
tmoniuszko | 050f2069 | 2016-01-29 16:15:36 | [diff] [blame] | 108 | Err* err); |
ngg | 3dbc813 | 2016-04-25 10:37:14 | [diff] [blame] | 109 | void WriteFiltersFileContents(std::ostream& out, |
| 110 | const Target* target, |
| 111 | const SourceFileCompileTypePairs& source_types); |
tmoniuszko | 014e81d | 2016-02-26 12:24:51 | [diff] [blame] | 112 | bool WriteSolutionFile(const std::string& sln_name, Err* err); |
tmoniuszko | 050f2069 | 2016-01-29 16:15:36 | [diff] [blame] | 113 | void WriteSolutionFileContents(std::ostream& out, |
| 114 | const base::FilePath& solution_dir_path); |
| 115 | |
| 116 | // Resolves all solution folders (parent folders for projects) into |folders_| |
| 117 | // and updates |root_folder_dir_|. Also sets |parent_folder| for |projects_|. |
| 118 | void ResolveSolutionFolders(); |
| 119 | |
ngg | d8d1d8e7 | 2016-02-24 13:05:44 | [diff] [blame] | 120 | std::string GetNinjaTarget(const Target* target); |
| 121 | |
tmoniuszko | 050f2069 | 2016-01-29 16:15:36 | [diff] [blame] | 122 | const BuildSettings* build_settings_; |
| 123 | |
ngg | d0bc0fa | 2016-02-22 23:18:48 | [diff] [blame] | 124 | // Toolset version. |
| 125 | const char* toolset_version_; |
| 126 | |
| 127 | // Project version. |
| 128 | const char* project_version_; |
| 129 | |
| 130 | // Visual Studio version string. |
| 131 | const char* version_string_; |
| 132 | |
tmoniuszko | bc312ac4 | 2016-02-04 10:53:33 | [diff] [blame] | 133 | // Platform for solution configuration (Win32, x64). Some projects may be |
| 134 | // configured for different platform. |
ngg | 5dd34fc | 2016-02-25 14:51:58 | [diff] [blame] | 135 | const char* config_platform_; |
tmoniuszko | 050f2069 | 2016-01-29 16:15:36 | [diff] [blame] | 136 | |
| 137 | // All projects contained by solution. |
tmoniuszko | bc312ac4 | 2016-02-04 10:53:33 | [diff] [blame] | 138 | SolutionProjects projects_; |
tmoniuszko | 050f2069 | 2016-01-29 16:15:36 | [diff] [blame] | 139 | |
| 140 | // Absolute root solution folder path. |
| 141 | std::string root_folder_path_; |
| 142 | |
| 143 | // Folders for all solution projects. |
tmoniuszko | bc312ac4 | 2016-02-04 10:53:33 | [diff] [blame] | 144 | SolutionFolders folders_; |
tmoniuszko | 050f2069 | 2016-01-29 16:15:36 | [diff] [blame] | 145 | |
| 146 | // Semicolon-separated Windows SDK include directories. |
| 147 | std::string windows_kits_include_dirs_; |
| 148 | |
ngg | d8d1d8e7 | 2016-02-24 13:05:44 | [diff] [blame] | 149 | // Path formatter for ninja targets. |
| 150 | PathOutput ninja_path_output_; |
| 151 | |
tmoniuszko | 050f2069 | 2016-01-29 16:15:36 | [diff] [blame] | 152 | DISALLOW_COPY_AND_ASSIGN(VisualStudioWriter); |
| 153 | }; |
| 154 | |
| 155 | #endif // TOOLS_GN_VISUAL_STUDIO_WRITER_H_ |