• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_XCODE_WRITER_H_
6 #define TOOLS_GN_XCODE_WRITER_H_
7 
8 #include <iosfwd>
9 #include <map>
10 #include <memory>
11 #include <string>
12 #include <vector>
13 
14 #include "base/macros.h"
15 
16 class Builder;
17 class BuildSettings;
18 class Err;
19 class Target;
20 
21 using PBXAttributes = std::map<std::string, std::string>;
22 class PBXProject;
23 
24 class XcodeWriter {
25  public:
26   enum TargetOsType {
27     WRITER_TARGET_OS_IOS,
28     WRITER_TARGET_OS_MACOS,
29   };
30 
31   // Writes Xcode workspace and project files.
32   //
33   // |workspace_name| is the optional name of the workspace file name ("all"
34   // is used if not specified). |root_target_name| is the name of the main
35   // target corresponding to building "All" (for example "gn_all" in Chromium).
36   // |ninja_executable| can be used to control which ninja executable will be
37   // run. When empty, regular ninja will be used.
38   // |ninja_extra_args| are additional arguments to pass to ninja invocation
39   // (can be used to increase limit of concurrent processes when using goma).
40   // |dir_filters_string| is optional semicolon-separated list of label patterns
41   // used to limit the set of generated projects. Only matching targets will be
42   // included to the workspace. On failure will populate |err| and return false.
43   static bool RunAndWriteFiles(const std::string& workspace_name,
44                                const std::string& root_target_name,
45                                const std::string& ninja_executable,
46                                const std::string& ninja_extra_args,
47                                const std::string& dir_filters_string,
48                                const BuildSettings* build_settings,
49                                const Builder& builder,
50                                Err* err);
51 
52  private:
53   XcodeWriter(const std::string& name);
54   ~XcodeWriter();
55 
56   // Filters the list of targets to only return the targets with artifacts
57   // usable from Xcode (mostly application bundles). On failure populate |err|
58   // and return false.
59   static bool FilterTargets(const BuildSettings* build_settings,
60                             const std::vector<const Target*>& all_targets,
61                             const std::string& dir_filters_string,
62                             std::vector<const Target*>* targets,
63                             Err* err);
64 
65   // Generate the "products.xcodeproj" project that reference all products
66   // (i.e. targets that have a build artefact usable from Xcode, mostly
67   // application bundles).
68   void CreateProductsProject(const std::vector<const Target*>& targets,
69                              const std::vector<const Target*>& all_targets,
70                              const PBXAttributes& attributes,
71                              const std::string& source_path,
72                              const std::string& config_name,
73                              const std::string& root_target,
74                              const std::string& ninja_executable,
75                              const std::string& ninja_extra_args,
76                              const BuildSettings* build_settings,
77                              TargetOsType target_os);
78 
79   bool WriteFiles(const BuildSettings* build_settings, Err* err);
80   bool WriteProjectFile(const BuildSettings* build_settings,
81                         PBXProject* project,
82                         Err* err);
83 
84   void WriteWorkspaceContent(std::ostream& out);
85   void WriteProjectContent(std::ostream& out, PBXProject* project);
86 
87   std::string name_;
88   std::vector<std::unique_ptr<PBXProject>> projects_;
89 
90   DISALLOW_COPY_AND_ASSIGN(XcodeWriter);
91 };
92 
93 #endif  // TOOLS_GN_XCODE_WRITER_H_
94