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.
5 #ifndef TOOLS_GN_TARGET_H_
6 #define TOOLS_GN_TARGET_H_
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"
28 class Target
: public Item
{
41 typedef std::vector
<SourceFile
> FileList
;
42 typedef std::vector
<std::string
> StringVector
;
44 Target(const Settings
* settings
, const Label
& label
);
47 // Returns a string naming the output type.
48 static const char* GetStringForOutputType(OutputType type
);
51 virtual Target
* AsTarget() OVERRIDE
;
52 virtual const Target
* AsTarget() const OVERRIDE
;
53 virtual void OnResolved() OVERRIDE
;
55 OutputType
output_type() const { return output_type_
; }
56 void set_output_type(OutputType t
) { output_type_
= t
; }
58 bool IsLinkable() const;
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
; }
64 const std::string
& output_extension() const { return output_extension_
; }
65 void set_output_extension(const std::string
& extension
) {
66 output_extension_
= extension
;
69 const FileList
& sources() const { return sources_
; }
70 FileList
& sources() { return sources_
; }
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
; }
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_
; }
82 // Compile-time extra dependencies.
83 const FileList
& inputs() const { return inputs_
; }
84 FileList
& inputs() { return inputs_
; }
86 // Runtime dependencies.
87 const FileList
& data() const { return data_
; }
88 FileList
& data() { return data_
; }
90 // Returns true if targets depending on this one should have an order
92 bool hard_dep() const {
93 return output_type_
== ACTION
||
94 output_type_
== ACTION_FOREACH
||
95 output_type_
== COPY_FILES
;
98 // Linked dependencies.
99 const LabelTargetVector
& deps() const { return deps_
; }
100 LabelTargetVector
& deps() { return deps_
; }
102 // Non-linked dependencies.
103 const LabelTargetVector
& datadeps() const { return datadeps_
; }
104 LabelTargetVector
& datadeps() { return datadeps_
; }
106 // List of configs that this class inherits settings from. Once a target is
107 // resolved, this will also list all- and direct-dependent configs.
108 const LabelConfigVector
& configs() const { return configs_
; }
109 LabelConfigVector
& configs() { return configs_
; }
111 // List of configs that all dependencies (direct and indirect) of this
112 // target get. These configs are not added to this target. Note that due
113 // to the way this is computed, there may be duplicates in this list.
114 const LabelConfigVector
& all_dependent_configs() const {
115 return all_dependent_configs_
;
117 LabelConfigVector
& all_dependent_configs() {
118 return all_dependent_configs_
;
121 // List of configs that targets depending directly on this one get. These
122 // configs are not added to this target.
123 const LabelConfigVector
& direct_dependent_configs() const {
124 return direct_dependent_configs_
;
126 LabelConfigVector
& direct_dependent_configs() {
127 return direct_dependent_configs_
;
130 // A list of a subset of deps where we'll re-export direct_dependent_configs
131 // as direct_dependent_configs of this target.
132 const LabelTargetVector
& forward_dependent_configs() const {
133 return forward_dependent_configs_
;
135 LabelTargetVector
& forward_dependent_configs() {
136 return forward_dependent_configs_
;
139 const std::set
<const Target
*>& inherited_libraries() const {
140 return inherited_libraries_
;
143 // This config represents the configuration set directly on this target.
144 ConfigValues
& config_values() { return config_values_
; }
145 const ConfigValues
& config_values() const { return config_values_
; }
147 ActionValues
& action_values() { return action_values_
; }
148 const ActionValues
& action_values() const { return action_values_
; }
150 const OrderedSet
<SourceDir
>& all_lib_dirs() const { return all_lib_dirs_
; }
151 const OrderedSet
<std::string
>& all_libs() const { return all_libs_
; }
153 const std::set
<const Target
*>& recursive_hard_deps() const {
154 return recursive_hard_deps_
;
158 // Pulls necessary information from dependencies to this one when all
159 // dependencies have been resolved.
160 void PullDependentTargetInfo(std::set
<const Config
*>* unique_configs
);
162 // These each pull specific things from dependencies to this one when all
163 // deps have been resolved.
164 void PullForwardedDependentConfigs();
165 void PullRecursiveHardDeps();
167 OutputType output_type_
;
168 std::string output_name_
;
169 std::string output_extension_
;
172 bool all_headers_public_
;
173 FileList public_headers_
;
179 // Note that if there are any groups in the deps, once the target is resolved
180 // these vectors will list *both* the groups as well as the groups' deps.
182 // This is because, in general, groups should be "transparent" ways to add
183 // groups of dependencies, so adding the groups deps make this happen with
184 // no additional complexity when iterating over a target's deps.
186 // However, a group may also have specific settings and configs added to it,
187 // so we also need the group in the list so we find these things. But you
188 // shouldn't need to look inside the deps of the group since those will
190 LabelTargetVector deps_
;
191 LabelTargetVector datadeps_
;
193 LabelConfigVector configs_
;
194 LabelConfigVector all_dependent_configs_
;
195 LabelConfigVector direct_dependent_configs_
;
196 LabelTargetVector forward_dependent_configs_
;
200 // Static libraries and source sets from transitive deps. These things need
201 // to be linked only with the end target (executable, shared library). Source
202 // sets do not get pushed beyond static library boundaries, and neither
203 // source sets nor static libraries get pushed beyond sahred library
205 std::set
<const Target
*> inherited_libraries_
;
207 // These libs and dirs are inherited from statically linked deps and all
208 // configs applying to this target.
209 OrderedSet
<SourceDir
> all_lib_dirs_
;
210 OrderedSet
<std::string
> all_libs_
;
212 // All hard deps from this target and all dependencies. Filled in when this
213 // target is marked resolved. This will not include the current target.
214 std::set
<const Target
*> recursive_hard_deps_
;
216 ConfigValues config_values_
; // Used for all binary targets.
217 ActionValues action_values_
; // Used for action[_foreach] targets.
219 DISALLOW_COPY_AND_ASSIGN(Target
);
222 #endif // TOOLS_GN_TARGET_H_