• 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 the list of inputs for the compilation of the asset catalog.
assets_catalog_sources()78   SourceFiles& assets_catalog_sources() { return assets_catalog_sources_; }
assets_catalog_sources()79   const SourceFiles& assets_catalog_sources() const {
80     return assets_catalog_sources_;
81   }
82 
83   // Returns the list of dependencies for the compilation of the asset catalog.
assets_catalog_deps()84   std::vector<const Target*> assets_catalog_deps() const {
85     return assets_catalog_deps_;
86   }
87 
file_rules()88   BundleFileRules& file_rules() { return file_rules_; }
file_rules()89   const BundleFileRules& file_rules() const { return file_rules_; }
90 
root_dir()91   SourceDir& root_dir() { return root_dir_; }
root_dir()92   const SourceDir& root_dir() const { return root_dir_; }
93 
contents_dir()94   SourceDir& contents_dir() { return contents_dir_; }
contents_dir()95   const SourceDir& contents_dir() const { return contents_dir_; }
96 
resources_dir()97   SourceDir& resources_dir() { return resources_dir_; }
resources_dir()98   const SourceDir& resources_dir() const { return resources_dir_; }
99 
executable_dir()100   SourceDir& executable_dir() { return executable_dir_; }
executable_dir()101   const SourceDir& executable_dir() const { return executable_dir_; }
102 
xcode_extra_attributes()103   std::map<std::string, std::string>& xcode_extra_attributes() {
104     return xcode_extra_attributes_;
105   }
xcode_extra_attributes()106   const std::map<std::string, std::string>& xcode_extra_attributes() const {
107     return xcode_extra_attributes_;
108   }
109 
product_type()110   std::string& product_type() { return product_type_; }
product_type()111   const std::string& product_type() const { return product_type_; }
112 
xcode_test_application_name()113   std::string& xcode_test_application_name() {
114     return xcode_test_application_name_;
115   }
xcode_test_application_name()116   const std::string& xcode_test_application_name() const {
117     return xcode_test_application_name_;
118   }
119 
set_partial_info_plist(const SourceFile & partial_info_plist)120   void set_partial_info_plist(const SourceFile& partial_info_plist) {
121     partial_info_plist_ = partial_info_plist;
122   }
partial_info_plist()123   const SourceFile& partial_info_plist() const { return partial_info_plist_; }
124 
set_code_signing_script(const SourceFile & script_file)125   void set_code_signing_script(const SourceFile& script_file) {
126     code_signing_script_ = script_file;
127   }
code_signing_script()128   const SourceFile& code_signing_script() const { return code_signing_script_; }
129 
code_signing_sources()130   std::vector<SourceFile>& code_signing_sources() {
131     return code_signing_sources_;
132   }
code_signing_sources()133   const std::vector<SourceFile>& code_signing_sources() const {
134     return code_signing_sources_;
135   }
136 
code_signing_outputs()137   SubstitutionList& code_signing_outputs() { return code_signing_outputs_; }
code_signing_outputs()138   const SubstitutionList& code_signing_outputs() const {
139     return code_signing_outputs_;
140   }
141 
code_signing_args()142   SubstitutionList& code_signing_args() { return code_signing_args_; }
code_signing_args()143   const SubstitutionList& code_signing_args() const {
144     return code_signing_args_;
145   }
146 
bundle_deps_filter()147   std::vector<LabelPattern>& bundle_deps_filter() {
148     return bundle_deps_filter_;
149   }
bundle_deps_filter()150   const std::vector<LabelPattern>& bundle_deps_filter() const {
151     return bundle_deps_filter_;
152   }
153 
154   // Recursive collection of all bundle_data that the target depends on.
bundle_deps()155   const UniqueTargets& bundle_deps() const { return bundle_deps_; }
156 
157   // Returns whether the bundle is a framework bundle.
is_framework()158   bool is_framework() const {
159     return product_type_ == "com.apple.product-type.framework";
160   }
161 
162  private:
163   SourceFiles assets_catalog_sources_;
164   std::vector<const Target*> assets_catalog_deps_;
165   BundleFileRules file_rules_;
166   UniqueTargets bundle_deps_;
167   std::vector<LabelPattern> bundle_deps_filter_;
168 
169   // All those values are subdirectories relative to root_build_dir, and apart
170   // from root_dir_, they are either equal to root_dir_ or subdirectories of it.
171   SourceDir root_dir_;
172   SourceDir contents_dir_;
173   SourceDir resources_dir_;
174   SourceDir executable_dir_;
175 
176   // The specified attributes will append to the build settings of the generated
177   // Xcode target.
178   std::map<std::string, std::string> xcode_extra_attributes_;
179 
180   // This is the target type as known to Xcode. This is only used to generate
181   // the Xcode project file when using --ide=xcode.
182   std::string product_type_;
183 
184   // Each Xcode unit test or ui test target must have a test application target,
185   // and this value corresponds to the target name. This is only used to
186   // generate the Xcode project when using --ide=xcode.
187   std::string xcode_test_application_name_;
188 
189   // Path to the partial Info.plist generated by the asset catalog compiler
190   // (corresponds to {{bundle_partial_info_plist}} expansion).
191   SourceFile partial_info_plist_;
192 
193   // Holds the values (script name, sources, outputs, script arguments) for the
194   // code signing step if defined.
195   SourceFile code_signing_script_;
196   std::vector<SourceFile> code_signing_sources_;
197   SubstitutionList code_signing_outputs_;
198   SubstitutionList code_signing_args_;
199 
200   DISALLOW_COPY_AND_ASSIGN(BundleData);
201 };
202 
203 #endif  // TOOLS_GN_BUNDLE_DATA_H_
204