OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef TOOLS_GN_TARGET_H_ | 5 #ifndef TOOLS_GN_TARGET_H_ |
6 #define TOOLS_GN_TARGET_H_ | 6 #define TOOLS_GN_TARGET_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
17 #include "tools/gn/action_values.h" | 17 #include "tools/gn/action_values.h" |
18 #include "tools/gn/config_values.h" | 18 #include "tools/gn/config_values.h" |
19 #include "tools/gn/item.h" | 19 #include "tools/gn/item.h" |
20 #include "tools/gn/label_ptr.h" | 20 #include "tools/gn/label_ptr.h" |
21 #include "tools/gn/ordered_set.h" | 21 #include "tools/gn/ordered_set.h" |
22 #include "tools/gn/source_file.h" | 22 #include "tools/gn/source_file.h" |
| 23 #include "tools/gn/unique_vector.h" |
23 | 24 |
24 class InputFile; | 25 class InputFile; |
25 class Settings; | 26 class Settings; |
26 class Token; | 27 class Token; |
27 | 28 |
28 class Target : public Item { | 29 class Target : public Item { |
29 public: | 30 public: |
30 enum OutputType { | 31 enum OutputType { |
31 UNKNOWN, | 32 UNKNOWN, |
32 GROUP, | 33 GROUP, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // Linked dependencies. | 99 // Linked dependencies. |
99 const LabelTargetVector& deps() const { return deps_; } | 100 const LabelTargetVector& deps() const { return deps_; } |
100 LabelTargetVector& deps() { return deps_; } | 101 LabelTargetVector& deps() { return deps_; } |
101 | 102 |
102 // Non-linked dependencies. | 103 // Non-linked dependencies. |
103 const LabelTargetVector& datadeps() const { return datadeps_; } | 104 const LabelTargetVector& datadeps() const { return datadeps_; } |
104 LabelTargetVector& datadeps() { return datadeps_; } | 105 LabelTargetVector& datadeps() { return datadeps_; } |
105 | 106 |
106 // List of configs that this class inherits settings from. Once a target is | 107 // 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 // resolved, this will also list all- and direct-dependent configs. |
108 const LabelConfigVector& configs() const { return configs_; } | 109 const UniqueVector<LabelConfigPair>& configs() const { return configs_; } |
109 LabelConfigVector& configs() { return configs_; } | 110 UniqueVector<LabelConfigPair>& configs() { return configs_; } |
110 | 111 |
111 // List of configs that all dependencies (direct and indirect) of this | 112 // 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 // 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 // to the way this is computed, there may be duplicates in this list. |
114 const LabelConfigVector& all_dependent_configs() const { | 115 const UniqueVector<LabelConfigPair>& all_dependent_configs() const { |
115 return all_dependent_configs_; | 116 return all_dependent_configs_; |
116 } | 117 } |
117 LabelConfigVector& all_dependent_configs() { | 118 UniqueVector<LabelConfigPair>& all_dependent_configs() { |
118 return all_dependent_configs_; | 119 return all_dependent_configs_; |
119 } | 120 } |
120 | 121 |
121 // List of configs that targets depending directly on this one get. These | 122 // List of configs that targets depending directly on this one get. These |
122 // configs are not added to this target. | 123 // configs are not added to this target. |
123 const LabelConfigVector& direct_dependent_configs() const { | 124 const UniqueVector<LabelConfigPair>& direct_dependent_configs() const { |
124 return direct_dependent_configs_; | 125 return direct_dependent_configs_; |
125 } | 126 } |
126 LabelConfigVector& direct_dependent_configs() { | 127 UniqueVector<LabelConfigPair>& direct_dependent_configs() { |
127 return direct_dependent_configs_; | 128 return direct_dependent_configs_; |
128 } | 129 } |
129 | 130 |
130 // A list of a subset of deps where we'll re-export direct_dependent_configs | 131 // A list of a subset of deps where we'll re-export direct_dependent_configs |
131 // as direct_dependent_configs of this target. | 132 // as direct_dependent_configs of this target. |
132 const LabelTargetVector& forward_dependent_configs() const { | 133 const UniqueVector<LabelTargetPair>& forward_dependent_configs() const { |
133 return forward_dependent_configs_; | 134 return forward_dependent_configs_; |
134 } | 135 } |
135 LabelTargetVector& forward_dependent_configs() { | 136 UniqueVector<LabelTargetPair>& forward_dependent_configs() { |
136 return forward_dependent_configs_; | 137 return forward_dependent_configs_; |
137 } | 138 } |
138 | 139 |
139 const std::set<const Target*>& inherited_libraries() const { | 140 const UniqueVector<const Target*>& inherited_libraries() const { |
140 return inherited_libraries_; | 141 return inherited_libraries_; |
141 } | 142 } |
142 | 143 |
143 // This config represents the configuration set directly on this target. | 144 // This config represents the configuration set directly on this target. |
144 ConfigValues& config_values() { return config_values_; } | 145 ConfigValues& config_values() { return config_values_; } |
145 const ConfigValues& config_values() const { return config_values_; } | 146 const ConfigValues& config_values() const { return config_values_; } |
146 | 147 |
147 ActionValues& action_values() { return action_values_; } | 148 ActionValues& action_values() { return action_values_; } |
148 const ActionValues& action_values() const { return action_values_; } | 149 const ActionValues& action_values() const { return action_values_; } |
149 | 150 |
150 const OrderedSet<SourceDir>& all_lib_dirs() const { return all_lib_dirs_; } | 151 const OrderedSet<SourceDir>& all_lib_dirs() const { return all_lib_dirs_; } |
151 const OrderedSet<std::string>& all_libs() const { return all_libs_; } | 152 const OrderedSet<std::string>& all_libs() const { return all_libs_; } |
152 | 153 |
153 const std::set<const Target*>& recursive_hard_deps() const { | 154 const std::set<const Target*>& recursive_hard_deps() const { |
154 return recursive_hard_deps_; | 155 return recursive_hard_deps_; |
155 } | 156 } |
156 | 157 |
157 private: | 158 private: |
158 // Pulls necessary information from dependencies to this one when all | 159 // Pulls necessary information from dependencies to this one when all |
159 // dependencies have been resolved. | 160 // dependencies have been resolved. |
160 void PullDependentTargetInfo(std::set<const Config*>* unique_configs); | 161 void PullDependentTargetInfo(); |
161 | 162 |
162 // These each pull specific things from dependencies to this one when all | 163 // These each pull specific things from dependencies to this one when all |
163 // deps have been resolved. | 164 // deps have been resolved. |
164 void PullForwardedDependentConfigs(); | 165 void PullForwardedDependentConfigs(); |
165 void PullRecursiveHardDeps(); | 166 void PullRecursiveHardDeps(); |
166 | 167 |
167 OutputType output_type_; | 168 OutputType output_type_; |
168 std::string output_name_; | 169 std::string output_name_; |
169 std::string output_extension_; | 170 std::string output_extension_; |
170 | 171 |
(...skipping 12 matching lines...) Expand all Loading... |
183 // groups of dependencies, so adding the groups deps make this happen with | 184 // groups of dependencies, so adding the groups deps make this happen with |
184 // no additional complexity when iterating over a target's deps. | 185 // no additional complexity when iterating over a target's deps. |
185 // | 186 // |
186 // However, a group may also have specific settings and configs added to it, | 187 // 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 // 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 // shouldn't need to look inside the deps of the group since those will |
189 // already be added. | 190 // already be added. |
190 LabelTargetVector deps_; | 191 LabelTargetVector deps_; |
191 LabelTargetVector datadeps_; | 192 LabelTargetVector datadeps_; |
192 | 193 |
193 LabelConfigVector configs_; | 194 UniqueVector<LabelConfigPair> configs_; |
194 LabelConfigVector all_dependent_configs_; | 195 UniqueVector<LabelConfigPair> all_dependent_configs_; |
195 LabelConfigVector direct_dependent_configs_; | 196 UniqueVector<LabelConfigPair> direct_dependent_configs_; |
196 LabelTargetVector forward_dependent_configs_; | 197 UniqueVector<LabelTargetPair> forward_dependent_configs_; |
197 | 198 |
198 bool external_; | 199 bool external_; |
199 | 200 |
200 // Static libraries and source sets from transitive deps. These things need | 201 // 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 // 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 // sets do not get pushed beyond static library boundaries, and neither |
203 // source sets nor static libraries get pushed beyond sahred library | 204 // source sets nor static libraries get pushed beyond sahred library |
204 // boundaries. | 205 // boundaries. |
205 std::set<const Target*> inherited_libraries_; | 206 UniqueVector<const Target*> inherited_libraries_; |
206 | 207 |
207 // These libs and dirs are inherited from statically linked deps and all | 208 // These libs and dirs are inherited from statically linked deps and all |
208 // configs applying to this target. | 209 // configs applying to this target. |
209 OrderedSet<SourceDir> all_lib_dirs_; | 210 OrderedSet<SourceDir> all_lib_dirs_; |
210 OrderedSet<std::string> all_libs_; | 211 OrderedSet<std::string> all_libs_; |
211 | 212 |
212 // All hard deps from this target and all dependencies. Filled in when this | 213 // 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 // target is marked resolved. This will not include the current target. |
214 std::set<const Target*> recursive_hard_deps_; | 215 std::set<const Target*> recursive_hard_deps_; |
215 | 216 |
216 ConfigValues config_values_; // Used for all binary targets. | 217 ConfigValues config_values_; // Used for all binary targets. |
217 ActionValues action_values_; // Used for action[_foreach] targets. | 218 ActionValues action_values_; // Used for action[_foreach] targets. |
218 | 219 |
219 DISALLOW_COPY_AND_ASSIGN(Target); | 220 DISALLOW_COPY_AND_ASSIGN(Target); |
220 }; | 221 }; |
221 | 222 |
| 223 namespace BASE_HASH_NAMESPACE { |
| 224 |
| 225 #if defined(COMPILER_GCC) |
| 226 template<> struct hash<const Target*> { |
| 227 std::size_t operator()(const Target* t) const { |
| 228 return reinterpret_cast<std::size_t>(t); |
| 229 } |
| 230 }; |
| 231 #elif defined(COMPILER_MSVC) |
| 232 inline size_t hash_value(const Target* t) { |
| 233 return reinterpret_cast<size_t>(t); |
| 234 } |
| 235 #endif // COMPILER... |
| 236 |
| 237 } // namespace BASE_HASH_NAMESPACE |
| 238 |
222 #endif // TOOLS_GN_TARGET_H_ | 239 #endif // TOOLS_GN_TARGET_H_ |
OLD | NEW |