| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 119 |
| 120 // Copy our own libs and lib_dirs to the final set. This will be from our | 120 // Copy our own libs and lib_dirs to the final set. This will be from our |
| 121 // target and all of our configs. We do this specially since these must be | 121 // target and all of our configs. We do this specially since these must be |
| 122 // inherited through the dependency tree (other flags don't work this way). | 122 // inherited through the dependency tree (other flags don't work this way). |
| 123 for (ConfigValuesIterator iter(this); !iter.done(); iter.Next()) { | 123 for (ConfigValuesIterator iter(this); !iter.done(); iter.Next()) { |
| 124 const ConfigValues& cur = iter.cur(); | 124 const ConfigValues& cur = iter.cur(); |
| 125 all_lib_dirs_.append(cur.lib_dirs().begin(), cur.lib_dirs().end()); | 125 all_lib_dirs_.append(cur.lib_dirs().begin(), cur.lib_dirs().end()); |
| 126 all_libs_.append(cur.libs().begin(), cur.libs().end()); | 126 all_libs_.append(cur.libs().begin(), cur.libs().end()); |
| 127 } | 127 } |
| 128 | 128 |
| 129 PullDependentTargetInfo(); | 129 PullDependentTargets(); |
| 130 PullForwardedDependentConfigs(); | 130 PullForwardedDependentConfigs(); |
| 131 PullRecursiveHardDeps(); | 131 PullRecursiveHardDeps(); |
| 132 | 132 |
| 133 FillOutputFiles(); | 133 FillOutputFiles(); |
| 134 | 134 |
| 135 if (!CheckVisibility(err)) | 135 if (!CheckVisibility(err)) |
| 136 return false; | 136 return false; |
| 137 if (!CheckTestonly(err)) | 137 if (!CheckTestonly(err)) |
| 138 return false; | 138 return false; |
| 139 if (!CheckNoNestedStaticLibs(err)) | 139 if (!CheckNoNestedStaticLibs(err)) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 "Alas, I can not continue.", | 201 "Alas, I can not continue.", |
| 202 label().GetUserVisibleName(false).c_str(), | 202 label().GetUserVisibleName(false).c_str(), |
| 203 GetStringForOutputType(output_type_), | 203 GetStringForOutputType(output_type_), |
| 204 label().GetToolchainLabel().GetUserVisibleName(false).c_str(), | 204 label().GetToolchainLabel().GetUserVisibleName(false).c_str(), |
| 205 Toolchain::ToolTypeToName( | 205 Toolchain::ToolTypeToName( |
| 206 toolchain->GetToolTypeForTargetFinalOutput(this)).c_str())); | 206 toolchain->GetToolTypeForTargetFinalOutput(this)).c_str())); |
| 207 } | 207 } |
| 208 return false; | 208 return false; |
| 209 } | 209 } |
| 210 | 210 |
| 211 void Target::PullDependentTargetInfo() { | 211 void Target::PullDependentTarget(const Target* dep, bool is_public) { |
| 212 // Gather info from our dependents we need. | 212 MergeAllDependentConfigsFrom(dep, &configs_, &all_dependent_configs_); |
| 213 for (const auto& pair : GetDeps(DEPS_LINKED)) { | 213 MergePublicConfigsFrom(dep, &configs_); |
| 214 const Target* dep = pair.ptr; | |
| 215 MergeAllDependentConfigsFrom(dep, &configs_, &all_dependent_configs_); | |
| 216 MergePublicConfigsFrom(dep, &configs_); | |
| 217 | 214 |
| 218 // Direct dependent libraries. | 215 // Direct dependent libraries. |
| 219 if (dep->output_type() == STATIC_LIBRARY || | 216 if (dep->output_type() == STATIC_LIBRARY || |
| 220 dep->output_type() == SHARED_LIBRARY || | 217 dep->output_type() == SHARED_LIBRARY || |
| 221 dep->output_type() == SOURCE_SET) | 218 dep->output_type() == SOURCE_SET) |
| 222 inherited_libraries_.push_back(dep); | 219 inherited_libraries_.Append(dep, is_public); |
| 223 | 220 |
| 224 // Inherited libraries and flags are inherited across static library | 221 if (dep->output_type() == SHARED_LIBRARY) { |
| 225 // boundaries. | 222 // Shared library dependendencies are inherited across public shared |
| 226 if (!dep->IsFinal()) { | 223 // library boundaries. |
| 227 inherited_libraries_.Append(dep->inherited_libraries().begin(), | 224 // |
| 228 dep->inherited_libraries().end()); | 225 // In this case: |
| 226 // EXE -> INTERMEDIATE_SHLIB --[public]--> FINAL_SHLIB |
| 227 // The EXE will also link to to FINAL_SHLIB. The public dependeny means |
| 228 // that the EXE can use the headers in FINAL_SHLIB so the FINAL_SHLIB |
| 229 // will need to appear on EXE's link line. |
| 230 // |
| 231 // However, if the dependency is private: |
| 232 // EXE -> INTERMEDIATE_SHLIB --[private]--> FINAL_SHLIB |
| 233 // the dependency will not be propogated because INTERMEDIATE_SHLIB is |
| 234 // not granting permission to call functiosn from FINAL_SHLIB. If EXE |
| 235 // wants to use functions (and link to) FINAL_SHLIB, it will need to do |
| 236 // so explicitly. |
| 237 // |
| 238 // Static libraries and source sets aren't inherited across shared |
| 239 // library boundaries because they will be linked into the shared |
| 240 // library. |
| 241 inherited_libraries_.AppendPublicSharedLibraries( |
| 242 dep->inherited_libraries(), is_public); |
| 243 } else if (!dep->IsFinal()) { |
| 244 // The current target isn't linked, so propogate linked deps and |
| 245 // libraries up the dependency tree. |
| 246 inherited_libraries_.AppendInherited(dep->inherited_libraries(), is_public); |
| 229 | 247 |
| 230 // Inherited library settings. | 248 // Inherited library settings. |
| 231 all_lib_dirs_.append(dep->all_lib_dirs()); | 249 all_lib_dirs_.append(dep->all_lib_dirs()); |
| 232 all_libs_.append(dep->all_libs()); | 250 all_libs_.append(dep->all_libs()); |
| 233 } | |
| 234 } | 251 } |
| 235 } | 252 } |
| 236 | 253 |
| 254 void Target::PullDependentTargets() { |
| 255 for (const auto& dep : public_deps_) |
| 256 PullDependentTarget(dep.ptr, true); |
| 257 for (const auto& dep : private_deps_) |
| 258 PullDependentTarget(dep.ptr, false); |
| 259 } |
| 260 |
| 237 void Target::PullForwardedDependentConfigs() { | 261 void Target::PullForwardedDependentConfigs() { |
| 238 // Pull public configs from each of our dependency's public deps. | 262 // Pull public configs from each of our dependency's public deps. |
| 239 for (const auto& dep : public_deps_) | 263 for (const auto& dep : public_deps_) |
| 240 PullForwardedDependentConfigsFrom(dep.ptr); | 264 PullForwardedDependentConfigsFrom(dep.ptr); |
| 241 | 265 |
| 242 // Forward public configs if explicitly requested. | 266 // Forward public configs if explicitly requested. |
| 243 for (const auto& dep : forward_dependent_configs_) { | 267 for (const auto& dep : forward_dependent_configs_) { |
| 244 const Target* from_target = dep.ptr; | 268 const Target* from_target = dep.ptr; |
| 245 | 269 |
| 246 // The forward_dependent_configs_ must be in the deps (public or private) | 270 // The forward_dependent_configs_ must be in the deps (public or private) |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 | 394 |
| 371 // Verify no deps are static libraries. | 395 // Verify no deps are static libraries. |
| 372 for (const auto& pair : GetDeps(DEPS_ALL)) { | 396 for (const auto& pair : GetDeps(DEPS_ALL)) { |
| 373 if (pair.ptr->output_type() == Target::STATIC_LIBRARY) { | 397 if (pair.ptr->output_type() == Target::STATIC_LIBRARY) { |
| 374 *err = MakeStaticLibDepsError(this, pair.ptr); | 398 *err = MakeStaticLibDepsError(this, pair.ptr); |
| 375 return false; | 399 return false; |
| 376 } | 400 } |
| 377 } | 401 } |
| 378 | 402 |
| 379 // Verify no inherited libraries are static libraries. | 403 // Verify no inherited libraries are static libraries. |
| 380 for (const auto& lib : inherited_libraries()) { | 404 for (const auto& lib : inherited_libraries().GetOrdered()) { |
| 381 if (lib->output_type() == Target::STATIC_LIBRARY) { | 405 if (lib->output_type() == Target::STATIC_LIBRARY) { |
| 382 *err = MakeStaticLibDepsError(this, lib); | 406 *err = MakeStaticLibDepsError(this, lib); |
| 383 return false; | 407 return false; |
| 384 } | 408 } |
| 385 } | 409 } |
| 386 return true; | 410 return true; |
| 387 } | 411 } |
| OLD | NEW |