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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 return Err(from->defined_from(), "Test-only dependency not allowed.", | 48 return Err(from->defined_from(), "Test-only dependency not allowed.", |
49 from->label().GetUserVisibleName(false) + "\n" | 49 from->label().GetUserVisibleName(false) + "\n" |
50 "which is NOT marked testonly can't depend on\n" + | 50 "which is NOT marked testonly can't depend on\n" + |
51 to->label().GetUserVisibleName(false) + "\n" | 51 to->label().GetUserVisibleName(false) + "\n" |
52 "which is marked testonly. Only targets with \"testonly = true\"\n" | 52 "which is marked testonly. Only targets with \"testonly = true\"\n" |
53 "can depend on other test-only targets.\n" | 53 "can depend on other test-only targets.\n" |
54 "\n" | 54 "\n" |
55 "Either mark it test-only or don't do this dependency."); | 55 "Either mark it test-only or don't do this dependency."); |
56 } | 56 } |
57 | 57 |
58 Err MakeStaticLibDepsError(const Target* from, const Target* to) { | |
59 return Err(from->defined_from(), | |
60 "Complete static libraries can't depend on static libraries.", | |
61 from->label().GetUserVisibleName(false) + | |
62 "\n" | |
63 "which is a complete static library can't depend on\n" + | |
64 to->label().GetUserVisibleName(false) + | |
65 "\n" | |
66 "which is a static library.\n" | |
67 "\n" | |
68 "Use source sets for intermediate targets instead."); | |
69 } | |
70 | |
71 // Set check_private_deps to true for the first invocation since a target | 58 // Set check_private_deps to true for the first invocation since a target |
72 // can see all of its dependencies. For recursive invocations this will be set | 59 // can see all of its dependencies. For recursive invocations this will be set |
73 // to false to follow only public dependency paths. | 60 // to false to follow only public dependency paths. |
74 // | 61 // |
75 // Pass a pointer to an empty set for the first invocation. This will be used | 62 // Pass a pointer to an empty set for the first invocation. This will be used |
76 // to avoid duplicate checking. | 63 // to avoid duplicate checking. |
77 // | 64 // |
78 // Checking of object files is optional because it is much slower. This allows | 65 // Checking of object files is optional because it is much slower. This allows |
79 // us to check targets for normal outputs, and then as a second pass check | 66 // us to check targets for normal outputs, and then as a second pass check |
80 // object files (since we know it will be an error otherwise). This allows | 67 // object files (since we know it will be an error otherwise). This allows |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 if (!ResolvePrecompiledHeaders(err)) | 297 if (!ResolvePrecompiledHeaders(err)) |
311 return false; | 298 return false; |
312 | 299 |
313 FillOutputFiles(); | 300 FillOutputFiles(); |
314 | 301 |
315 if (settings()->build_settings()->check_for_bad_items()) { | 302 if (settings()->build_settings()->check_for_bad_items()) { |
316 if (!CheckVisibility(err)) | 303 if (!CheckVisibility(err)) |
317 return false; | 304 return false; |
318 if (!CheckTestonly(err)) | 305 if (!CheckTestonly(err)) |
319 return false; | 306 return false; |
320 if (!CheckNoNestedStaticLibs(err)) | |
321 return false; | |
322 if (!CheckAssertNoDeps(err)) | 307 if (!CheckAssertNoDeps(err)) |
323 return false; | 308 return false; |
324 CheckSourcesGenerated(); | 309 CheckSourcesGenerated(); |
325 } | 310 } |
326 | 311 |
327 if (!write_runtime_deps_output_.value().empty()) | 312 if (!write_runtime_deps_output_.value().empty()) |
328 g_scheduler->AddWriteRuntimeDepsTarget(this); | 313 g_scheduler->AddWriteRuntimeDepsTarget(this); |
329 | 314 |
330 return true; | 315 return true; |
331 } | 316 } |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 // | 460 // |
476 // Static libraries and source sets aren't inherited across shared | 461 // Static libraries and source sets aren't inherited across shared |
477 // library boundaries because they will be linked into the shared | 462 // library boundaries because they will be linked into the shared |
478 // library. | 463 // library. |
479 inherited_libraries_.AppendPublicSharedLibraries( | 464 inherited_libraries_.AppendPublicSharedLibraries( |
480 dep->inherited_libraries(), is_public); | 465 dep->inherited_libraries(), is_public); |
481 } else if (!dep->IsFinal()) { | 466 } else if (!dep->IsFinal()) { |
482 // The current target isn't linked, so propogate linked deps and | 467 // The current target isn't linked, so propogate linked deps and |
483 // libraries up the dependency tree. | 468 // libraries up the dependency tree. |
484 inherited_libraries_.AppendInherited(dep->inherited_libraries(), is_public); | 469 inherited_libraries_.AppendInherited(dep->inherited_libraries(), is_public); |
| 470 } else if (dep->complete_static_lib()) { |
| 471 // Inherit only final targets through _complete_ static libraries. |
| 472 // |
| 473 // Inherited final libraries aren't linked into complete static libraries. |
| 474 // They are forwarded here so that targets that depend on complete |
| 475 // static libraries can link them in. Conversely, since complete static |
| 476 // libraries link in non-final targets they shouldn't be inherited. |
| 477 for (const auto& inherited : |
| 478 dep->inherited_libraries().GetOrderedAndPublicFlag()) { |
| 479 if (inherited.first->IsFinal()) { |
| 480 inherited_libraries_.Append(inherited.first, |
| 481 is_public && inherited.second); |
| 482 } |
| 483 } |
| 484 } |
485 | 485 |
486 // Inherited library settings. | 486 // Library settings are always inherited across static library boundaries. |
| 487 if (!dep->IsFinal() || dep->output_type() == STATIC_LIBRARY) { |
487 all_lib_dirs_.append(dep->all_lib_dirs()); | 488 all_lib_dirs_.append(dep->all_lib_dirs()); |
488 all_libs_.append(dep->all_libs()); | 489 all_libs_.append(dep->all_libs()); |
489 } | 490 } |
490 } | 491 } |
491 | 492 |
492 void Target::PullDependentTargetLibs() { | 493 void Target::PullDependentTargetLibs() { |
493 for (const auto& dep : public_deps_) | 494 for (const auto& dep : public_deps_) |
494 PullDependentTargetLibsFrom(dep.ptr, true); | 495 PullDependentTargetLibsFrom(dep.ptr, true); |
495 for (const auto& dep : private_deps_) | 496 for (const auto& dep : private_deps_) |
496 PullDependentTargetLibsFrom(dep.ptr, false); | 497 PullDependentTargetLibsFrom(dep.ptr, false); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 for (const auto& pair : GetDeps(DEPS_ALL)) { | 696 for (const auto& pair : GetDeps(DEPS_ALL)) { |
696 if (pair.ptr->testonly()) { | 697 if (pair.ptr->testonly()) { |
697 *err = MakeTestOnlyError(this, pair.ptr); | 698 *err = MakeTestOnlyError(this, pair.ptr); |
698 return false; | 699 return false; |
699 } | 700 } |
700 } | 701 } |
701 | 702 |
702 return true; | 703 return true; |
703 } | 704 } |
704 | 705 |
705 bool Target::CheckNoNestedStaticLibs(Err* err) const { | |
706 // If the current target is not a complete static library, it can depend on | |
707 // static library targets with no problem. | |
708 if (!(output_type() == Target::STATIC_LIBRARY && complete_static_lib())) | |
709 return true; | |
710 | |
711 // Verify no deps are static libraries. | |
712 for (const auto& pair : GetDeps(DEPS_ALL)) { | |
713 if (pair.ptr->output_type() == Target::STATIC_LIBRARY) { | |
714 *err = MakeStaticLibDepsError(this, pair.ptr); | |
715 return false; | |
716 } | |
717 } | |
718 | |
719 // Verify no inherited libraries are static libraries. | |
720 for (const auto& lib : inherited_libraries().GetOrdered()) { | |
721 if (lib->output_type() == Target::STATIC_LIBRARY) { | |
722 *err = MakeStaticLibDepsError(this, lib); | |
723 return false; | |
724 } | |
725 } | |
726 return true; | |
727 } | |
728 | |
729 bool Target::CheckAssertNoDeps(Err* err) const { | 706 bool Target::CheckAssertNoDeps(Err* err) const { |
730 if (assert_no_deps_.empty()) | 707 if (assert_no_deps_.empty()) |
731 return true; | 708 return true; |
732 | 709 |
733 std::set<const Target*> visited; | 710 std::set<const Target*> visited; |
734 std::string failure_path_str; | 711 std::string failure_path_str; |
735 const LabelPattern* failure_pattern = nullptr; | 712 const LabelPattern* failure_pattern = nullptr; |
736 | 713 |
737 if (!RecursiveCheckAssertNoDeps(this, false, assert_no_deps_, &visited, | 714 if (!RecursiveCheckAssertNoDeps(this, false, assert_no_deps_, &visited, |
738 &failure_path_str, &failure_pattern)) { | 715 &failure_path_str, &failure_pattern)) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 check_data_deps = g_scheduler->IsFileGeneratedByWriteRuntimeDeps(out_file); | 759 check_data_deps = g_scheduler->IsFileGeneratedByWriteRuntimeDeps(out_file); |
783 // Check object files (much slower and very rare) only if the "normal" | 760 // Check object files (much slower and very rare) only if the "normal" |
784 // output check failed. | 761 // output check failed. |
785 consider_object_files = !check_data_deps; | 762 consider_object_files = !check_data_deps; |
786 if (!EnsureFileIsGeneratedByDependency(this, out_file, true, | 763 if (!EnsureFileIsGeneratedByDependency(this, out_file, true, |
787 consider_object_files, | 764 consider_object_files, |
788 check_data_deps, &seen_targets)) | 765 check_data_deps, &seen_targets)) |
789 g_scheduler->AddUnknownGeneratedInput(this, source); | 766 g_scheduler->AddUnknownGeneratedInput(this, source); |
790 } | 767 } |
791 } | 768 } |
OLD | NEW |