[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 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" |
[email protected] | 2fbe101 | 2014-03-20 17:59:15 | [diff] [blame] | 17 | #include "tools/gn/action_values.h" |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 18 | #include "tools/gn/config_values.h" |
| 19 | #include "tools/gn/item.h" |
[email protected] | 68d1dd3 | 2013-11-01 21:59:51 | [diff] [blame] | 20 | #include "tools/gn/label_ptr.h" |
[email protected] | b1e468f | 2013-09-10 22:58:02 | [diff] [blame] | 21 | #include "tools/gn/ordered_set.h" |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 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 { |
[email protected] | c0822d7f | 2013-08-13 17:10:56 | [diff] [blame] | 31 | UNKNOWN, |
| 32 | GROUP, |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 33 | EXECUTABLE, |
| 34 | SHARED_LIBRARY, |
| 35 | STATIC_LIBRARY, |
[email protected] | 7ff2f5d | 2013-10-08 21:30:34 | [diff] [blame] | 36 | SOURCE_SET, |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 37 | COPY_FILES, |
[email protected] | 2fbe101 | 2014-03-20 17:59:15 | [diff] [blame] | 38 | ACTION, |
| 39 | ACTION_FOREACH, |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 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 | |
[email protected] | ac1128e | 2013-08-23 00:26:56 | [diff] [blame] | 47 | // Returns a string naming the output type. |
| 48 | static const char* GetStringForOutputType(OutputType type); |
| 49 | |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 50 | // Item overrides. |
| 51 | virtual Target* AsTarget() OVERRIDE; |
| 52 | virtual const Target* AsTarget() const OVERRIDE; |
| 53 | virtual void OnResolved() OVERRIDE; |
| 54 | |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 55 | 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] | b5c19e3 | 2013-09-10 23:01:25 | [diff] [blame] | 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 | |
[email protected] | b9473ee | 2014-02-28 21:51:10 | [diff] [blame] | 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 | |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 69 | const FileList& sources() const { return sources_; } |
[email protected] | 3c1274d | 2013-09-10 22:21:21 | [diff] [blame] | 70 | FileList& sources() { return sources_; } |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 71 | |
[email protected] | 126d8b5 | 2014-04-07 22:17:35 | [diff] [blame] | 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 | |
[email protected] | 234be520 | 2013-09-11 20:44:02 | [diff] [blame] | 82 | // Compile-time extra dependencies. |
| 83 | const FileList& source_prereqs() const { return source_prereqs_; } |
| 84 | FileList& source_prereqs() { return source_prereqs_; } |
[email protected] | 234be520 | 2013-09-11 20:44:02 | [diff] [blame] | 85 | |
| 86 | // Runtime dependencies. |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 87 | const FileList& data() const { return data_; } |
[email protected] | 3c1274d | 2013-09-10 22:21:21 | [diff] [blame] | 88 | FileList& data() { return data_; } |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 89 | |
[email protected] | ef348fe | 2014-05-01 18:31:31 | [diff] [blame] | 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 | } |
[email protected] | 234be520 | 2013-09-11 20:44:02 | [diff] [blame] | 97 | |
[email protected] | 4441041b | 2013-08-06 21:11:06 | [diff] [blame] | 98 | // Linked dependencies. |
[email protected] | 68d1dd3 | 2013-11-01 21:59:51 | [diff] [blame] | 99 | const LabelTargetVector& deps() const { return deps_; } |
| 100 | LabelTargetVector& deps() { return deps_; } |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 101 | |
[email protected] | 4441041b | 2013-08-06 21:11:06 | [diff] [blame] | 102 | // Non-linked dependencies. |
[email protected] | 68d1dd3 | 2013-11-01 21:59:51 | [diff] [blame] | 103 | const LabelTargetVector& datadeps() const { return datadeps_; } |
| 104 | LabelTargetVector& datadeps() { return datadeps_; } |
[email protected] | 4441041b | 2013-08-06 21:11:06 | [diff] [blame] | 105 | |
[email protected] | 08035b9 | 2014-05-13 19:40:56 | [diff] [blame] | 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. |
[email protected] | 68d1dd3 | 2013-11-01 21:59:51 | [diff] [blame] | 108 | const LabelConfigVector& configs() const { return configs_; } |
| 109 | LabelConfigVector& configs() { return configs_; } |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 110 | |
| 111 | // List of configs that all dependencies (direct and indirect) of this |
[email protected] | 62a61063 | 2013-08-21 23:45:23 | [diff] [blame] | 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. |
[email protected] | 68d1dd3 | 2013-11-01 21:59:51 | [diff] [blame] | 114 | const LabelConfigVector& all_dependent_configs() const { |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 115 | return all_dependent_configs_; |
| 116 | } |
[email protected] | 68d1dd3 | 2013-11-01 21:59:51 | [diff] [blame] | 117 | LabelConfigVector& all_dependent_configs() { |
[email protected] | 3c1274d | 2013-09-10 22:21:21 | [diff] [blame] | 118 | return all_dependent_configs_; |
| 119 | } |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 120 | |
| 121 | // List of configs that targets depending directly on this one get. These |
| 122 | // configs are not added to this target. |
[email protected] | 68d1dd3 | 2013-11-01 21:59:51 | [diff] [blame] | 123 | const LabelConfigVector& direct_dependent_configs() const { |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 124 | return direct_dependent_configs_; |
| 125 | } |
[email protected] | 68d1dd3 | 2013-11-01 21:59:51 | [diff] [blame] | 126 | LabelConfigVector& direct_dependent_configs() { |
[email protected] | 3c1274d | 2013-09-10 22:21:21 | [diff] [blame] | 127 | return direct_dependent_configs_; |
| 128 | } |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 129 | |
[email protected] | 62a61063 | 2013-08-21 23:45:23 | [diff] [blame] | 130 | // 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] | 68d1dd3 | 2013-11-01 21:59:51 | [diff] [blame] | 132 | const LabelTargetVector& forward_dependent_configs() const { |
[email protected] | 62a61063 | 2013-08-21 23:45:23 | [diff] [blame] | 133 | return forward_dependent_configs_; |
| 134 | } |
[email protected] | 68d1dd3 | 2013-11-01 21:59:51 | [diff] [blame] | 135 | LabelTargetVector& forward_dependent_configs() { |
[email protected] | 3c1274d | 2013-09-10 22:21:21 | [diff] [blame] | 136 | return forward_dependent_configs_; |
| 137 | } |
[email protected] | 62a61063 | 2013-08-21 23:45:23 | [diff] [blame] | 138 | |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 139 | 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] | 2fbe101 | 2014-03-20 17:59:15 | [diff] [blame] | 147 | ActionValues& action_values() { return action_values_; } |
| 148 | const ActionValues& action_values() const { return action_values_; } |
[email protected] | c0822d7f | 2013-08-13 17:10:56 | [diff] [blame] | 149 | |
[email protected] | 2ed04ae | 2013-10-07 20:17:16 | [diff] [blame] | 150 | const OrderedSet<SourceDir>& all_lib_dirs() const { return all_lib_dirs_; } |
| 151 | const OrderedSet<std::string>& all_libs() const { return all_libs_; } |
[email protected] | 3c1274d | 2013-09-10 22:21:21 | [diff] [blame] | 152 | |
[email protected] | ef348fe | 2014-05-01 18:31:31 | [diff] [blame] | 153 | const std::set<const Target*>& recursive_hard_deps() const { |
| 154 | return recursive_hard_deps_; |
| 155 | } |
| 156 | |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 157 | private: |
[email protected] | ef348fe | 2014-05-01 18:31:31 | [diff] [blame] | 158 | // Pulls necessary information from dependencies to this one when all |
[email protected] | 3c1274d | 2013-09-10 22:21:21 | [diff] [blame] | 159 | // dependencies have been resolved. |
| 160 | void PullDependentTargetInfo(std::set<const Config*>* unique_configs); |
| 161 | |
[email protected] | ef348fe | 2014-05-01 18:31:31 | [diff] [blame] | 162 | // These each pull specific things from dependencies to this one when all |
| 163 | // deps have been resolved. |
[email protected] | 8499f51f | 2014-04-24 23:43:02 | [diff] [blame] | 164 | void PullForwardedDependentConfigs(); |
[email protected] | ef348fe | 2014-05-01 18:31:31 | [diff] [blame] | 165 | void PullRecursiveHardDeps(); |
[email protected] | 8499f51f | 2014-04-24 23:43:02 | [diff] [blame] | 166 | |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 167 | OutputType output_type_; |
[email protected] | b5c19e3 | 2013-09-10 23:01:25 | [diff] [blame] | 168 | std::string output_name_; |
[email protected] | b9473ee | 2014-02-28 21:51:10 | [diff] [blame] | 169 | std::string output_extension_; |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 170 | |
| 171 | FileList sources_; |
[email protected] | 126d8b5 | 2014-04-07 22:17:35 | [diff] [blame] | 172 | bool all_headers_public_; |
| 173 | FileList public_headers_; |
[email protected] | 234be520 | 2013-09-11 20:44:02 | [diff] [blame] | 174 | FileList source_prereqs_; |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 175 | FileList data_; |
[email protected] | 3c1274d | 2013-09-10 22:21:21 | [diff] [blame] | 176 | |
[email protected] | 234be520 | 2013-09-11 20:44:02 | [diff] [blame] | 177 | bool hard_dep_; |
| 178 | |
[email protected] | 3c1274d | 2013-09-10 22:21:21 | [diff] [blame] | 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. |
| 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] | 68d1dd3 | 2013-11-01 21:59:51 | [diff] [blame] | 190 | LabelTargetVector deps_; |
| 191 | LabelTargetVector datadeps_; |
[email protected] | 3c1274d | 2013-09-10 22:21:21 | [diff] [blame] | 192 | |
[email protected] | 68d1dd3 | 2013-11-01 21:59:51 | [diff] [blame] | 193 | LabelConfigVector configs_; |
| 194 | LabelConfigVector all_dependent_configs_; |
| 195 | LabelConfigVector direct_dependent_configs_; |
| 196 | LabelTargetVector forward_dependent_configs_; |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 197 | |
[email protected] | 0a79fe4 | 2013-08-29 21:06:26 | [diff] [blame] | 198 | bool external_; |
| 199 | |
[email protected] | 7ff2f5d | 2013-10-08 21:30:34 | [diff] [blame] | 200 | // Static libraries and source sets from transitive deps. These things need |
[email protected] | 678b5b94 | 2014-05-30 16:30:21 | [diff] [blame^] | 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 |
| 204 | // boundaries. |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 205 | std::set<const Target*> inherited_libraries_; |
| 206 | |
[email protected] | 2ed04ae | 2013-10-07 20:17:16 | [diff] [blame] | 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_; |
[email protected] | 3c1274d | 2013-09-10 22:21:21 | [diff] [blame] | 211 | |
[email protected] | ef348fe | 2014-05-01 18:31:31 | [diff] [blame] | 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_; |
| 215 | |
[email protected] | c0822d7f | 2013-08-13 17:10:56 | [diff] [blame] | 216 | ConfigValues config_values_; // Used for all binary targets. |
[email protected] | 2fbe101 | 2014-03-20 17:59:15 | [diff] [blame] | 217 | ActionValues action_values_; // Used for action[_foreach] targets. |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 218 | |
[email protected] | 96ea63d | 2013-07-30 10:17:07 | [diff] [blame] | 219 | DISALLOW_COPY_AND_ASSIGN(Target); |
| 220 | }; |
| 221 | |
| 222 | #endif // TOOLS_GN_TARGET_H_ |