summaryrefslogtreecommitdiffstats
path: root/tools/gn/visual_studio_writer.h
blob: bd94f929b7e50214eea0a49f6012f0585e39ad7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef TOOLS_GN_VISUAL_STUDIO_WRITER_H_
#define TOOLS_GN_VISUAL_STUDIO_WRITER_H_

#include <iosfwd>
#include <string>
#include <vector>

#include "base/gtest_prod_util.h"
#include "base/macros.h"

namespace base {
class FilePath;
}

class Builder;
class BuildSettings;
class Err;
class Target;

class VisualStudioWriter {
 public:
  // On failure will populate |err| and will return false.
  static bool RunAndWriteFiles(const BuildSettings* build_settings,
                               Builder* builder,
                               Err* err);

 private:
  FRIEND_TEST_ALL_PREFIXES(VisualStudioWriterTest, ResolveSolutionFolders);
  FRIEND_TEST_ALL_PREFIXES(VisualStudioWriterTest,
                           ResolveSolutionFolders_AbsPath);

  // Solution project or folder.
  struct SolutionEntry {
    SolutionEntry(const std::string& name,
                  const std::string& path,
                  const std::string& guid);
    virtual ~SolutionEntry();

    // Entry name. For projects must be unique in the solution.
    std::string name;
    // Absolute project file or folder directory path.
    std::string path;
    // GUID-like string.
    std::string guid;
    // Pointer to parent folder. nullptr if entry has no parent.
    SolutionEntry* parent_folder;
  };

  struct SolutionProject : public SolutionEntry {
    SolutionProject(const std::string& name,
                    const std::string& path,
                    const std::string& guid,
                    const std::string& label_dir_path,
                    const std::string& config_platform);
    ~SolutionProject() override;

    // Absolute label dir path.
    std::string label_dir_path;
    // Configuration platform. May be different than solution config platform.
    std::string config_platform;
  };

  using SolutionProjects = std::vector<SolutionProject*>;
  using SolutionFolders = std::vector<SolutionEntry*>;

  explicit VisualStudioWriter(const BuildSettings* build_settings);
  ~VisualStudioWriter();

  bool WriteProjectFiles(const Target* target, Err* err);
  bool WriteProjectFileContents(std::ostream& out,
                                const SolutionProject& solution_project,
                                const Target* target,
                                Err* err);
  void WriteFiltersFileContents(std::ostream& out, const Target* target);
  bool WriteSolutionFile(Err* err);
  void WriteSolutionFileContents(std::ostream& out,
                                 const base::FilePath& solution_dir_path);

  // Resolves all solution folders (parent folders for projects) into |folders_|
  // and updates |root_folder_dir_|. Also sets |parent_folder| for |projects_|.
  void ResolveSolutionFolders();

  const BuildSettings* build_settings_;

  // Indicates if project files are generated for Debug mode configuration.
  bool is_debug_config_;

  // Platform for solution configuration (Win32, x64). Some projects may be
  // configured for different platform.
  std::string config_platform_;

  // All projects contained by solution.
  SolutionProjects projects_;

  // Absolute root solution folder path.
  std::string root_folder_path_;

  // Folders for all solution projects.
  SolutionFolders folders_;

  // Semicolon-separated Windows SDK include directories.
  std::string windows_kits_include_dirs_;

  DISALLOW_COPY_AND_ASSIGN(VisualStudioWriter);
};

#endif  // TOOLS_GN_VISUAL_STUDIO_WRITER_H_