OLD | NEW |
(Empty) | |
| 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_OBJECT_H_ |
| 6 #define TOOLS_GN_XCODE_OBJECT_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 // Helper classes to generate Xcode project files. |
| 17 // |
| 18 // This code is based on gyp xcodeproj_file.py generator. It does not support |
| 19 // all features of Xcode project but instead just enough to implement a hybrid |
| 20 // mode where Xcode uses external scripts to perform the compilation steps. |
| 21 // |
| 22 // See https://chromium.googlesource.com/external/gyp/+/master/pylib/gyp/xcodepr
oj_file.py |
| 23 // for more information on Xcode project file format. |
| 24 |
| 25 // PBXObjectClass ------------------------------------------------------------- |
| 26 |
| 27 enum PBXObjectClass { |
| 28 // Those values needs to stay sorted in alphabetic order. |
| 29 PBXAggregateTargetClass, |
| 30 PBXBuildFileClass, |
| 31 PBXFileReferenceClass, |
| 32 PBXFrameworksBuildPhaseClass, |
| 33 PBXGroupClass, |
| 34 PBXNativeTargetClass, |
| 35 PBXProjectClass, |
| 36 PBXShellScriptBuildPhaseClass, |
| 37 PBXSourcesBuildPhaseClass, |
| 38 XCBuildConfigurationClass, |
| 39 XCConfigurationListClass, |
| 40 }; |
| 41 |
| 42 const char* ToString(PBXObjectClass cls); |
| 43 |
| 44 // Forward-declarations ------------------------------------------------------- |
| 45 |
| 46 class PBXAggregateTarget; |
| 47 class PBXBuildFile; |
| 48 class PBXFileReference; |
| 49 class PBXBuildPhase; |
| 50 class PBXFrameworksBuildPhase; |
| 51 class PBXGroup; |
| 52 class PBXNativeTarget; |
| 53 class PBXObject; |
| 54 class PBXProject; |
| 55 class PBXShellScriptBuildPhase; |
| 56 class PBXSourcesBuildPhase; |
| 57 class PBXTarget; |
| 58 class XCBuildConfiguration; |
| 59 class XCConfigurationList; |
| 60 |
| 61 using PBXAttributes = std::map<std::string, std::string>; |
| 62 |
| 63 // PBXObjectVisitor ----------------------------------------------------------- |
| 64 |
| 65 class PBXObjectVisitor { |
| 66 public: |
| 67 PBXObjectVisitor(); |
| 68 virtual ~PBXObjectVisitor(); |
| 69 virtual void Visit(PBXObject* object) = 0; |
| 70 |
| 71 private: |
| 72 DISALLOW_COPY_AND_ASSIGN(PBXObjectVisitor); |
| 73 }; |
| 74 |
| 75 // PBXObject ------------------------------------------------------------------ |
| 76 |
| 77 class PBXObject { |
| 78 public: |
| 79 PBXObject(); |
| 80 virtual ~PBXObject(); |
| 81 |
| 82 const std::string id() const { return id_; } |
| 83 void SetId(const std::string& id); |
| 84 |
| 85 std::string Reference() const; |
| 86 |
| 87 virtual PBXObjectClass Class() const = 0; |
| 88 virtual std::string Name() const = 0; |
| 89 virtual std::string Comment() const; |
| 90 virtual void Visit(PBXObjectVisitor& visitor); |
| 91 virtual void Print(std::ostream& out, unsigned indent) const = 0; |
| 92 |
| 93 private: |
| 94 std::string id_; |
| 95 |
| 96 DISALLOW_COPY_AND_ASSIGN(PBXObject); |
| 97 }; |
| 98 |
| 99 // PBXBuildPhase -------------------------------------------------------------- |
| 100 |
| 101 class PBXBuildPhase : public PBXObject { |
| 102 public: |
| 103 PBXBuildPhase(); |
| 104 ~PBXBuildPhase() override; |
| 105 |
| 106 private: |
| 107 DISALLOW_COPY_AND_ASSIGN(PBXBuildPhase); |
| 108 }; |
| 109 |
| 110 // PBXTarget ------------------------------------------------------------------ |
| 111 |
| 112 class PBXTarget : public PBXObject { |
| 113 public: |
| 114 PBXTarget(const std::string& name, |
| 115 const std::string& shell_script, |
| 116 const std::string& config_name, |
| 117 const PBXAttributes& attributes); |
| 118 ~PBXTarget() override; |
| 119 |
| 120 // PXBObject implementation. |
| 121 std::string Name() const override; |
| 122 void Visit(PBXObjectVisitor& visitor) override; |
| 123 |
| 124 protected: |
| 125 std::unique_ptr<XCConfigurationList> configurations_; |
| 126 std::vector<std::unique_ptr<PBXBuildPhase>> build_phases_; |
| 127 PBXSourcesBuildPhase* source_build_phase_; |
| 128 std::string name_; |
| 129 |
| 130 private: |
| 131 DISALLOW_COPY_AND_ASSIGN(PBXTarget); |
| 132 }; |
| 133 |
| 134 // PBXAggregateTarget --------------------------------------------------------- |
| 135 |
| 136 class PBXAggregateTarget : public PBXTarget { |
| 137 public: |
| 138 PBXAggregateTarget(const std::string& name, |
| 139 const std::string& shell_script, |
| 140 const std::string& config_name, |
| 141 const PBXAttributes& attributes); |
| 142 ~PBXAggregateTarget() override; |
| 143 |
| 144 // PXBObject implementation. |
| 145 PBXObjectClass Class() const override; |
| 146 void Print(std::ostream& out, unsigned indent) const override; |
| 147 |
| 148 private: |
| 149 DISALLOW_COPY_AND_ASSIGN(PBXAggregateTarget); |
| 150 }; |
| 151 |
| 152 // PBXBuildFile --------------------------------------------------------------- |
| 153 |
| 154 class PBXBuildFile : public PBXObject { |
| 155 public: |
| 156 PBXBuildFile(const PBXFileReference* file_reference, |
| 157 const PBXSourcesBuildPhase* build_phase); |
| 158 ~PBXBuildFile() override; |
| 159 |
| 160 // PXBObject implementation. |
| 161 PBXObjectClass Class() const override; |
| 162 std::string Name() const override; |
| 163 void Print(std::ostream& out, unsigned indent) const override; |
| 164 |
| 165 private: |
| 166 const PBXFileReference* file_reference_; |
| 167 const PBXSourcesBuildPhase* build_phase_; |
| 168 |
| 169 DISALLOW_COPY_AND_ASSIGN(PBXBuildFile); |
| 170 }; |
| 171 |
| 172 // PBXFileReference ----------------------------------------------------------- |
| 173 |
| 174 class PBXFileReference : public PBXObject { |
| 175 public: |
| 176 PBXFileReference(const std::string& name, |
| 177 const std::string& path, |
| 178 const std::string& type); |
| 179 ~PBXFileReference() override; |
| 180 |
| 181 // PBXObject implementation. |
| 182 PBXObjectClass Class() const override; |
| 183 std::string Name() const override; |
| 184 void Print(std::ostream& out, unsigned indent) const override; |
| 185 |
| 186 private: |
| 187 std::string name_; |
| 188 std::string path_; |
| 189 std::string type_; |
| 190 |
| 191 DISALLOW_COPY_AND_ASSIGN(PBXFileReference); |
| 192 }; |
| 193 |
| 194 // PBXFrameworksBuildPhase ---------------------------------------------------- |
| 195 |
| 196 class PBXFrameworksBuildPhase : public PBXBuildPhase { |
| 197 public: |
| 198 PBXFrameworksBuildPhase(); |
| 199 ~PBXFrameworksBuildPhase() override; |
| 200 |
| 201 // PBXObject implementation. |
| 202 PBXObjectClass Class() const override; |
| 203 std::string Name() const override; |
| 204 void Print(std::ostream& out, unsigned indent) const override; |
| 205 |
| 206 private: |
| 207 DISALLOW_COPY_AND_ASSIGN(PBXFrameworksBuildPhase); |
| 208 }; |
| 209 |
| 210 // PBXGroup ------------------------------------------------------------------- |
| 211 |
| 212 class PBXGroup : public PBXObject { |
| 213 public: |
| 214 explicit PBXGroup(const std::string& path = std::string(), |
| 215 const std::string& name = std::string()); |
| 216 ~PBXGroup() override; |
| 217 |
| 218 const std::string& path() const { return path_; } |
| 219 |
| 220 PBXObject* AddChild(std::unique_ptr<PBXObject> child); |
| 221 PBXFileReference* AddSourceFile(const std::string& source_path); |
| 222 |
| 223 // PBXObject implementation. |
| 224 PBXObjectClass Class() const override; |
| 225 std::string Name() const override; |
| 226 void Visit(PBXObjectVisitor& visitor) override; |
| 227 void Print(std::ostream& out, unsigned indent) const override; |
| 228 |
| 229 private: |
| 230 std::vector<std::unique_ptr<PBXObject>> children_; |
| 231 std::string name_; |
| 232 std::string path_; |
| 233 |
| 234 DISALLOW_COPY_AND_ASSIGN(PBXGroup); |
| 235 }; |
| 236 |
| 237 // PBXNativeTarget ------------------------------------------------------------ |
| 238 |
| 239 class PBXNativeTarget : public PBXTarget { |
| 240 public: |
| 241 PBXNativeTarget(const std::string& name, |
| 242 const std::string& shell_script, |
| 243 const std::string& config_name, |
| 244 const PBXAttributes& attributes, |
| 245 const std::string& product_type, |
| 246 const PBXFileReference* product_reference); |
| 247 ~PBXNativeTarget() override; |
| 248 |
| 249 void AddFileForIndexing(const PBXFileReference* file_reference); |
| 250 |
| 251 // PBXObject implementation. |
| 252 PBXObjectClass Class() const override; |
| 253 void Print(std::ostream& out, unsigned indent) const override; |
| 254 |
| 255 private: |
| 256 const PBXFileReference* product_reference_; |
| 257 std::string product_type_; |
| 258 |
| 259 DISALLOW_COPY_AND_ASSIGN(PBXNativeTarget); |
| 260 }; |
| 261 |
| 262 // PBXProject ----------------------------------------------------------------- |
| 263 |
| 264 class PBXProject : public PBXObject { |
| 265 public: |
| 266 PBXProject(const std::string& name, |
| 267 const std::string& config_name, |
| 268 const std::string& source_path, |
| 269 const PBXAttributes& attributes); |
| 270 ~PBXProject() override; |
| 271 |
| 272 void AddSourceFile(const std::string& source_path); |
| 273 void AddAggregateTarget(const std::string& name, |
| 274 const std::string& shell_script); |
| 275 void AddNativeTarget(const std::string& name, |
| 276 const std::string& type, |
| 277 const std::string& output_name, |
| 278 const std::string& output_type, |
| 279 const std::string& shell_script); |
| 280 |
| 281 void SetProjectDirPath(const std::string& project_dir_path); |
| 282 void SetProjectRoot(const std::string& project_root); |
| 283 void AddTarget(std::unique_ptr<PBXTarget> target); |
| 284 |
| 285 // PBXObject implementation. |
| 286 PBXObjectClass Class() const override; |
| 287 std::string Name() const override; |
| 288 std::string Comment() const override; |
| 289 void Visit(PBXObjectVisitor& visitor) override; |
| 290 void Print(std::ostream& out, unsigned indent) const override; |
| 291 |
| 292 private: |
| 293 PBXAttributes attributes_; |
| 294 std::unique_ptr<XCConfigurationList> configurations_; |
| 295 std::unique_ptr<PBXGroup> main_group_; |
| 296 std::string project_dir_path_; |
| 297 std::string project_root_; |
| 298 std::vector<std::unique_ptr<PBXTarget>> targets_; |
| 299 std::string name_; |
| 300 std::string config_name_; |
| 301 |
| 302 PBXGroup* sources_; |
| 303 PBXGroup* products_; |
| 304 PBXNativeTarget* target_for_indexing_; |
| 305 |
| 306 DISALLOW_COPY_AND_ASSIGN(PBXProject); |
| 307 }; |
| 308 |
| 309 // PBXShellScriptBuildPhase --------------------------------------------------- |
| 310 |
| 311 class PBXShellScriptBuildPhase : public PBXBuildPhase { |
| 312 public: |
| 313 PBXShellScriptBuildPhase(const std::string& name, |
| 314 const std::string& shell_script); |
| 315 ~PBXShellScriptBuildPhase() override; |
| 316 |
| 317 // PBXObject implementation. |
| 318 PBXObjectClass Class() const override; |
| 319 std::string Name() const override; |
| 320 void Print(std::ostream& out, unsigned indent) const override; |
| 321 |
| 322 private: |
| 323 std::string name_; |
| 324 std::string shell_script_; |
| 325 |
| 326 DISALLOW_COPY_AND_ASSIGN(PBXShellScriptBuildPhase); |
| 327 }; |
| 328 |
| 329 // PBXSourcesBuildPhase ------------------------------------------------------- |
| 330 |
| 331 class PBXSourcesBuildPhase : public PBXBuildPhase { |
| 332 public: |
| 333 PBXSourcesBuildPhase(); |
| 334 ~PBXSourcesBuildPhase() override; |
| 335 |
| 336 void AddBuildFile(std::unique_ptr<PBXBuildFile> build_file); |
| 337 |
| 338 // PBXObject implementation. |
| 339 PBXObjectClass Class() const override; |
| 340 std::string Name() const override; |
| 341 void Visit(PBXObjectVisitor& visitor) override; |
| 342 void Print(std::ostream& out, unsigned indent) const override; |
| 343 |
| 344 private: |
| 345 std::vector<std::unique_ptr<PBXBuildFile>> files_; |
| 346 |
| 347 DISALLOW_COPY_AND_ASSIGN(PBXSourcesBuildPhase); |
| 348 }; |
| 349 |
| 350 // XCBuildConfiguration ------------------------------------------------------- |
| 351 |
| 352 class XCBuildConfiguration : public PBXObject { |
| 353 public: |
| 354 XCBuildConfiguration(const std::string& name, |
| 355 const PBXAttributes& attributes); |
| 356 ~XCBuildConfiguration() override; |
| 357 |
| 358 // PBXObject implementation. |
| 359 PBXObjectClass Class() const override; |
| 360 std::string Name() const override; |
| 361 void Print(std::ostream& out, unsigned indent) const override; |
| 362 |
| 363 private: |
| 364 PBXAttributes attributes_; |
| 365 std::string name_; |
| 366 |
| 367 DISALLOW_COPY_AND_ASSIGN(XCBuildConfiguration); |
| 368 }; |
| 369 |
| 370 // XCConfigurationList -------------------------------------------------------- |
| 371 |
| 372 class XCConfigurationList : public PBXObject { |
| 373 public: |
| 374 XCConfigurationList(const std::string& name, |
| 375 const PBXAttributes& attributes, |
| 376 const PBXObject* owner_reference); |
| 377 ~XCConfigurationList() override; |
| 378 |
| 379 // PBXObject implementation. |
| 380 PBXObjectClass Class() const override; |
| 381 std::string Name() const override; |
| 382 void Visit(PBXObjectVisitor& visitor) override; |
| 383 void Print(std::ostream& out, unsigned indent) const override; |
| 384 |
| 385 private: |
| 386 std::vector<std::unique_ptr<XCBuildConfiguration>> configurations_; |
| 387 const PBXObject* owner_reference_; |
| 388 |
| 389 DISALLOW_COPY_AND_ASSIGN(XCConfigurationList); |
| 390 }; |
| 391 |
| 392 #endif // TOOLS_GN_XCODE_OBJECT_H_ |
OLD | NEW |