| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 return this; | 153 return this; |
| 154 } | 154 } |
| 155 | 155 |
| 156 bool Target::OnResolved(Err* err) { | 156 bool Target::OnResolved(Err* err) { |
| 157 DCHECK(output_type_ != UNKNOWN); | 157 DCHECK(output_type_ != UNKNOWN); |
| 158 DCHECK(toolchain_) << "Toolchain should have been set before resolving."; | 158 DCHECK(toolchain_) << "Toolchain should have been set before resolving."; |
| 159 | 159 |
| 160 ScopedTrace trace(TraceItem::TRACE_ON_RESOLVED, label()); | 160 ScopedTrace trace(TraceItem::TRACE_ON_RESOLVED, label()); |
| 161 trace.SetToolchain(settings()->toolchain_label()); | 161 trace.SetToolchain(settings()->toolchain_label()); |
| 162 | 162 |
| 163 // Copy our own dependent configs to the list of configs applying to us. | 163 // Copy this target's own dependent and public configs to the list of configs |
| 164 // applying to it. |
| 164 configs_.Append(all_dependent_configs_.begin(), all_dependent_configs_.end()); | 165 configs_.Append(all_dependent_configs_.begin(), all_dependent_configs_.end()); |
| 165 MergePublicConfigsFrom(this, &configs_); | 166 MergePublicConfigsFrom(this, &configs_); |
| 166 | 167 |
| 168 // Copy public configs from all dependencies into the list of configs |
| 169 // applying to this target (configs_). |
| 170 PullDependentTargetConfigs(); |
| 171 |
| 172 // Copies public dependencies' public configs to this target's public |
| 173 // configs. These configs have already been applied to this target by |
| 174 // PullDependentTargetConfigs above, along with the public configs from |
| 175 // private deps. This step re-exports them as public configs for targets that |
| 176 // depend on this one. |
| 177 for (const auto& dep : public_deps_) { |
| 178 public_configs_.Append(dep.ptr->public_configs().begin(), |
| 179 dep.ptr->public_configs().end()); |
| 180 } |
| 181 |
| 167 // Copy our own libs and lib_dirs to the final set. This will be from our | 182 // Copy our own libs and lib_dirs to the final set. This will be from our |
| 168 // target and all of our configs. We do this specially since these must be | 183 // target and all of our configs. We do this specially since these must be |
| 169 // inherited through the dependency tree (other flags don't work this way). | 184 // inherited through the dependency tree (other flags don't work this way). |
| 185 // |
| 186 // This needs to happen after we pull dependent target configs for the |
| 187 // public config's libs to be included here. And it needs to happen |
| 188 // before pulling the dependent target libs so the libs are in the correct |
| 189 // order (local ones first, then the dependency's). |
| 170 for (ConfigValuesIterator iter(this); !iter.done(); iter.Next()) { | 190 for (ConfigValuesIterator iter(this); !iter.done(); iter.Next()) { |
| 171 const ConfigValues& cur = iter.cur(); | 191 const ConfigValues& cur = iter.cur(); |
| 172 all_lib_dirs_.append(cur.lib_dirs().begin(), cur.lib_dirs().end()); | 192 all_lib_dirs_.append(cur.lib_dirs().begin(), cur.lib_dirs().end()); |
| 173 all_libs_.append(cur.libs().begin(), cur.libs().end()); | 193 all_libs_.append(cur.libs().begin(), cur.libs().end()); |
| 174 } | 194 } |
| 175 | 195 |
| 176 PullDependentTargets(); | 196 PullDependentTargetLibs(); |
| 177 PullPublicConfigs(); | |
| 178 PullRecursiveHardDeps(); | 197 PullRecursiveHardDeps(); |
| 179 if (!ResolvePrecompiledHeaders(err)) | 198 if (!ResolvePrecompiledHeaders(err)) |
| 180 return false; | 199 return false; |
| 181 | 200 |
| 182 FillOutputFiles(); | 201 FillOutputFiles(); |
| 183 | 202 |
| 184 if (settings()->build_settings()->check_for_bad_items()) { | 203 if (settings()->build_settings()->check_for_bad_items()) { |
| 185 if (!CheckVisibility(err)) | 204 if (!CheckVisibility(err)) |
| 186 return false; | 205 return false; |
| 187 if (!CheckTestonly(err)) | 206 if (!CheckTestonly(err)) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 "Alas, I can not continue.", | 278 "Alas, I can not continue.", |
| 260 label().GetUserVisibleName(false).c_str(), | 279 label().GetUserVisibleName(false).c_str(), |
| 261 GetStringForOutputType(output_type_), | 280 GetStringForOutputType(output_type_), |
| 262 label().GetToolchainLabel().GetUserVisibleName(false).c_str(), | 281 label().GetToolchainLabel().GetUserVisibleName(false).c_str(), |
| 263 Toolchain::ToolTypeToName( | 282 Toolchain::ToolTypeToName( |
| 264 toolchain->GetToolTypeForTargetFinalOutput(this)).c_str())); | 283 toolchain->GetToolTypeForTargetFinalOutput(this)).c_str())); |
| 265 } | 284 } |
| 266 return false; | 285 return false; |
| 267 } | 286 } |
| 268 | 287 |
| 269 void Target::PullDependentTarget(const Target* dep, bool is_public) { | 288 void Target::PullDependentTargetConfigsFrom(const Target* dep) { |
| 270 MergeAllDependentConfigsFrom(dep, &configs_, &all_dependent_configs_); | 289 MergeAllDependentConfigsFrom(dep, &configs_, &all_dependent_configs_); |
| 271 MergePublicConfigsFrom(dep, &configs_); | 290 MergePublicConfigsFrom(dep, &configs_); |
| 291 } |
| 272 | 292 |
| 293 void Target::PullDependentTargetConfigs() { |
| 294 for (const auto& pair : GetDeps(DEPS_LINKED)) |
| 295 PullDependentTargetConfigsFrom(pair.ptr); |
| 296 } |
| 297 |
| 298 void Target::PullDependentTargetLibsFrom(const Target* dep, bool is_public) { |
| 273 // Direct dependent libraries. | 299 // Direct dependent libraries. |
| 274 if (dep->output_type() == STATIC_LIBRARY || | 300 if (dep->output_type() == STATIC_LIBRARY || |
| 275 dep->output_type() == SHARED_LIBRARY || | 301 dep->output_type() == SHARED_LIBRARY || |
| 276 dep->output_type() == SOURCE_SET) | 302 dep->output_type() == SOURCE_SET) |
| 277 inherited_libraries_.Append(dep, is_public); | 303 inherited_libraries_.Append(dep, is_public); |
| 278 | 304 |
| 279 if (dep->output_type() == SHARED_LIBRARY) { | 305 if (dep->output_type() == SHARED_LIBRARY) { |
| 280 // Shared library dependendencies are inherited across public shared | 306 // Shared library dependendencies are inherited across public shared |
| 281 // library boundaries. | 307 // library boundaries. |
| 282 // | 308 // |
| (...skipping 19 matching lines...) Expand all Loading... |
| 302 // The current target isn't linked, so propogate linked deps and | 328 // The current target isn't linked, so propogate linked deps and |
| 303 // libraries up the dependency tree. | 329 // libraries up the dependency tree. |
| 304 inherited_libraries_.AppendInherited(dep->inherited_libraries(), is_public); | 330 inherited_libraries_.AppendInherited(dep->inherited_libraries(), is_public); |
| 305 | 331 |
| 306 // Inherited library settings. | 332 // Inherited library settings. |
| 307 all_lib_dirs_.append(dep->all_lib_dirs()); | 333 all_lib_dirs_.append(dep->all_lib_dirs()); |
| 308 all_libs_.append(dep->all_libs()); | 334 all_libs_.append(dep->all_libs()); |
| 309 } | 335 } |
| 310 } | 336 } |
| 311 | 337 |
| 312 void Target::PullDependentTargets() { | 338 void Target::PullDependentTargetLibs() { |
| 313 for (const auto& dep : public_deps_) | 339 for (const auto& dep : public_deps_) |
| 314 PullDependentTarget(dep.ptr, true); | 340 PullDependentTargetLibsFrom(dep.ptr, true); |
| 315 for (const auto& dep : private_deps_) | 341 for (const auto& dep : private_deps_) |
| 316 PullDependentTarget(dep.ptr, false); | 342 PullDependentTargetLibsFrom(dep.ptr, false); |
| 317 } | |
| 318 | |
| 319 void Target::PullPublicConfigs() { | |
| 320 // Pull public configs from each of our dependency's public deps. | |
| 321 for (const auto& dep : public_deps_) | |
| 322 PullPublicConfigsFrom(dep.ptr); | |
| 323 } | |
| 324 | |
| 325 void Target::PullPublicConfigsFrom(const Target* from) { | |
| 326 public_configs_.Append(from->public_configs().begin(), | |
| 327 from->public_configs().end()); | |
| 328 } | 343 } |
| 329 | 344 |
| 330 void Target::PullRecursiveHardDeps() { | 345 void Target::PullRecursiveHardDeps() { |
| 331 for (const auto& pair : GetDeps(DEPS_LINKED)) { | 346 for (const auto& pair : GetDeps(DEPS_LINKED)) { |
| 332 // Direct hard dependencies. | 347 // Direct hard dependencies. |
| 333 if (pair.ptr->hard_dep()) | 348 if (pair.ptr->hard_dep()) |
| 334 recursive_hard_deps_.insert(pair.ptr); | 349 recursive_hard_deps_.insert(pair.ptr); |
| 335 | 350 |
| 336 // Recursive hard dependencies of all dependencies. | 351 // Recursive hard dependencies of all dependencies. |
| 337 recursive_hard_deps_.insert(pair.ptr->recursive_hard_deps().begin(), | 352 recursive_hard_deps_.insert(pair.ptr->recursive_hard_deps().begin(), |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 return; // Not in output dir, this is OK. | 560 return; // Not in output dir, this is OK. |
| 546 | 561 |
| 547 // Tell the scheduler about unknown files. This will be noted for later so | 562 // Tell the scheduler about unknown files. This will be noted for later so |
| 548 // the list of files written by the GN build itself (often response files) | 563 // the list of files written by the GN build itself (often response files) |
| 549 // can be filtered out of this list. | 564 // can be filtered out of this list. |
| 550 OutputFile out_file(settings()->build_settings(), source); | 565 OutputFile out_file(settings()->build_settings(), source); |
| 551 std::set<const Target*> seen_targets; | 566 std::set<const Target*> seen_targets; |
| 552 if (!EnsureFileIsGeneratedByDependency(this, out_file, true, &seen_targets)) | 567 if (!EnsureFileIsGeneratedByDependency(this, out_file, true, &seen_targets)) |
| 553 g_scheduler->AddUnknownGeneratedInput(this, source); | 568 g_scheduler->AddUnknownGeneratedInput(this, source); |
| 554 } | 569 } |
| OLD | NEW |