| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // to avoid duplicate checking. | 76 // to avoid duplicate checking. |
| 77 // | 77 // |
| 78 // Checking of object files is optional because it is much slower. This allows | 78 // 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 | 79 // 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 | 80 // object files (since we know it will be an error otherwise). This allows |
| 81 // us to avoid computing all object file names in the common case. | 81 // us to avoid computing all object file names in the common case. |
| 82 bool EnsureFileIsGeneratedByDependency(const Target* target, | 82 bool EnsureFileIsGeneratedByDependency(const Target* target, |
| 83 const OutputFile& file, | 83 const OutputFile& file, |
| 84 bool check_private_deps, | 84 bool check_private_deps, |
| 85 bool consider_object_files, | 85 bool consider_object_files, |
| 86 bool check_data_deps, |
| 86 std::set<const Target*>* seen_targets) { | 87 std::set<const Target*>* seen_targets) { |
| 87 if (seen_targets->find(target) != seen_targets->end()) | 88 if (seen_targets->find(target) != seen_targets->end()) |
| 88 return false; // Already checked this one and it's not found. | 89 return false; // Already checked this one and it's not found. |
| 89 seen_targets->insert(target); | 90 seen_targets->insert(target); |
| 90 | 91 |
| 91 // Assume that we have relatively few generated inputs so brute-force | 92 // Assume that we have relatively few generated inputs so brute-force |
| 92 // searching here is OK. If this becomes a bottleneck, consider storing | 93 // searching here is OK. If this becomes a bottleneck, consider storing |
| 93 // computed_outputs as a hash set. | 94 // computed_outputs as a hash set. |
| 94 for (const OutputFile& cur : target->computed_outputs()) { | 95 for (const OutputFile& cur : target->computed_outputs()) { |
| 95 if (file == cur) | 96 if (file == cur) |
| 96 return true; | 97 return true; |
| 97 } | 98 } |
| 98 | 99 |
| 100 if (file == target->write_runtime_deps_output()) { |
| 101 return true; |
| 102 } |
| 103 |
| 99 // Check binary target intermediate files if requested. | 104 // Check binary target intermediate files if requested. |
| 100 if (consider_object_files && target->IsBinary()) { | 105 if (consider_object_files && target->IsBinary()) { |
| 101 std::vector<OutputFile> source_outputs; | 106 std::vector<OutputFile> source_outputs; |
| 102 for (const SourceFile& source : target->sources()) { | 107 for (const SourceFile& source : target->sources()) { |
| 103 Toolchain::ToolType tool_type; | 108 Toolchain::ToolType tool_type; |
| 104 if (!target->GetOutputFilesForSource(source, &tool_type, &source_outputs)) | 109 if (!target->GetOutputFilesForSource(source, &tool_type, &source_outputs)) |
| 105 continue; | 110 continue; |
| 106 if (std::find(source_outputs.begin(), source_outputs.end(), file) != | 111 if (std::find(source_outputs.begin(), source_outputs.end(), file) != |
| 107 source_outputs.end()) | 112 source_outputs.end()) |
| 108 return true; | 113 return true; |
| 109 } | 114 } |
| 110 } | 115 } |
| 111 | 116 |
| 117 if (check_data_deps) { |
| 118 check_data_deps = false; // Consider only direct data_deps. |
| 119 for (const auto& pair : target->data_deps()) { |
| 120 if (EnsureFileIsGeneratedByDependency(pair.ptr, file, false, |
| 121 consider_object_files, |
| 122 check_data_deps, seen_targets)) |
| 123 return true; // Found a path. |
| 124 } |
| 125 } |
| 126 |
| 112 // Check all public dependencies (don't do data ones since those are | 127 // Check all public dependencies (don't do data ones since those are |
| 113 // runtime-only). | 128 // runtime-only). |
| 114 for (const auto& pair : target->public_deps()) { | 129 for (const auto& pair : target->public_deps()) { |
| 115 if (EnsureFileIsGeneratedByDependency(pair.ptr, file, false, | 130 if (EnsureFileIsGeneratedByDependency(pair.ptr, file, false, |
| 116 consider_object_files, seen_targets)) | 131 consider_object_files, |
| 132 check_data_deps, seen_targets)) |
| 117 return true; // Found a path. | 133 return true; // Found a path. |
| 118 } | 134 } |
| 119 | 135 |
| 120 // Only check private deps if requested. | 136 // Only check private deps if requested. |
| 121 if (check_private_deps) { | 137 if (check_private_deps) { |
| 122 for (const auto& pair : target->private_deps()) { | 138 for (const auto& pair : target->private_deps()) { |
| 123 if (EnsureFileIsGeneratedByDependency(pair.ptr, file, false, | 139 if (EnsureFileIsGeneratedByDependency(pair.ptr, file, false, |
| 124 consider_object_files, | 140 consider_object_files, |
| 125 seen_targets)) | 141 check_data_deps, seen_targets)) |
| 126 return true; // Found a path. | 142 return true; // Found a path. |
| 127 } | 143 } |
| 128 } | 144 } |
| 129 return false; | 145 return false; |
| 130 } | 146 } |
| 131 | 147 |
| 132 // check_this indicates if the given target should be matched against the | 148 // check_this indicates if the given target should be matched against the |
| 133 // patterns. It should be set to false for the first call since assert_no_deps | 149 // patterns. It should be set to false for the first call since assert_no_deps |
| 134 // shouldn't match the target itself. | 150 // shouldn't match the target itself. |
| 135 // | 151 // |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 void Target::CheckSourceGenerated(const SourceFile& source) const { | 770 void Target::CheckSourceGenerated(const SourceFile& source) const { |
| 755 if (!IsStringInOutputDir(settings()->build_settings()->build_dir(), | 771 if (!IsStringInOutputDir(settings()->build_settings()->build_dir(), |
| 756 source.value())) | 772 source.value())) |
| 757 return; // Not in output dir, this is OK. | 773 return; // Not in output dir, this is OK. |
| 758 | 774 |
| 759 // Tell the scheduler about unknown files. This will be noted for later so | 775 // Tell the scheduler about unknown files. This will be noted for later so |
| 760 // the list of files written by the GN build itself (often response files) | 776 // the list of files written by the GN build itself (often response files) |
| 761 // can be filtered out of this list. | 777 // can be filtered out of this list. |
| 762 OutputFile out_file(settings()->build_settings(), source); | 778 OutputFile out_file(settings()->build_settings(), source); |
| 763 std::set<const Target*> seen_targets; | 779 std::set<const Target*> seen_targets; |
| 764 if (!EnsureFileIsGeneratedByDependency(this, out_file, true, false, | 780 bool check_data_deps = false; |
| 781 bool consider_object_files = false; |
| 782 if (!EnsureFileIsGeneratedByDependency(this, out_file, true, |
| 783 consider_object_files, check_data_deps, |
| 765 &seen_targets)) { | 784 &seen_targets)) { |
| 785 seen_targets.clear(); |
| 786 // Allow dependency to be through data_deps for files generated by gn. |
| 787 check_data_deps = g_scheduler->IsFileGeneratedByWriteRuntimeDeps(out_file); |
| 766 // Check object files (much slower and very rare) only if the "normal" | 788 // Check object files (much slower and very rare) only if the "normal" |
| 767 // output check failed. | 789 // output check failed. |
| 768 seen_targets.clear(); | 790 consider_object_files = !check_data_deps; |
| 769 if (!EnsureFileIsGeneratedByDependency(this, out_file, true, true, | 791 if (!EnsureFileIsGeneratedByDependency(this, out_file, true, |
| 770 &seen_targets)) | 792 consider_object_files, |
| 793 check_data_deps, &seen_targets)) |
| 771 g_scheduler->AddUnknownGeneratedInput(this, source); | 794 g_scheduler->AddUnknownGeneratedInput(this, source); |
| 772 } | 795 } |
| 773 } | 796 } |
| OLD | NEW |