blob: 639be09e315c73d2fa7bac285a944817b58cbaca [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
31 Vs2015 // Visual Studio 2015
32 };
33
tmoniuszko014e81d2016-02-26 12:24:5134 // Writes Visual Studio project and solution files. |sln_name| is the optional
tmoniuszko64edbcf2016-08-03 11:34:1735 // 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.
tmoniuszko050f20692016-01-29 16:15:3640 static bool RunAndWriteFiles(const BuildSettings* build_settings,
brettw8293c352016-07-26 20:38:3741 const Builder& builder,
nggd0bc0fa2016-02-22 23:18:4842 Version version,
tmoniuszko014e81d2016-02-26 12:24:5143 const std::string& sln_name,
tmoniuszko64edbcf2016-08-03 11:34:1744 const std::string& filters,
45 bool no_deps,
tmoniuszko050f20692016-01-29 16:15:3646 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);
tmoniuszkobc312ac42016-02-04 10:53:3358 virtual ~SolutionEntry();
tmoniuszko050f20692016-01-29 16:15:3659
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;
tmoniuszko050f20692016-01-29 16:15:3664 // GUID-like string.
65 std::string guid;
66 // Pointer to parent folder. nullptr if entry has no parent.
67 SolutionEntry* parent_folder;
68 };
69
tmoniuszkobc312ac42016-02-04 10:53:3370 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
ngg3dbc8132016-04-25 10:37:1484 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
jbroman31500012016-04-18 21:22:1894 using SolutionProjects = std::vector<std::unique_ptr<SolutionProject>>;
95 using SolutionFolders = std::vector<std::unique_ptr<SolutionEntry>>;
ngg3dbc8132016-04-25 10:37:1496 using SourceFileCompileTypePairs = std::vector<SourceFileCompileTypePair>;
tmoniuszko050f20692016-01-29 16:15:3697
tmoniuszko014e81d2016-02-26 12:24:5198 VisualStudioWriter(const BuildSettings* build_settings,
99 const char* config_platform,
100 Version version);
tmoniuszko050f20692016-01-29 16:15:36101 ~VisualStudioWriter();
102
103 bool WriteProjectFiles(const Target* target, Err* err);
104 bool WriteProjectFileContents(std::ostream& out,
tmoniuszkobc312ac42016-02-04 10:53:33105 const SolutionProject& solution_project,
tmoniuszko050f20692016-01-29 16:15:36106 const Target* target,
ngg3dbc8132016-04-25 10:37:14107 SourceFileCompileTypePairs* source_types,
tmoniuszko050f20692016-01-29 16:15:36108 Err* err);
ngg3dbc8132016-04-25 10:37:14109 void WriteFiltersFileContents(std::ostream& out,
110 const Target* target,
111 const SourceFileCompileTypePairs& source_types);
tmoniuszko014e81d2016-02-26 12:24:51112 bool WriteSolutionFile(const std::string& sln_name, Err* err);
tmoniuszko050f20692016-01-29 16:15:36113 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
nggd8d1d8e72016-02-24 13:05:44120 std::string GetNinjaTarget(const Target* target);
121
tmoniuszko050f20692016-01-29 16:15:36122 const BuildSettings* build_settings_;
123
nggd0bc0fa2016-02-22 23:18:48124 // 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
tmoniuszkobc312ac42016-02-04 10:53:33133 // Platform for solution configuration (Win32, x64). Some projects may be
134 // configured for different platform.
ngg5dd34fc2016-02-25 14:51:58135 const char* config_platform_;
tmoniuszko050f20692016-01-29 16:15:36136
137 // All projects contained by solution.
tmoniuszkobc312ac42016-02-04 10:53:33138 SolutionProjects projects_;
tmoniuszko050f20692016-01-29 16:15:36139
140 // Absolute root solution folder path.
141 std::string root_folder_path_;
142
143 // Folders for all solution projects.
tmoniuszkobc312ac42016-02-04 10:53:33144 SolutionFolders folders_;
tmoniuszko050f20692016-01-29 16:15:36145
146 // Semicolon-separated Windows SDK include directories.
147 std::string windows_kits_include_dirs_;
148
nggd8d1d8e72016-02-24 13:05:44149 // Path formatter for ninja targets.
150 PathOutput ninja_path_output_;
151
tmoniuszko050f20692016-01-29 16:15:36152 DISALLOW_COPY_AND_ASSIGN(VisualStudioWriter);
153};
154
155#endif // TOOLS_GN_VISUAL_STUDIO_WRITER_H_