• 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_BUNDLE_DATA_H_
6 #define TOOLS_GN_BUNDLE_DATA_H_
7 
8 #include <map>
9 #include <string>
10 #include <vector>
11 
12 #include "gn/action_values.h"
13 #include "gn/bundle_file_rule.h"
14 #include "gn/source_dir.h"
15 #include "gn/source_file.h"
16 #include "gn/substitution_list.h"
17 #include "gn/unique_vector.h"
18 
19 class LabelPattern;
20 class OutputFile;
21 class Settings;
22 class Target;
23 
24 // BundleData holds the information required by "create_bundle" target.
25 class BundleData {
26  public:
27   using UniqueTargets = UniqueVector<const Target*>;
28   using SourceFiles = std::vector<SourceFile>;
29   using OutputFiles = std::vector<OutputFile>;
30   using BundleFileRules = std::vector<BundleFileRule>;
31 
32   BundleData();
33   ~BundleData();
34 
35   // Adds a bundle_data target to the recursive collection of all bundle_data
36   // that the target depends on.
37   void AddBundleData(const Target* target);
38 
39   // Called upon resolution of the target owning this instance of BundleData.
40   // |owning_target| is the owning target.
41   void OnTargetResolved(Target* owning_target);
42 
43   // Returns the list of inputs.
44   void GetSourceFiles(SourceFiles* sources) const;
45 
46   // Returns the list of outputs.
47   bool GetOutputFiles(const Settings* settings,
48                       const Target* target,
49                       OutputFiles* outputs,
50                       Err* err) const;
51 
52   // Returns the list of outputs as SourceFile.
53   bool GetOutputsAsSourceFiles(const Settings* settings,
54                                const Target* target,
55                                SourceFiles* outputs_as_source,
56                                Err* err) const;
57 
58   // Returns the path to the compiled asset catalog. Only valid if
59   // assets_catalog_sources() is not empty.
60   SourceFile GetCompiledAssetCatalogPath() const;
61 
62   // Returns the path to the top-level directory of the bundle. This is
63   // based on root_dir(), but since that can be Bundle.app/Contents/ or
64   // any other subpath, this is just the most top-level directory (e.g.,
65   // just Bundle.app/).
66   //
67   // Note that this is a SourceFile instead of a SourceDir. This is because
68   // the output of a create_bundle rule is a single logical unit, even though
69   // it is really a directory containing many outputs. This allows other
70   // targets to treat the bundle as a single unit, rather than a collection
71   // of its contents.
72   SourceFile GetBundleRootDirOutput(const Settings* settings) const;
73 
74   // Performs GetBundleRootDirOutput but returns the result as a directory.
75   SourceDir GetBundleRootDirOutputAsDir(const Settings* settings) const;
76 
77   // Returns directory where bundle is
78   SourceDir GetBundleDir(const Settings* settings) const;
79 
80   // Returns the list of inputs for the compilation of the asset catalog.
assets_catalog_sources()81   SourceFiles& assets_catalog_sources() { return assets_catalog_sources_; }
assets_catalog_sources()82   const SourceFiles& assets_catalog_sources() const {
83     return assets_catalog_sources_;
84   }
85 
86   // Returns the list of dependencies for the compilation of the asset catalog.
assets_catalog_deps()87   std::vector<const Target*> assets_catalog_deps() const {
88     return assets_catalog_deps_;
89   }
90 
file_rules()91   BundleFileRules& file_rules() { return file_rules_; }
file_rules()92   const BundleFileRules& file_rules() const { return file_rules_; }
93 
root_dir()94   SourceDir& root_dir() { return root_dir_; }
root_dir()95   const SourceDir& root_dir() const { return root_dir_; }
96 
contents_dir()97   SourceDir& contents_dir() { return contents_dir_; }
contents_dir()98   const SourceDir& contents_dir() const { return contents_dir_; }
99 
resources_dir()100   SourceDir& resources_dir() { return resources_dir_; }
resources_dir()101   const SourceDir& resources_dir() const { return resources_dir_; }
102 
executable_dir()103   SourceDir& executable_dir() { return executable_dir_; }
executable_dir()104   const SourceDir& executable_dir() const { return executable_dir_; }
105 
xcode_extra_attributes()106   std::map<std::string, std::string>& xcode_extra_attributes() {
107     return xcode_extra_attributes_;
108   }
xcode_extra_attributes()109   const std::map<std::string, std::string>& xcode_extra_attributes() const {
110     return xcode_extra_attributes_;
111   }
112 
product_type()113   std::string& product_type() { return product_type_; }
product_type()114   const std::string& product_type() const { return product_type_; }
115 
xcode_test_application_name()116   std::string& xcode_test_application_name() {
117     return xcode_test_application_name_;
118   }
xcode_test_application_name()119   const std::string& xcode_test_application_name() const {
120     return xcode_test_application_name_;
121   }
122 
set_partial_info_plist(const SourceFile & partial_info_plist)123   void set_partial_info_plist(const SourceFile& partial_info_plist) {
124     partial_info_plist_ = partial_info_plist;
125   }
partial_info_plist()126   const SourceFile& partial_info_plist() const { return partial_info_plist_; }
127 
set_code_signing_script(const SourceFile & script_file)128   void set_code_signing_script(const SourceFile& script_file) {
129     code_signing_script_ = script_file;
130   }
code_signing_script()131   const SourceFile& code_signing_script() const { return code_signing_script_; }
132 
code_signing_sources()133   std::vector<SourceFile>& code_signing_sources() {
134     return code_signing_sources_;
135   }
code_signing_sources()136   const std::vector<SourceFile>& code_signing_sources() const {
137     return code_signing_sources_;
138   }
139 
code_signing_outputs()140   SubstitutionList& code_signing_outputs() { return code_signing_outputs_; }
code_signing_outputs()141   const SubstitutionList& code_signing_outputs() const {
142     return code_signing_outputs_;
143   }
144 
code_signing_args()145   SubstitutionList& code_signing_args() { return code_signing_args_; }
code_signing_args()146   const SubstitutionList& code_signing_args() const {
147     return code_signing_args_;
148   }
149 
bundle_deps_filter()150   std::vector<LabelPattern>& bundle_deps_filter() {
151     return bundle_deps_filter_;
152   }
bundle_deps_filter()153   const std::vector<LabelPattern>& bundle_deps_filter() const {
154     return bundle_deps_filter_;
155   }
156 
xcasset_compiler_flags()157   SubstitutionList& xcasset_compiler_flags() { return xcasset_compiler_flags_; }
xcasset_compiler_flags()158   const SubstitutionList& xcasset_compiler_flags() const {
159     return xcasset_compiler_flags_;
160   }
161 
162   // Recursive collection of all bundle_data that the target depends on.
bundle_deps()163   const UniqueTargets& bundle_deps() const { return bundle_deps_; }
164 
165   // Returns whether the bundle is a framework bundle.
is_framework()166   bool is_framework() const {
167     return product_type_ == "com.apple.product-type.framework";
168   }
169 
170  private:
171   SourceFiles assets_catalog_sources_;
172   std::vector<const Target*> assets_catalog_deps_;
173   BundleFileRules file_rules_;
174   UniqueTargets bundle_deps_;
175   std::vector<LabelPattern> bundle_deps_filter_;
176 
177   // All those values are subdirectories relative to root_build_dir, and apart
178   // from root_dir_, they are either equal to root_dir_ or subdirectories of it.
179   SourceDir root_dir_;
180   SourceDir contents_dir_;
181   SourceDir resources_dir_;
182   SourceDir executable_dir_;
183 
184   // The specified attributes will append to the build settings of the generated
185   // Xcode target.
186   std::map<std::string, std::string> xcode_extra_attributes_;
187 
188   // This is the target type as known to Xcode. This is only used to generate
189   // the Xcode project file when using --ide=xcode.
190   std::string product_type_;
191 
192   // Each Xcode unit test or ui test target must have a test application target,
193   // and this value corresponds to the target name. This is only used to
194   // generate the Xcode project when using --ide=xcode.
195   std::string xcode_test_application_name_;
196 
197   // Path to the partial Info.plist generated by the asset catalog compiler
198   // (corresponds to {{bundle_partial_info_plist}} expansion).
199   SourceFile partial_info_plist_;
200 
201   // Holds the values (script name, sources, outputs, script arguments) for the
202   // code signing step if defined.
203   SourceFile code_signing_script_;
204   std::vector<SourceFile> code_signing_sources_;
205   SubstitutionList code_signing_outputs_;
206   SubstitutionList code_signing_args_;
207   SubstitutionList xcasset_compiler_flags_;
208 
209   BundleData(const BundleData&) = delete;
210   BundleData& operator=(const BundleData&) = delete;
211 };
212 
213 #endif  // TOOLS_GN_BUNDLE_DATA_H_
214