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> |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 FileList& data() { return data_; } | 118 FileList& data() { return data_; } |
119 | 119 |
120 // Returns true if targets depending on this one should have an order | 120 // Returns true if targets depending on this one should have an order |
121 // dependency. | 121 // dependency. |
122 bool hard_dep() const { | 122 bool hard_dep() const { |
123 return output_type_ == ACTION || | 123 return output_type_ == ACTION || |
124 output_type_ == ACTION_FOREACH || | 124 output_type_ == ACTION_FOREACH || |
125 output_type_ == COPY_FILES; | 125 output_type_ == COPY_FILES; |
126 } | 126 } |
127 | 127 |
128 // Linked dependencies. | 128 // Linked private dependencies. |
129 const LabelTargetVector& deps() const { return deps_; } | 129 const LabelTargetVector& private_deps() const { return private_deps_; } |
130 LabelTargetVector& deps() { return deps_; } | 130 LabelTargetVector& private_deps() { return private_deps_; } |
131 | |
132 // Linked public dependencies. | |
133 const LabelTargetVector& public_deps() const { return public_deps_; } | |
134 LabelTargetVector& public_deps() { return public_deps_; } | |
131 | 135 |
132 // Non-linked dependencies. | 136 // Non-linked dependencies. |
133 const LabelTargetVector& datadeps() const { return datadeps_; } | 137 const LabelTargetVector& data_deps() const { return data_deps_; } |
134 LabelTargetVector& datadeps() { return datadeps_; } | 138 LabelTargetVector& data_deps() { return data_deps_; } |
135 | 139 |
136 // List of configs that this class inherits settings from. Once a target is | 140 // List of configs that this class inherits settings from. Once a target is |
137 // resolved, this will also list all- and direct-dependent configs. | 141 // resolved, this will also list all-dependent and public configs. |
138 const UniqueVector<LabelConfigPair>& configs() const { return configs_; } | 142 const UniqueVector<LabelConfigPair>& configs() const { return configs_; } |
139 UniqueVector<LabelConfigPair>& configs() { return configs_; } | 143 UniqueVector<LabelConfigPair>& configs() { return configs_; } |
140 | 144 |
141 // List of configs that all dependencies (direct and indirect) of this | 145 // List of configs that all dependencies (direct and indirect) of this |
142 // target get. These configs are not added to this target. Note that due | 146 // target get. These configs are not added to this target. Note that due |
143 // to the way this is computed, there may be duplicates in this list. | 147 // to the way this is computed, there may be duplicates in this list. |
144 const UniqueVector<LabelConfigPair>& all_dependent_configs() const { | 148 const UniqueVector<LabelConfigPair>& all_dependent_configs() const { |
145 return all_dependent_configs_; | 149 return all_dependent_configs_; |
146 } | 150 } |
147 UniqueVector<LabelConfigPair>& all_dependent_configs() { | 151 UniqueVector<LabelConfigPair>& all_dependent_configs() { |
148 return all_dependent_configs_; | 152 return all_dependent_configs_; |
149 } | 153 } |
150 | 154 |
151 // List of configs that targets depending directly on this one get. These | 155 // List of configs that targets depending directly on this one get. These |
152 // configs are not added to this target. | 156 // configs are also added to this target. |
153 const UniqueVector<LabelConfigPair>& direct_dependent_configs() const { | 157 const UniqueVector<LabelConfigPair>& public_configs() const { |
154 return direct_dependent_configs_; | 158 return public_configs_; |
155 } | 159 } |
156 UniqueVector<LabelConfigPair>& direct_dependent_configs() { | 160 UniqueVector<LabelConfigPair>& public_configs() { |
157 return direct_dependent_configs_; | 161 return public_configs_; |
158 } | 162 } |
159 | 163 |
160 // A list of a subset of deps where we'll re-export direct_dependent_configs | 164 // A list of a subset of deps where we'll re-export public_configs as |
161 // as direct_dependent_configs of this target. | 165 // public_configs of this target. |
162 const UniqueVector<LabelTargetPair>& forward_dependent_configs() const { | 166 const UniqueVector<LabelTargetPair>& forward_dependent_configs() const { |
163 return forward_dependent_configs_; | 167 return forward_dependent_configs_; |
164 } | 168 } |
165 UniqueVector<LabelTargetPair>& forward_dependent_configs() { | 169 UniqueVector<LabelTargetPair>& forward_dependent_configs() { |
166 return forward_dependent_configs_; | 170 return forward_dependent_configs_; |
167 } | 171 } |
168 | 172 |
169 // Dependencies that can include files from this target. | 173 // Dependencies that can include files from this target. |
170 const std::set<Label>& allow_circular_includes_from() const { | 174 const std::set<Label>& allow_circular_includes_from() const { |
171 return allow_circular_includes_from_; | 175 return allow_circular_includes_from_; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 // that. This is a cache of the files to prevent every target that depends on | 221 // that. This is a cache of the files to prevent every target that depends on |
218 // a given library from recomputing the same pattern. | 222 // a given library from recomputing the same pattern. |
219 const OutputFile& link_output_file() const { | 223 const OutputFile& link_output_file() const { |
220 return link_output_file_; | 224 return link_output_file_; |
221 } | 225 } |
222 const OutputFile& dependency_output_file() const { | 226 const OutputFile& dependency_output_file() const { |
223 return dependency_output_file_; | 227 return dependency_output_file_; |
224 } | 228 } |
225 | 229 |
226 private: | 230 private: |
227 void ExpandGroups(); | |
228 | |
229 // Pulls necessary information from dependencies to this one when all | 231 // Pulls necessary information from dependencies to this one when all |
230 // dependencies have been resolved. | 232 // dependencies have been resolved. |
231 void PullDependentTargetInfo(); | 233 void PullDependentTargetInfo(); |
232 | 234 |
233 // These each pull specific things from dependencies to this one when all | 235 // These each pull specific things from dependencies to this one when all |
234 // deps have been resolved. | 236 // deps have been resolved. |
235 void PullForwardedDependentConfigs(); | 237 void PullForwardedDependentConfigs(); |
238 void PullForwardedDependentConfigsFrom(const Target* from); | |
236 void PullRecursiveHardDeps(); | 239 void PullRecursiveHardDeps(); |
237 | 240 |
238 // Fills the link and dependency output files when a target is resolved. | 241 // Fills the link and dependency output files when a target is resolved. |
239 void FillOutputFiles(); | 242 void FillOutputFiles(); |
240 | 243 |
241 // Validates the given thing when a target is resolved. | 244 // Validates the given thing when a target is resolved. |
242 bool CheckVisibility(Err* err) const; | 245 bool CheckVisibility(Err* err) const; |
243 bool CheckTestonly(Err* err) const; | 246 bool CheckTestonly(Err* err) const; |
244 | 247 |
245 OutputType output_type_; | 248 OutputType output_type_; |
246 std::string output_name_; | 249 std::string output_name_; |
247 std::string output_extension_; | 250 std::string output_extension_; |
248 | 251 |
249 FileList sources_; | 252 FileList sources_; |
250 bool all_headers_public_; | 253 bool all_headers_public_; |
251 FileList public_headers_; | 254 FileList public_headers_; |
252 bool check_includes_; | 255 bool check_includes_; |
253 bool complete_static_lib_; | 256 bool complete_static_lib_; |
254 bool testonly_; | 257 bool testonly_; |
255 FileList inputs_; | 258 FileList inputs_; |
256 FileList data_; | 259 FileList data_; |
257 | 260 |
258 bool hard_dep_; | 261 bool hard_dep_; |
259 | 262 |
260 // Note that if there are any groups in the deps, once the target is resolved | 263 LabelTargetVector private_deps_; |
261 // these vectors will list *both* the groups as well as the groups' deps. | 264 LabelTargetVector public_deps_; |
262 // | 265 LabelTargetVector data_deps_; |
263 // This is because, in general, groups should be "transparent" ways to add | |
264 // groups of dependencies, so adding the groups deps make this happen with | |
265 // no additional complexity when iterating over a target's deps. | |
266 // | |
267 // However, a group may also have specific settings and configs added to it, | |
268 // so we also need the group in the list so we find these things. But you | |
269 // shouldn't need to look inside the deps of the group since those will | |
270 // already be added. | |
271 LabelTargetVector deps_; | |
272 LabelTargetVector datadeps_; | |
273 | 266 |
274 UniqueVector<LabelConfigPair> configs_; | 267 UniqueVector<LabelConfigPair> configs_; |
275 UniqueVector<LabelConfigPair> all_dependent_configs_; | 268 UniqueVector<LabelConfigPair> all_dependent_configs_; |
276 UniqueVector<LabelConfigPair> direct_dependent_configs_; | 269 UniqueVector<LabelConfigPair> public_configs_; |
277 UniqueVector<LabelTargetPair> forward_dependent_configs_; | 270 UniqueVector<LabelTargetPair> forward_dependent_configs_; |
278 | 271 |
279 std::set<Label> allow_circular_includes_from_; | 272 std::set<Label> allow_circular_includes_from_; |
280 | 273 |
281 bool external_; | 274 bool external_; |
282 | 275 |
283 // Static libraries and source sets from transitive deps. These things need | 276 // Static libraries and source sets from transitive deps. These things need |
284 // to be linked only with the end target (executable, shared library). Source | 277 // to be linked only with the end target (executable, shared library). Source |
285 // sets do not get pushed beyond static library boundaries, and neither | 278 // sets do not get pushed beyond static library boundaries, and neither |
286 // source sets nor static libraries get pushed beyond sahred library | 279 // source sets nor static libraries get pushed beyond sahred library |
(...skipping 15 matching lines...) Expand all Loading... | |
302 // Toolchain used by this target. Null until target is resolved. | 295 // Toolchain used by this target. Null until target is resolved. |
303 const Toolchain* toolchain_; | 296 const Toolchain* toolchain_; |
304 | 297 |
305 // Output files. Null until the target is resolved. | 298 // Output files. Null until the target is resolved. |
306 OutputFile link_output_file_; | 299 OutputFile link_output_file_; |
307 OutputFile dependency_output_file_; | 300 OutputFile dependency_output_file_; |
308 | 301 |
309 DISALLOW_COPY_AND_ASSIGN(Target); | 302 DISALLOW_COPY_AND_ASSIGN(Target); |
310 }; | 303 }; |
311 | 304 |
305 // Iterates over the deps of a target. | |
306 // | |
307 // Since there are multiple kinds of deps, this iterator allows looping over | |
308 // each one in one loop. | |
309 class DepsIterator { | |
jamesr
2014/09/16 20:09:25
imho this should get its own .h/.cc
| |
310 public: | |
311 enum LinkedOnly { | |
312 LINKED_ONLY, | |
313 }; | |
314 | |
315 // Iterate over public, private, and data deps. | |
316 explicit DepsIterator(const Target* t); | |
317 | |
318 // Iterate over the public and private linked deps, but not the data deps. | |
319 DepsIterator(const Target* t, LinkedOnly); | |
320 | |
321 // Returns true when there are no more targets. | |
322 bool done() const { | |
323 return !vect_stack_[0]; | |
324 } | |
325 | |
326 // Advance to the next position. This assumes there are more vectors. | |
jamesr
2014/09/16 20:09:25
'more vectors' -> 'more targets' ?
| |
327 // | |
328 // For internal use, this function tolerates an initial index equal to the | |
329 // length of the current vector. In this case, it will advance to the next | |
330 // one. | |
331 void Advance(); | |
332 | |
333 // The current dependency. | |
334 const LabelTargetPair& pair() const { | |
335 DCHECK(current_index_ < vect_stack_[0]->size()); | |
jamesr
2014/09/16 20:09:25
DCHECK_LT will print the lhs and rhs when the asse
| |
336 return (*vect_stack_[0])[current_index_]; | |
337 } | |
338 | |
339 // The pointer to the current dependency. | |
340 const Target* target() const { return pair().ptr; } | |
341 | |
342 // The label of the current dependency. | |
343 const Label& label() const { return pair().label; } | |
344 | |
345 private: | |
346 const LabelTargetVector* vect_stack_[3]; | |
347 | |
348 size_t current_index_; | |
349 | |
350 DISALLOW_COPY_AND_ASSIGN(DepsIterator); | |
351 }; | |
352 | |
312 namespace BASE_HASH_NAMESPACE { | 353 namespace BASE_HASH_NAMESPACE { |
313 | 354 |
314 #if defined(COMPILER_GCC) | 355 #if defined(COMPILER_GCC) |
315 template<> struct hash<const Target*> { | 356 template<> struct hash<const Target*> { |
316 std::size_t operator()(const Target* t) const { | 357 std::size_t operator()(const Target* t) const { |
317 return reinterpret_cast<std::size_t>(t); | 358 return reinterpret_cast<std::size_t>(t); |
318 } | 359 } |
319 }; | 360 }; |
320 #elif defined(COMPILER_MSVC) | 361 #elif defined(COMPILER_MSVC) |
321 inline size_t hash_value(const Target* t) { | 362 inline size_t hash_value(const Target* t) { |
322 return reinterpret_cast<size_t>(t); | 363 return reinterpret_cast<size_t>(t); |
323 } | 364 } |
324 #endif // COMPILER... | 365 #endif // COMPILER... |
325 | 366 |
326 } // namespace BASE_HASH_NAMESPACE | 367 } // namespace BASE_HASH_NAMESPACE |
327 | 368 |
328 #endif // TOOLS_GN_TARGET_H_ | 369 #endif // TOOLS_GN_TARGET_H_ |
OLD | NEW |