Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / tools / gn / target.h
1 // Copyright (c) 2013 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_TARGET_H_
6 #define TOOLS_GN_TARGET_H_
7
8 #include <set>
9 #include <string>
10 #include <vector>
11
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/logging.h"
15 #include "base/strings/string_piece.h"
16 #include "base/synchronization/lock.h"
17 #include "tools/gn/action_values.h"
18 #include "tools/gn/config_values.h"
19 #include "tools/gn/item.h"
20 #include "tools/gn/label_ptr.h"
21 #include "tools/gn/ordered_set.h"
22 #include "tools/gn/source_file.h"
23
24 class InputFile;
25 class Settings;
26 class Token;
27
28 class Target : public Item {
29  public:
30   enum OutputType {
31     UNKNOWN,
32     GROUP,
33     EXECUTABLE,
34     SHARED_LIBRARY,
35     STATIC_LIBRARY,
36     SOURCE_SET,
37     COPY_FILES,
38     ACTION,
39     ACTION_FOREACH,
40   };
41   typedef std::vector<SourceFile> FileList;
42   typedef std::vector<std::string> StringVector;
43
44   Target(const Settings* settings, const Label& label);
45   virtual ~Target();
46
47   // Returns a string naming the output type.
48   static const char* GetStringForOutputType(OutputType type);
49
50   // Item overrides.
51   virtual Target* AsTarget() OVERRIDE;
52   virtual const Target* AsTarget() const OVERRIDE;
53   virtual void OnResolved() OVERRIDE;
54
55   OutputType output_type() const { return output_type_; }
56   void set_output_type(OutputType t) { output_type_ = t; }
57
58   bool IsLinkable() const;
59
60   // Will be the empty string to use the target label as the output name.
61   const std::string& output_name() const { return output_name_; }
62   void set_output_name(const std::string& name) { output_name_ = name; }
63
64   const std::string& output_extension() const { return output_extension_; }
65   void set_output_extension(const std::string& extension) {
66     output_extension_ = extension;
67   }
68
69   const FileList& sources() const { return sources_; }
70   FileList& sources() { return sources_; }
71
72   // Set to true when all sources are public. This is the default. In this case
73   // the public headers list should be empty.
74   bool all_headers_public() const { return all_headers_public_; }
75   void set_all_headers_public(bool p) { all_headers_public_ = p; }
76
77   // When all_headers_public is false, this is the list of public headers. It
78   // could be empty which would mean no headers are public.
79   const FileList& public_headers() const { return public_headers_; }
80   FileList& public_headers() { return public_headers_; }
81
82   // Compile-time extra dependencies.
83   const FileList& source_prereqs() const { return source_prereqs_; }
84   FileList& source_prereqs() { return source_prereqs_; }
85
86   // Runtime dependencies.
87   const FileList& data() const { return data_; }
88   FileList& data() { return data_; }
89
90   // Returns true if targets depending on this one should have an order
91   // dependency.
92   bool hard_dep() const {
93     return output_type_ == ACTION ||
94            output_type_ == ACTION_FOREACH ||
95            output_type_ == COPY_FILES;
96   }
97
98   // Linked dependencies.
99   const LabelTargetVector& deps() const { return deps_; }
100   LabelTargetVector& deps() { return deps_; }
101
102   // Non-linked dependencies.
103   const LabelTargetVector& datadeps() const { return datadeps_; }
104   LabelTargetVector& datadeps() { return datadeps_; }
105
106   // List of configs that this class inherits settings from.
107   const LabelConfigVector& configs() const { return configs_; }
108   LabelConfigVector& configs() { return configs_; }
109
110   // List of configs that all dependencies (direct and indirect) of this
111   // target get. These configs are not added to this target. Note that due
112   // to the way this is computed, there may be duplicates in this list.
113   const LabelConfigVector& all_dependent_configs() const {
114     return all_dependent_configs_;
115   }
116   LabelConfigVector& all_dependent_configs() {
117     return all_dependent_configs_;
118   }
119
120   // List of configs that targets depending directly on this one get. These
121   // configs are not added to this target.
122   const LabelConfigVector& direct_dependent_configs() const {
123     return direct_dependent_configs_;
124   }
125   LabelConfigVector& direct_dependent_configs() {
126     return direct_dependent_configs_;
127   }
128
129   // A list of a subset of deps where we'll re-export direct_dependent_configs
130   // as direct_dependent_configs of this target.
131   const LabelTargetVector& forward_dependent_configs() const {
132     return forward_dependent_configs_;
133   }
134   LabelTargetVector& forward_dependent_configs() {
135     return forward_dependent_configs_;
136   }
137
138   const std::set<const Target*>& inherited_libraries() const {
139     return inherited_libraries_;
140   }
141
142   // This config represents the configuration set directly on this target.
143   ConfigValues& config_values() { return config_values_; }
144   const ConfigValues& config_values() const { return config_values_; }
145
146   ActionValues& action_values() { return action_values_; }
147   const ActionValues& action_values() const { return action_values_; }
148
149   const OrderedSet<SourceDir>& all_lib_dirs() const { return all_lib_dirs_; }
150   const OrderedSet<std::string>& all_libs() const { return all_libs_; }
151
152   const std::set<const Target*>& recursive_hard_deps() const {
153     return recursive_hard_deps_;
154   }
155
156  private:
157   // Pulls necessary information from dependencies to this one when all
158   // dependencies have been resolved.
159   void PullDependentTargetInfo(std::set<const Config*>* unique_configs);
160
161   // These each pull specific things from dependencies to this one when all
162   // deps have been resolved.
163   void PullForwardedDependentConfigs();
164   void PullRecursiveHardDeps();
165
166   OutputType output_type_;
167   std::string output_name_;
168   std::string output_extension_;
169
170   FileList sources_;
171   bool all_headers_public_;
172   FileList public_headers_;
173   FileList source_prereqs_;
174   FileList data_;
175
176   bool hard_dep_;
177
178   // Note that if there are any groups in the deps, once the target is resolved
179   // these vectors will list *both* the groups as well as the groups' deps.
180   //
181   // This is because, in general, groups should be "transparent" ways to add
182   // groups of dependencies, so adding the groups deps make this happen with
183   // no additional complexity when iterating over a target's deps.
184   //
185   // However, a group may also have specific settings and configs added to it,
186   // so we also need the group in the list so we find these things. But you
187   // shouldn't need to look inside the deps of the group since those will
188   // already be added.
189   LabelTargetVector deps_;
190   LabelTargetVector datadeps_;
191
192   LabelConfigVector configs_;
193   LabelConfigVector all_dependent_configs_;
194   LabelConfigVector direct_dependent_configs_;
195   LabelTargetVector forward_dependent_configs_;
196
197   bool external_;
198
199   // Static libraries and source sets from transitive deps. These things need
200   // to be linked only with the end target (executable, shared library). These
201   // do not get pushed beyond shared library boundaries.
202   std::set<const Target*> inherited_libraries_;
203
204   // These libs and dirs are inherited from statically linked deps and all
205   // configs applying to this target.
206   OrderedSet<SourceDir> all_lib_dirs_;
207   OrderedSet<std::string> all_libs_;
208
209   // All hard deps from this target and all dependencies. Filled in when this
210   // target is marked resolved. This will not include the current target.
211   std::set<const Target*> recursive_hard_deps_;
212
213   ConfigValues config_values_;  // Used for all binary targets.
214   ActionValues action_values_;  // Used for action[_foreach] targets.
215
216   DISALLOW_COPY_AND_ASSIGN(Target);
217 };
218
219 #endif  // TOOLS_GN_TARGET_H_