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 #include "tools/gn/target.h" | 5 #include "tools/gn/target.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "tools/gn/config_values_extractors.h" | 10 #include "tools/gn/config_values_extractors.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
23 const UniqueVector<LabelConfigPair>& pub = from_target->public_configs(); | 23 const UniqueVector<LabelConfigPair>& pub = from_target->public_configs(); |
24 dest->Append(pub.begin(), pub.end()); | 24 dest->Append(pub.begin(), pub.end()); |
25 } | 25 } |
26 | 26 |
27 // Like MergePublicConfigsFrom above except does the "all dependent" ones. This | 27 // Like MergePublicConfigsFrom above except does the "all dependent" ones. This |
28 // additionally adds all configs to the all_dependent_configs_ of the dest | 28 // additionally adds all configs to the all_dependent_configs_ of the dest |
29 // target given in *all_dest. | 29 // target given in *all_dest. |
30 void MergeAllDependentConfigsFrom(const Target* from_target, | 30 void MergeAllDependentConfigsFrom(const Target* from_target, |
31 UniqueVector<LabelConfigPair>* dest, | 31 UniqueVector<LabelConfigPair>* dest, |
32 UniqueVector<LabelConfigPair>* all_dest) { | 32 UniqueVector<LabelConfigPair>* all_dest) { |
33 const UniqueVector<LabelConfigPair>& all = | 33 for (const auto& pair : from_target->all_dependent_configs()) { |
34 from_target->all_dependent_configs(); | 34 all_dest->push_back(pair); |
35 for (size_t i = 0; i < all.size(); i++) { | 35 dest->push_back(pair); |
36 all_dest->push_back(all[i]); | |
37 dest->push_back(all[i]); | |
38 } | 36 } |
39 } | 37 } |
40 | 38 |
41 Err MakeTestOnlyError(const Target* from, const Target* to) { | 39 Err MakeTestOnlyError(const Target* from, const Target* to) { |
42 return Err(from->defined_from(), "Test-only dependency not allowed.", | 40 return Err(from->defined_from(), "Test-only dependency not allowed.", |
43 from->label().GetUserVisibleName(false) + "\n" | 41 from->label().GetUserVisibleName(false) + "\n" |
44 "which is NOT marked testonly can't depend on\n" + | 42 "which is NOT marked testonly can't depend on\n" + |
45 to->label().GetUserVisibleName(false) + "\n" | 43 to->label().GetUserVisibleName(false) + "\n" |
46 "which is marked testonly. Only targets with \"testonly = true\"\n" | 44 "which is marked testonly. Only targets with \"testonly = true\"\n" |
47 "can depend on other test-only targets.\n" | 45 "can depend on other test-only targets.\n" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 | 145 |
148 bool Target::IsLinkable() const { | 146 bool Target::IsLinkable() const { |
149 return output_type_ == STATIC_LIBRARY || output_type_ == SHARED_LIBRARY; | 147 return output_type_ == STATIC_LIBRARY || output_type_ == SHARED_LIBRARY; |
150 } | 148 } |
151 | 149 |
152 bool Target::IsFinal() const { | 150 bool Target::IsFinal() const { |
153 return output_type_ == EXECUTABLE || output_type_ == SHARED_LIBRARY || | 151 return output_type_ == EXECUTABLE || output_type_ == SHARED_LIBRARY || |
154 (output_type_ == STATIC_LIBRARY && complete_static_lib_); | 152 (output_type_ == STATIC_LIBRARY && complete_static_lib_); |
155 } | 153 } |
156 | 154 |
155 DepsIteratorRange Target::GetDeps(DepsIterationType type) const { | |
156 if (type == DEPS_LINKED) { | |
157 return DepsIteratorRange(DepsIterator( | |
158 &public_deps_, &private_deps_, nullptr)); | |
159 } | |
160 // All deps. | |
161 return DepsIteratorRange(DepsIterator( | |
162 &public_deps_, &private_deps_, &data_deps_)); | |
163 } | |
164 | |
157 std::string Target::GetComputedOutputName(bool include_prefix) const { | 165 std::string Target::GetComputedOutputName(bool include_prefix) const { |
158 DCHECK(toolchain_) | 166 DCHECK(toolchain_) |
159 << "Toolchain must be specified before getting the computed output name."; | 167 << "Toolchain must be specified before getting the computed output name."; |
160 | 168 |
161 const std::string& name = output_name_.empty() ? label().name() | 169 const std::string& name = output_name_.empty() ? label().name() |
162 : output_name_; | 170 : output_name_; |
163 | 171 |
164 std::string result; | 172 std::string result; |
165 if (include_prefix) { | 173 if (include_prefix) { |
166 const Tool* tool = toolchain_->GetToolForTargetFinalOutput(this); | 174 const Tool* tool = toolchain_->GetToolForTargetFinalOutput(this); |
(...skipping 29 matching lines...) Expand all Loading... | |
196 GetStringForOutputType(output_type_), | 204 GetStringForOutputType(output_type_), |
197 label().GetToolchainLabel().GetUserVisibleName(false).c_str(), | 205 label().GetToolchainLabel().GetUserVisibleName(false).c_str(), |
198 Toolchain::ToolTypeToName( | 206 Toolchain::ToolTypeToName( |
199 toolchain->GetToolTypeForTargetFinalOutput(this)).c_str())); | 207 toolchain->GetToolTypeForTargetFinalOutput(this)).c_str())); |
200 } | 208 } |
201 return false; | 209 return false; |
202 } | 210 } |
203 | 211 |
204 void Target::PullDependentTargetInfo() { | 212 void Target::PullDependentTargetInfo() { |
205 // Gather info from our dependents we need. | 213 // Gather info from our dependents we need. |
206 for (DepsIterator iter(this, DepsIterator::LINKED_ONLY); !iter.done(); | 214 for (const auto& pair : GetDeps(DEPS_LINKED)) { |
207 iter.Advance()) { | 215 const Target* dep = pair.ptr; |
208 const Target* dep = iter.target(); | |
209 MergeAllDependentConfigsFrom(dep, &configs_, &all_dependent_configs_); | 216 MergeAllDependentConfigsFrom(dep, &configs_, &all_dependent_configs_); |
210 MergePublicConfigsFrom(dep, &configs_); | 217 MergePublicConfigsFrom(dep, &configs_); |
211 | 218 |
212 // Direct dependent libraries. | 219 // Direct dependent libraries. |
213 if (dep->output_type() == STATIC_LIBRARY || | 220 if (dep->output_type() == STATIC_LIBRARY || |
214 dep->output_type() == SHARED_LIBRARY || | 221 dep->output_type() == SHARED_LIBRARY || |
215 dep->output_type() == SOURCE_SET) | 222 dep->output_type() == SOURCE_SET) |
216 inherited_libraries_.push_back(dep); | 223 inherited_libraries_.push_back(dep); |
217 | 224 |
218 // Inherited libraries and flags are inherited across static library | 225 // Inherited libraries and flags are inherited across static library |
219 // boundaries. | 226 // boundaries. |
220 if (!dep->IsFinal()) { | 227 if (!dep->IsFinal()) { |
221 inherited_libraries_.Append(dep->inherited_libraries().begin(), | 228 inherited_libraries_.Append(dep->inherited_libraries().begin(), |
222 dep->inherited_libraries().end()); | 229 dep->inherited_libraries().end()); |
223 | 230 |
224 // Inherited library settings. | 231 // Inherited library settings. |
225 all_lib_dirs_.append(dep->all_lib_dirs()); | 232 all_lib_dirs_.append(dep->all_lib_dirs()); |
226 all_libs_.append(dep->all_libs()); | 233 all_libs_.append(dep->all_libs()); |
227 } | 234 } |
228 } | 235 } |
229 } | 236 } |
230 | 237 |
231 void Target::PullForwardedDependentConfigs() { | 238 void Target::PullForwardedDependentConfigs() { |
232 // Pull public configs from each of our dependency's public deps. | 239 // Pull public configs from each of our dependency's public deps. |
233 for (size_t dep = 0; dep < public_deps_.size(); dep++) | 240 for (const auto& dep : public_deps_) |
234 PullForwardedDependentConfigsFrom(public_deps_[dep].ptr); | 241 PullForwardedDependentConfigsFrom(dep.ptr); |
235 | 242 |
236 // Forward public configs if explicitly requested. | 243 // Forward public configs if explicitly requested. |
237 for (size_t dep = 0; dep < forward_dependent_configs_.size(); dep++) { | 244 for (const auto& dep : forward_dependent_configs_) { |
238 const Target* from_target = forward_dependent_configs_[dep].ptr; | 245 const Target* from_target = dep.ptr; |
239 | 246 |
240 // The forward_dependent_configs_ must be in the deps (public or private) | 247 // The forward_dependent_configs_ must be in the deps (public or private) |
241 // already, so we don't need to bother copying to our configs, only | 248 // already, so we don't need to bother copying to our configs, only |
242 // forwarding. | 249 // forwarding. |
243 DCHECK(std::find_if(private_deps_.begin(), private_deps_.end(), | 250 DCHECK(std::find_if(private_deps_.begin(), private_deps_.end(), |
244 LabelPtrPtrEquals<Target>(from_target)) != | 251 LabelPtrPtrEquals<Target>(from_target)) != |
245 private_deps_.end() || | 252 private_deps_.end() || |
246 std::find_if(public_deps_.begin(), public_deps_.end(), | 253 std::find_if(public_deps_.begin(), public_deps_.end(), |
247 LabelPtrPtrEquals<Target>(from_target)) != | 254 LabelPtrPtrEquals<Target>(from_target)) != |
248 public_deps_.end()); | 255 public_deps_.end()); |
249 | 256 |
250 PullForwardedDependentConfigsFrom(from_target); | 257 PullForwardedDependentConfigsFrom(from_target); |
251 } | 258 } |
252 } | 259 } |
253 | 260 |
254 void Target::PullForwardedDependentConfigsFrom(const Target* from) { | 261 void Target::PullForwardedDependentConfigsFrom(const Target* from) { |
255 public_configs_.Append(from->public_configs().begin(), | 262 public_configs_.Append(from->public_configs().begin(), |
256 from->public_configs().end()); | 263 from->public_configs().end()); |
257 } | 264 } |
258 | 265 |
259 void Target::PullRecursiveHardDeps() { | 266 void Target::PullRecursiveHardDeps() { |
260 for (DepsIterator iter(this, DepsIterator::LINKED_ONLY); !iter.done(); | 267 for (const auto& pair : GetDeps(DEPS_LINKED)) { |
261 iter.Advance()) { | 268 if (pair.ptr->hard_dep()) |
262 if (iter.target()->hard_dep()) | 269 recursive_hard_deps_.insert(pair.ptr); |
263 recursive_hard_deps_.insert(iter.target()); | |
264 | 270 |
265 // Android STL doesn't like insert(begin, end) so do it manually. | 271 // Android STL doesn't like insert(begin, end) so do it manually. |
266 // TODO(brettw) this can be changed to | 272 // TODO(brettw) this can be changed to |
267 // insert(iter.target()->begin(), iter.target()->end()) | 273 // insert(iter.target()->begin(), iter.target()->end()) |
268 // when Android uses a better STL. | 274 // when Android uses a better STL. |
269 for (std::set<const Target*>::const_iterator cur = | 275 for (std::set<const Target*>::const_iterator cur = |
scottmg
2014/09/27 00:40:07
for (const auto& cur : pair.ptr->recursive_hard_de
brettw
2014/09/27 22:21:34
I'm going to do another pass for the rest. I had t
| |
270 iter.target()->recursive_hard_deps().begin(); | 276 pair.ptr->recursive_hard_deps().begin(); |
271 cur != iter.target()->recursive_hard_deps().end(); ++cur) | 277 cur != pair.ptr->recursive_hard_deps().end(); ++cur) |
272 recursive_hard_deps_.insert(*cur); | 278 recursive_hard_deps_.insert(*cur); |
273 } | 279 } |
274 } | 280 } |
275 | 281 |
276 void Target::FillOutputFiles() { | 282 void Target::FillOutputFiles() { |
277 const Tool* tool = toolchain_->GetToolForTargetFinalOutput(this); | 283 const Tool* tool = toolchain_->GetToolForTargetFinalOutput(this); |
278 switch (output_type_) { | 284 switch (output_type_) { |
279 case GROUP: | 285 case GROUP: |
280 case SOURCE_SET: | 286 case SOURCE_SET: |
281 case COPY_FILES: | 287 case COPY_FILES: |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
326 } | 332 } |
327 } | 333 } |
328 break; | 334 break; |
329 case UNKNOWN: | 335 case UNKNOWN: |
330 default: | 336 default: |
331 NOTREACHED(); | 337 NOTREACHED(); |
332 } | 338 } |
333 } | 339 } |
334 | 340 |
335 bool Target::CheckVisibility(Err* err) const { | 341 bool Target::CheckVisibility(Err* err) const { |
336 for (DepsIterator iter(this); !iter.done(); iter.Advance()) { | 342 for (const auto& pair : GetDeps(DEPS_ALL)) { |
337 if (!Visibility::CheckItemVisibility(this, iter.target(), err)) | 343 if (!Visibility::CheckItemVisibility(this, pair.ptr, err)) |
338 return false; | 344 return false; |
339 } | 345 } |
340 return true; | 346 return true; |
341 } | 347 } |
342 | 348 |
343 bool Target::CheckTestonly(Err* err) const { | 349 bool Target::CheckTestonly(Err* err) const { |
344 // If the current target is marked testonly, it can include both testonly | 350 // If the current target is marked testonly, it can include both testonly |
345 // and non-testonly targets, so there's nothing to check. | 351 // and non-testonly targets, so there's nothing to check. |
346 if (testonly()) | 352 if (testonly()) |
347 return true; | 353 return true; |
348 | 354 |
349 // Verify no deps have "testonly" set. | 355 // Verify no deps have "testonly" set. |
350 for (DepsIterator iter(this); !iter.done(); iter.Advance()) { | 356 for (const auto& pair : GetDeps(DEPS_ALL)) { |
351 if (iter.target()->testonly()) { | 357 if (pair.ptr->testonly()) { |
352 *err = MakeTestOnlyError(this, iter.target()); | 358 *err = MakeTestOnlyError(this, pair.ptr); |
353 return false; | 359 return false; |
354 } | 360 } |
355 } | 361 } |
356 | 362 |
357 return true; | 363 return true; |
358 } | 364 } |
359 | 365 |
360 bool Target::CheckNoNestedStaticLibs(Err* err) const { | 366 bool Target::CheckNoNestedStaticLibs(Err* err) const { |
361 // If the current target is not a complete static library, it can depend on | 367 // If the current target is not a complete static library, it can depend on |
362 // static library targets with no problem. | 368 // static library targets with no problem. |
363 if (!(output_type() == Target::STATIC_LIBRARY && complete_static_lib())) | 369 if (!(output_type() == Target::STATIC_LIBRARY && complete_static_lib())) |
364 return true; | 370 return true; |
365 | 371 |
366 // Verify no deps are static libraries. | 372 // Verify no deps are static libraries. |
367 for (DepsIterator iter(this); !iter.done(); iter.Advance()) { | 373 for (const auto& pair : GetDeps(DEPS_ALL)) { |
368 if (iter.target()->output_type() == Target::STATIC_LIBRARY) { | 374 if (pair.ptr->output_type() == Target::STATIC_LIBRARY) { |
369 *err = MakeStaticLibDepsError(this, iter.target()); | 375 *err = MakeStaticLibDepsError(this, pair.ptr); |
370 return false; | 376 return false; |
371 } | 377 } |
372 } | 378 } |
373 | 379 |
374 // Verify no inherited libraries are static libraries. | 380 // Verify no inherited libraries are static libraries. |
375 for (size_t i = 0; i < inherited_libraries().size(); ++i) { | 381 for (const auto& lib : inherited_libraries()) { |
376 if (inherited_libraries()[i]->output_type() == Target::STATIC_LIBRARY) { | 382 if (lib->output_type() == Target::STATIC_LIBRARY) { |
377 *err = MakeStaticLibDepsError(this, inherited_libraries()[i]); | 383 *err = MakeStaticLibDepsError(this, lib); |
378 return false; | 384 return false; |
379 } | 385 } |
380 } | 386 } |
381 return true; | 387 return true; |
382 } | 388 } |
OLD | NEW |