Chromium Code Reviews| 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 29 matching lines...) Expand all Loading... | |
| 40 return Err(from->defined_from(), "Test-only dependency not allowed.", | 40 return Err(from->defined_from(), "Test-only dependency not allowed.", |
| 41 from->label().GetUserVisibleName(false) + "\n" | 41 from->label().GetUserVisibleName(false) + "\n" |
| 42 "which is NOT marked testonly can't depend on\n" + | 42 "which is NOT marked testonly can't depend on\n" + |
| 43 to->label().GetUserVisibleName(false) + "\n" | 43 to->label().GetUserVisibleName(false) + "\n" |
| 44 "which is marked testonly. Only targets with \"testonly = true\"\n" | 44 "which is marked testonly. Only targets with \"testonly = true\"\n" |
| 45 "can depend on other test-only targets.\n" | 45 "can depend on other test-only targets.\n" |
| 46 "\n" | 46 "\n" |
| 47 "Either mark it test-only or don't do this dependency."); | 47 "Either mark it test-only or don't do this dependency."); |
| 48 } | 48 } |
| 49 | 49 |
| 50 Err MakeStaticLibDepsError(const Target* from, const Target* to) { | |
| 51 return Err(from->defined_from(), | |
| 52 "Complete static libraries can't depend on static libraries.", | |
| 53 from->label().GetUserVisibleName(false) + | |
| 54 "\n" | |
| 55 "which is a complete static library can't depend on\n" + | |
| 56 to->label().GetUserVisibleName(false) + | |
| 57 "\n" | |
| 58 "which is a static library.\n" | |
| 59 "\n" | |
| 60 "Use source sets for intermediate targets instead."); | |
| 61 } | |
| 62 | |
| 63 } // namespace | 50 } // namespace |
| 64 | 51 |
| 65 Target::Target(const Settings* settings, const Label& label) | 52 Target::Target(const Settings* settings, const Label& label) |
| 66 : Item(settings, label), | 53 : Item(settings, label), |
| 67 output_type_(UNKNOWN), | 54 output_type_(UNKNOWN), |
| 68 all_headers_public_(true), | 55 all_headers_public_(true), |
| 69 check_includes_(true), | 56 check_includes_(true), |
| 70 complete_static_lib_(false), | 57 complete_static_lib_(false), |
| 71 testonly_(false), | 58 testonly_(false), |
| 72 toolchain_(nullptr) { | 59 toolchain_(nullptr) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 PullDependentTargets(); | 116 PullDependentTargets(); |
| 130 PullForwardedDependentConfigs(); | 117 PullForwardedDependentConfigs(); |
| 131 PullRecursiveHardDeps(); | 118 PullRecursiveHardDeps(); |
| 132 | 119 |
| 133 FillOutputFiles(); | 120 FillOutputFiles(); |
| 134 | 121 |
| 135 if (!CheckVisibility(err)) | 122 if (!CheckVisibility(err)) |
| 136 return false; | 123 return false; |
| 137 if (!CheckTestonly(err)) | 124 if (!CheckTestonly(err)) |
| 138 return false; | 125 return false; |
| 139 if (!CheckNoNestedStaticLibs(err)) | |
| 140 return false; | |
| 141 | 126 |
| 142 return true; | 127 return true; |
| 143 } | 128 } |
| 144 | 129 |
| 145 bool Target::IsLinkable() const { | 130 bool Target::IsLinkable() const { |
| 146 return output_type_ == STATIC_LIBRARY || output_type_ == SHARED_LIBRARY; | 131 return output_type_ == STATIC_LIBRARY || output_type_ == SHARED_LIBRARY; |
| 147 } | 132 } |
| 148 | 133 |
| 149 bool Target::IsFinal() const { | 134 bool Target::IsFinal() const { |
| 150 return output_type_ == EXECUTABLE || output_type_ == SHARED_LIBRARY || | 135 return output_type_ == EXECUTABLE || output_type_ == SHARED_LIBRARY || |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 // | 222 // |
| 238 // Static libraries and source sets aren't inherited across shared | 223 // Static libraries and source sets aren't inherited across shared |
| 239 // library boundaries because they will be linked into the shared | 224 // library boundaries because they will be linked into the shared |
| 240 // library. | 225 // library. |
| 241 inherited_libraries_.AppendPublicSharedLibraries( | 226 inherited_libraries_.AppendPublicSharedLibraries( |
| 242 dep->inherited_libraries(), is_public); | 227 dep->inherited_libraries(), is_public); |
| 243 } else if (!dep->IsFinal()) { | 228 } else if (!dep->IsFinal()) { |
| 244 // The current target isn't linked, so propogate linked deps and | 229 // The current target isn't linked, so propogate linked deps and |
| 245 // libraries up the dependency tree. | 230 // libraries up the dependency tree. |
| 246 inherited_libraries_.AppendInherited(dep->inherited_libraries(), is_public); | 231 inherited_libraries_.AppendInherited(dep->inherited_libraries(), is_public); |
| 232 } else if (dep->complete_static_lib()) { | |
| 233 // Inherit only final targets through _complete_ static libraries. | |
| 234 // | |
| 235 // Inherited final libraries aren't linked into complete static libraries. | |
| 236 // They are forwarded here so that targets that depend on complete | |
| 237 // static libraries can link them in. Conversely, since complete static | |
| 238 // libraries link in non-final targets they shouldn't be inherited. | |
| 239 for (const auto& inherited : | |
| 240 dep->inherited_libraries().GetOrderedAndPublicFlag()) { | |
| 241 if (inherited.first->IsFinal()) | |
| 242 inherited_libraries_.Append(inherited.first, | |
| 243 is_public && inherited.second); | |
|
kal
2015/04/27 21:10:34
Does the is_public handling here make sense?
| |
| 244 } | |
| 245 } | |
| 247 | 246 |
| 248 // Inherited library settings. | 247 // Library settings are always inherited across static library boundaries. |
| 248 if (!dep->IsFinal() || dep->output_type() == STATIC_LIBRARY) { | |
| 249 all_lib_dirs_.append(dep->all_lib_dirs()); | 249 all_lib_dirs_.append(dep->all_lib_dirs()); |
| 250 all_libs_.append(dep->all_libs()); | 250 all_libs_.append(dep->all_libs()); |
| 251 } | 251 } |
| 252 } | 252 } |
| 253 | 253 |
| 254 void Target::PullDependentTargets() { | 254 void Target::PullDependentTargets() { |
| 255 for (const auto& dep : public_deps_) | 255 for (const auto& dep : public_deps_) |
| 256 PullDependentTarget(dep.ptr, true); | 256 PullDependentTarget(dep.ptr, true); |
| 257 for (const auto& dep : private_deps_) | 257 for (const auto& dep : private_deps_) |
| 258 PullDependentTarget(dep.ptr, false); | 258 PullDependentTarget(dep.ptr, false); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 378 // Verify no deps have "testonly" set. | 378 // Verify no deps have "testonly" set. |
| 379 for (const auto& pair : GetDeps(DEPS_ALL)) { | 379 for (const auto& pair : GetDeps(DEPS_ALL)) { |
| 380 if (pair.ptr->testonly()) { | 380 if (pair.ptr->testonly()) { |
| 381 *err = MakeTestOnlyError(this, pair.ptr); | 381 *err = MakeTestOnlyError(this, pair.ptr); |
| 382 return false; | 382 return false; |
| 383 } | 383 } |
| 384 } | 384 } |
| 385 | 385 |
| 386 return true; | 386 return true; |
| 387 } | 387 } |
| 388 | |
| 389 bool Target::CheckNoNestedStaticLibs(Err* err) const { | |
| 390 // If the current target is not a complete static library, it can depend on | |
| 391 // static library targets with no problem. | |
| 392 if (!(output_type() == Target::STATIC_LIBRARY && complete_static_lib())) | |
| 393 return true; | |
| 394 | |
| 395 // Verify no deps are static libraries. | |
| 396 for (const auto& pair : GetDeps(DEPS_ALL)) { | |
| 397 if (pair.ptr->output_type() == Target::STATIC_LIBRARY) { | |
| 398 *err = MakeStaticLibDepsError(this, pair.ptr); | |
| 399 return false; | |
| 400 } | |
| 401 } | |
| 402 | |
| 403 // Verify no inherited libraries are static libraries. | |
| 404 for (const auto& lib : inherited_libraries().GetOrdered()) { | |
| 405 if (lib->output_type() == Target::STATIC_LIBRARY) { | |
| 406 *err = MakeStaticLibDepsError(this, lib); | |
| 407 return false; | |
| 408 } | |
| 409 } | |
| 410 return true; | |
| 411 } | |
| OLD | NEW |