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& source_prereqs() const { return source_prereqs_; }
84 FileList& source_prereqs() { return source_prereqs_; }
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.
107 const LabelConfigVector& configs() const { return configs_; }
108 LabelConfigVector& configs() { return configs_; }
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_;
116 LabelConfigVector& all_dependent_configs() {
117 return all_dependent_configs_;
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_;
125 LabelConfigVector& direct_dependent_configs() {
126 return direct_dependent_configs_;
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_;
134 LabelTargetVector& forward_dependent_configs() {
135 return forward_dependent_configs_;
138 const std::set<const Target*>& inherited_libraries() const {
139 return inherited_libraries_;
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_; }
146 ActionValues& action_values() { return action_values_; }
147 const ActionValues& action_values() const { return action_values_; }
149 const OrderedSet<SourceDir>& all_lib_dirs() const { return all_lib_dirs_; }
150 const OrderedSet<std::string>& all_libs() const { return all_libs_; }
152 const std::set<const Target*>& recursive_hard_deps() const {
153 return recursive_hard_deps_;
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);
161 // These each pull specific things from dependencies to this one when all
162 // deps have been resolved.
163 void PullForwardedDependentConfigs();
164 void PullRecursiveHardDeps();
166 OutputType output_type_;
167 std::string output_name_;
168 std::string output_extension_;
171 bool all_headers_public_;
172 FileList public_headers_;
173 FileList source_prereqs_;
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.
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.
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
189 LabelTargetVector deps_;
190 LabelTargetVector datadeps_;
192 LabelConfigVector configs_;
193 LabelConfigVector all_dependent_configs_;
194 LabelConfigVector direct_dependent_configs_;
195 LabelTargetVector forward_dependent_configs_;
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_;
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_;
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_;
213 ConfigValues config_values_; // Used for all binary targets.
214 ActionValues action_values_; // Used for action[_foreach] targets.
216 DISALLOW_COPY_AND_ASSIGN(Target);
219 #endif // TOOLS_GN_TARGET_H_