OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "tools/gn/target.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "tools/gn/scheduler.h" |
| 9 |
| 10 namespace { |
| 11 |
| 12 void TargetResolvedThunk(const base::Callback<void(const Target*)>& cb, |
| 13 const Target* t) { |
| 14 cb.Run(t); |
| 15 } |
| 16 |
| 17 } // namespace |
| 18 |
| 19 Target::Target(const Settings* settings, const Label& label) |
| 20 : Item(label), |
| 21 settings_(settings), |
| 22 output_type_(NONE), |
| 23 generated_(false), |
| 24 generator_function_(NULL) { |
| 25 } |
| 26 |
| 27 Target::~Target() { |
| 28 } |
| 29 |
| 30 Target* Target::AsTarget() { |
| 31 return this; |
| 32 } |
| 33 |
| 34 const Target* Target::AsTarget() const { |
| 35 return this; |
| 36 } |
| 37 |
| 38 void Target::OnResolved() { |
| 39 // Gather info from our dependents we need. |
| 40 for (size_t dep = 0; dep < deps_.size(); dep++) { |
| 41 // All dependent configs get pulled to us, and to our dependents. |
| 42 const std::vector<const Config*>& all = |
| 43 deps_[dep]->all_dependent_configs(); |
| 44 for (size_t i = 0; i < all.size(); i++) { |
| 45 configs_.push_back(all[i]); |
| 46 all_dependent_configs_.push_back(all[i]); |
| 47 } |
| 48 |
| 49 // Direct dependent configs get pulled only to us. |
| 50 const std::vector<const Config*>& direct = |
| 51 deps_[dep]->direct_dependent_configs(); |
| 52 for (size_t i = 0; i < direct.size(); i++) |
| 53 configs_.push_back(direct[i]); |
| 54 |
| 55 // Direct dependent libraries. |
| 56 if (deps_[dep]->output_type() == STATIC_LIBRARY || |
| 57 deps_[dep]->output_type() == SHARED_LIBRARY || |
| 58 deps_[dep]->output_type() == LOADABLE_MODULE) |
| 59 inherited_libraries_.insert(deps_[dep]); |
| 60 |
| 61 // Inherited libraries. DOn't pull transitive libraries from shared |
| 62 // libraries, since obviously those shouldn't be linked directly into |
| 63 // later deps unless explicitly specified. |
| 64 if (deps_[dep]->output_type() != SHARED_LIBRARY && |
| 65 deps_[dep]->output_type() != LOADABLE_MODULE && |
| 66 deps_[dep]->output_type() != EXECUTABLE) { |
| 67 const std::set<const Target*> inherited = |
| 68 deps_[dep]->inherited_libraries(); |
| 69 for (std::set<const Target*>::const_iterator i = inherited.begin(); |
| 70 i != inherited.end(); ++i) |
| 71 inherited_libraries_.insert(*i); |
| 72 } |
| 73 } |
| 74 |
| 75 if (!settings_->build_settings()->target_resolved_callback().is_null()) { |
| 76 g_scheduler->ScheduleWork(base::Bind(&TargetResolvedThunk, |
| 77 settings_->build_settings()->target_resolved_callback(), |
| 78 this)); |
| 79 } |
| 80 } |
| 81 |
| 82 bool Target::HasBeenGenerated() const { |
| 83 return generated_; |
| 84 } |
| 85 |
| 86 void Target::SetGenerated(const Token* token) { |
| 87 DCHECK(!generated_); |
| 88 generated_ = true; |
| 89 generator_function_ = token; |
| 90 } |
| 91 |
| 92 bool Target::IsLinkable() const { |
| 93 return output_type_ == STATIC_LIBRARY || output_type_ == SHARED_LIBRARY; |
| 94 } |
OLD | NEW |