blob: 644704355c3ca3f82d08e293fd3afe97fc0f3320 [file] [log] [blame]
[email protected]96ea63d2013-07-30 10:17:071// 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"
[email protected]2fbe1012014-03-20 17:59:1517#include "tools/gn/action_values.h"
[email protected]96ea63d2013-07-30 10:17:0718#include "tools/gn/config_values.h"
19#include "tools/gn/item.h"
[email protected]68d1dd32013-11-01 21:59:5120#include "tools/gn/label_ptr.h"
[email protected]b1e468f2013-09-10 22:58:0221#include "tools/gn/ordered_set.h"
[email protected]96ea63d2013-07-30 10:17:0722#include "tools/gn/source_file.h"
23
24class InputFile;
25class Settings;
26class Token;
27
28class Target : public Item {
29 public:
30 enum OutputType {
[email protected]c0822d7f2013-08-13 17:10:5631 UNKNOWN,
32 GROUP,
[email protected]96ea63d2013-07-30 10:17:0733 EXECUTABLE,
34 SHARED_LIBRARY,
35 STATIC_LIBRARY,
[email protected]7ff2f5d2013-10-08 21:30:3436 SOURCE_SET,
[email protected]96ea63d2013-07-30 10:17:0737 COPY_FILES,
[email protected]2fbe1012014-03-20 17:59:1538 ACTION,
39 ACTION_FOREACH,
[email protected]96ea63d2013-07-30 10:17:0740 };
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
[email protected]ac1128e2013-08-23 00:26:5647 // Returns a string naming the output type.
48 static const char* GetStringForOutputType(OutputType type);
49
[email protected]96ea63d2013-07-30 10:17:0750 // Item overrides.
51 virtual Target* AsTarget() OVERRIDE;
52 virtual const Target* AsTarget() const OVERRIDE;
53 virtual void OnResolved() OVERRIDE;
54
[email protected]96ea63d2013-07-30 10:17:0755 OutputType output_type() const { return output_type_; }
56 void set_output_type(OutputType t) { output_type_ = t; }
57
58 bool IsLinkable() const;
59
[email protected]b5c19e32013-09-10 23:01:2560 // 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
[email protected]b9473ee2014-02-28 21:51:1064 const std::string& output_extension() const { return output_extension_; }
65 void set_output_extension(const std::string& extension) {
66 output_extension_ = extension;
67 }
68
[email protected]96ea63d2013-07-30 10:17:0769 const FileList& sources() const { return sources_; }
[email protected]3c1274d2013-09-10 22:21:2170 FileList& sources() { return sources_; }
[email protected]96ea63d2013-07-30 10:17:0771
[email protected]126d8b52014-04-07 22:17:3572 // 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
[email protected]234be5202013-09-11 20:44:0282 // Compile-time extra dependencies.
83 const FileList& source_prereqs() const { return source_prereqs_; }
84 FileList& source_prereqs() { return source_prereqs_; }
[email protected]234be5202013-09-11 20:44:0285
86 // Runtime dependencies.
[email protected]96ea63d2013-07-30 10:17:0787 const FileList& data() const { return data_; }
[email protected]3c1274d2013-09-10 22:21:2188 FileList& data() { return data_; }
[email protected]96ea63d2013-07-30 10:17:0789
[email protected]ef348fe2014-05-01 18:31:3190 // 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 }
[email protected]234be5202013-09-11 20:44:0297
[email protected]4441041b2013-08-06 21:11:0698 // Linked dependencies.
[email protected]68d1dd32013-11-01 21:59:5199 const LabelTargetVector& deps() const { return deps_; }
100 LabelTargetVector& deps() { return deps_; }
[email protected]96ea63d2013-07-30 10:17:07101
[email protected]4441041b2013-08-06 21:11:06102 // Non-linked dependencies.
[email protected]68d1dd32013-11-01 21:59:51103 const LabelTargetVector& datadeps() const { return datadeps_; }
104 LabelTargetVector& datadeps() { return datadeps_; }
[email protected]4441041b2013-08-06 21:11:06105
[email protected]08035b92014-05-13 19:40:56106 // List of configs that this class inherits settings from. Once a target is
107 // resolved, this will also list all- and direct-dependent configs.
[email protected]68d1dd32013-11-01 21:59:51108 const LabelConfigVector& configs() const { return configs_; }
109 LabelConfigVector& configs() { return configs_; }
[email protected]96ea63d2013-07-30 10:17:07110
111 // List of configs that all dependencies (direct and indirect) of this
[email protected]62a610632013-08-21 23:45:23112 // 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.
[email protected]68d1dd32013-11-01 21:59:51114 const LabelConfigVector& all_dependent_configs() const {
[email protected]96ea63d2013-07-30 10:17:07115 return all_dependent_configs_;
116 }
[email protected]68d1dd32013-11-01 21:59:51117 LabelConfigVector& all_dependent_configs() {
[email protected]3c1274d2013-09-10 22:21:21118 return all_dependent_configs_;
119 }
[email protected]96ea63d2013-07-30 10:17:07120
121 // List of configs that targets depending directly on this one get. These
122 // configs are not added to this target.
[email protected]68d1dd32013-11-01 21:59:51123 const LabelConfigVector& direct_dependent_configs() const {
[email protected]96ea63d2013-07-30 10:17:07124 return direct_dependent_configs_;
125 }
[email protected]68d1dd32013-11-01 21:59:51126 LabelConfigVector& direct_dependent_configs() {
[email protected]3c1274d2013-09-10 22:21:21127 return direct_dependent_configs_;
128 }
[email protected]96ea63d2013-07-30 10:17:07129
[email protected]62a610632013-08-21 23:45:23130 // A list of a subset of deps where we'll re-export direct_dependent_configs
131 // as direct_dependent_configs of this target.
[email protected]68d1dd32013-11-01 21:59:51132 const LabelTargetVector& forward_dependent_configs() const {
[email protected]62a610632013-08-21 23:45:23133 return forward_dependent_configs_;
134 }
[email protected]68d1dd32013-11-01 21:59:51135 LabelTargetVector& forward_dependent_configs() {
[email protected]3c1274d2013-09-10 22:21:21136 return forward_dependent_configs_;
137 }
[email protected]62a610632013-08-21 23:45:23138
[email protected]96ea63d2013-07-30 10:17:07139 const std::set<const Target*>& inherited_libraries() const {
140 return inherited_libraries_;
141 }
142
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_; }
146
[email protected]2fbe1012014-03-20 17:59:15147 ActionValues& action_values() { return action_values_; }
148 const ActionValues& action_values() const { return action_values_; }
[email protected]c0822d7f2013-08-13 17:10:56149
[email protected]2ed04ae2013-10-07 20:17:16150 const OrderedSet<SourceDir>& all_lib_dirs() const { return all_lib_dirs_; }
151 const OrderedSet<std::string>& all_libs() const { return all_libs_; }
[email protected]3c1274d2013-09-10 22:21:21152
[email protected]ef348fe2014-05-01 18:31:31153 const std::set<const Target*>& recursive_hard_deps() const {
154 return recursive_hard_deps_;
155 }
156
[email protected]96ea63d2013-07-30 10:17:07157 private:
[email protected]ef348fe2014-05-01 18:31:31158 // Pulls necessary information from dependencies to this one when all
[email protected]3c1274d2013-09-10 22:21:21159 // dependencies have been resolved.
160 void PullDependentTargetInfo(std::set<const Config*>* unique_configs);
161
[email protected]ef348fe2014-05-01 18:31:31162 // These each pull specific things from dependencies to this one when all
163 // deps have been resolved.
[email protected]8499f51f2014-04-24 23:43:02164 void PullForwardedDependentConfigs();
[email protected]ef348fe2014-05-01 18:31:31165 void PullRecursiveHardDeps();
[email protected]8499f51f2014-04-24 23:43:02166
[email protected]96ea63d2013-07-30 10:17:07167 OutputType output_type_;
[email protected]b5c19e32013-09-10 23:01:25168 std::string output_name_;
[email protected]b9473ee2014-02-28 21:51:10169 std::string output_extension_;
[email protected]96ea63d2013-07-30 10:17:07170
171 FileList sources_;
[email protected]126d8b52014-04-07 22:17:35172 bool all_headers_public_;
173 FileList public_headers_;
[email protected]234be5202013-09-11 20:44:02174 FileList source_prereqs_;
[email protected]96ea63d2013-07-30 10:17:07175 FileList data_;
[email protected]3c1274d2013-09-10 22:21:21176
[email protected]234be5202013-09-11 20:44:02177 bool hard_dep_;
178
[email protected]3c1274d2013-09-10 22:21:21179 // 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.
181 //
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.
185 //
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
189 // already be added.
[email protected]68d1dd32013-11-01 21:59:51190 LabelTargetVector deps_;
191 LabelTargetVector datadeps_;
[email protected]3c1274d2013-09-10 22:21:21192
[email protected]68d1dd32013-11-01 21:59:51193 LabelConfigVector configs_;
194 LabelConfigVector all_dependent_configs_;
195 LabelConfigVector direct_dependent_configs_;
196 LabelTargetVector forward_dependent_configs_;
[email protected]96ea63d2013-07-30 10:17:07197
[email protected]0a79fe42013-08-29 21:06:26198 bool external_;
199
[email protected]7ff2f5d2013-10-08 21:30:34200 // Static libraries and source sets from transitive deps. These things need
[email protected]678b5b942014-05-30 16:30:21201 // 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
204 // boundaries.
[email protected]96ea63d2013-07-30 10:17:07205 std::set<const Target*> inherited_libraries_;
206
[email protected]2ed04ae2013-10-07 20:17:16207 // 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_;
[email protected]3c1274d2013-09-10 22:21:21211
[email protected]ef348fe2014-05-01 18:31:31212 // 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_;
215
[email protected]c0822d7f2013-08-13 17:10:56216 ConfigValues config_values_; // Used for all binary targets.
[email protected]2fbe1012014-03-20 17:59:15217 ActionValues action_values_; // Used for action[_foreach] targets.
[email protected]96ea63d2013-07-30 10:17:07218
[email protected]96ea63d2013-07-30 10:17:07219 DISALLOW_COPY_AND_ASSIGN(Target);
220};
221
222#endif // TOOLS_GN_TARGET_H_