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/files/file_path.h" 15 16 class Builder; 17 class BuildSettings; 18 class Err; 19 20 enum class XcodeBuildSystem { 21 kLegacy, 22 kNew, 23 }; 24 25 // Writes an Xcode workspace to build and debug code. 26 class XcodeWriter { 27 public: 28 // Controls some parameters and behaviour of the RunAndWriteFiles(). 29 struct Options { 30 // Name of the generated project file. Defaults to "all" is empty. 31 std::string project_name; 32 33 // Name of the ninja target to use for the "All" target in the generated 34 // project. If empty, no target will be passed to ninja which will thus 35 // try to build all defined targets. 36 std::string root_target_name; 37 38 // Name of the ninja executable. Defaults to "ninja" if empty. 39 std::string ninja_executable; 40 41 // If specified, should be a semicolon-separated list of label patterns. 42 // It will be used to filter the list of targets generated in the project 43 // (in the same way that the other filtering is done, source and header 44 // files for those target will still be listed in the generated project). 45 std::string dir_filters_string; 46 47 // If specified, should be a semicolon-separated list of configuration 48 // names. It will be used to generate all the configuration variations 49 // in the project. If empty, the project is assumed to only use a single 50 // configuration "Release". 51 std::string configurations; 52 53 // If specified, should be the path for the configuration's build 54 // directory. It can use Xcode variables such as ${CONFIGURATION} or 55 // ${EFFECTIVE_PLATFORM_NAME}. If empty, it is assumed to be the same 56 // as the project directory. 57 base::FilePath configuration_build_dir; 58 59 // If specified, should be a semicolon-separated list of file patterns. 60 // It will be used to add files to the project that are not referenced 61 // from the BUILD.gn files. This is usually used to add documentation 62 // files. 63 base::FilePath::StringType additional_files_patterns; 64 65 // If specified, should be a semicolon-separated list of file roots. 66 // It will be used to add files to the project that are not referenced 67 // from the BUILD.gn files. This is usually used to add documentation 68 // files. 69 base::FilePath::StringType additional_files_roots; 70 71 // Control which version of the build system should be used for the 72 // generated Xcode project. 73 XcodeBuildSystem build_system = XcodeBuildSystem::kLegacy; 74 }; 75 76 // Writes an Xcode workspace with a single project file. 77 // 78 // The project will lists all files referenced for the build (including the 79 // sources, headers and some supporting files). The project can be used to 80 // build, develop and debug from Xcode (though adding files, changing build 81 // settings, etc. still needs to be done via BUILD.gn files). 82 // 83 // The list of targets is filtered to only include relevant targets for 84 // debugging (mostly binaries and bundles) so it is not possible to build 85 // individuals targets (i.e. source_set) via Xcode. This filtering is done 86 // to improve the performances when loading the solution in Xcode (project 87 // like Chromium cannot be opened if all targets are generated). 88 // 89 // The source and header files are still listed in the generated generated 90 // Xcode project, even if the target they are defined in are filtered (not 91 // doing so would make it less pleasant to use Xcode to debug without any 92 // significant performance improvement). 93 // 94 // Extra behaviour is controlled by the |options| parameter. See comments 95 // of the Options type for more informations. 96 // 97 // Returns true on success, fails on failure. |err| is set in that case. 98 static bool RunAndWriteFiles(const BuildSettings* build_settings, 99 const Builder& builder, 100 Options options, 101 Err* err); 102 103 private: 104 XcodeWriter(const XcodeWriter&) = delete; 105 XcodeWriter& operator=(const XcodeWriter&) = delete; 106 }; 107 108 #endif // TOOLS_GN_XCODE_WRITER_H_ 109