| 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 "tools/gn/config_values_extractors.h" | 8 #include "tools/gn/config_values_extractors.h" |
| 9 #include "tools/gn/scheduler.h" | 9 #include "tools/gn/scheduler.h" |
| 10 | 10 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 57 } // namespace | 57 } // namespace |
| 58 | 58 |
| 59 Target::Target(const Settings* settings, const Label& label) | 59 Target::Target(const Settings* settings, const Label& label) |
| 60 : Item(settings, label), | 60 : Item(settings, label), |
| 61 output_type_(UNKNOWN), | 61 output_type_(UNKNOWN), |
| 62 hard_dep_(false), | 62 hard_dep_(false), |
| 63 external_(false), | 63 external_(false) { |
| 64 generated_(false), | |
| 65 generator_function_(NULL) { | |
| 66 } | 64 } |
| 67 | 65 |
| 68 Target::~Target() { | 66 Target::~Target() { |
| 69 } | 67 } |
| 70 | 68 |
| 71 // static | 69 // static |
| 72 const char* Target::GetStringForOutputType(OutputType type) { | 70 const char* Target::GetStringForOutputType(OutputType type) { |
| 73 switch (type) { | 71 switch (type) { |
| 74 case UNKNOWN: | 72 case UNKNOWN: |
| 75 return "Unknown"; | 73 return "Unknown"; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 } | 143 } |
| 146 | 144 |
| 147 if (output_type_ != GROUP) { | 145 if (output_type_ != GROUP) { |
| 148 // Don't pull target info like libraries and configs from dependencies into | 146 // Don't pull target info like libraries and configs from dependencies into |
| 149 // a group target. When A depends on a group G, the G's dependents will | 147 // a group target. When A depends on a group G, the G's dependents will |
| 150 // be treated as direct dependencies of A, so this is unnecessary and will | 148 // be treated as direct dependencies of A, so this is unnecessary and will |
| 151 // actually result in duplicated settings (since settings will also be | 149 // actually result in duplicated settings (since settings will also be |
| 152 // pulled from G to A in case G has configs directly on it). | 150 // pulled from G to A in case G has configs directly on it). |
| 153 PullDependentTargetInfo(&unique_configs); | 151 PullDependentTargetInfo(&unique_configs); |
| 154 } | 152 } |
| 155 | |
| 156 // Mark as resolved. | |
| 157 if (!settings()->build_settings()->target_resolved_callback().is_null()) { | |
| 158 g_scheduler->ScheduleWork(base::Bind(&TargetResolvedThunk, | |
| 159 settings()->build_settings()->target_resolved_callback(), | |
| 160 this)); | |
| 161 } | |
| 162 } | |
| 163 | |
| 164 bool Target::HasBeenGenerated() const { | |
| 165 return generated_; | |
| 166 } | |
| 167 | |
| 168 void Target::SetGenerated(const Token* token) { | |
| 169 DCHECK(!generated_); | |
| 170 generated_ = true; | |
| 171 generator_function_ = token; | |
| 172 } | 153 } |
| 173 | 154 |
| 174 bool Target::IsLinkable() const { | 155 bool Target::IsLinkable() const { |
| 175 return output_type_ == STATIC_LIBRARY || output_type_ == SHARED_LIBRARY; | 156 return output_type_ == STATIC_LIBRARY || output_type_ == SHARED_LIBRARY; |
| 176 } | 157 } |
| 177 | 158 |
| 178 void Target::PullDependentTargetInfo(std::set<const Config*>* unique_configs) { | 159 void Target::PullDependentTargetInfo(std::set<const Config*>* unique_configs) { |
| 179 // Gather info from our dependents we need. | 160 // Gather info from our dependents we need. |
| 180 for (size_t dep_i = 0; dep_i < deps_.size(); dep_i++) { | 161 for (size_t dep_i = 0; dep_i < deps_.size(); dep_i++) { |
| 181 const Target* dep = deps_[dep_i].ptr; | 162 const Target* dep = deps_[dep_i].ptr; |
| 182 MergeAllDependentConfigsFrom(dep, unique_configs, &configs_, | 163 MergeAllDependentConfigsFrom(dep, unique_configs, &configs_, |
| 183 &all_dependent_configs_); | 164 &all_dependent_configs_); |
| 184 MergeDirectDependentConfigsFrom(dep, unique_configs, &configs_); | 165 MergeDirectDependentConfigsFrom(dep, unique_configs, &configs_); |
| 185 | 166 |
| 186 // Direct dependent libraries. | 167 // Direct dependent libraries. |
| 187 if (dep->output_type() == STATIC_LIBRARY || | 168 if (dep->output_type() == STATIC_LIBRARY || |
| 188 dep->output_type() == SHARED_LIBRARY || | 169 dep->output_type() == SHARED_LIBRARY || |
| 189 dep->output_type() == SOURCE_SET) | 170 dep->output_type() == SOURCE_SET) |
| 190 inherited_libraries_.insert(dep); | 171 inherited_libraries_.insert(dep); |
| 191 | 172 |
| 192 // Inherited libraries and flags are inherited across static library | 173 // Inherited libraries and flags are inherited across static library |
| 193 // boundaries. For external targets, assume that the external_link_deps | 174 // boundaries. |
| 194 // will take care of this. | 175 if (dep->output_type() != SHARED_LIBRARY && |
| 195 if ((!dep->external() || | |
| 196 !settings()->build_settings()->using_external_generator()) && | |
| 197 dep->output_type() != SHARED_LIBRARY && | |
| 198 dep->output_type() != EXECUTABLE) { | 176 dep->output_type() != EXECUTABLE) { |
| 199 const std::set<const Target*> inherited = dep->inherited_libraries(); | 177 const std::set<const Target*> inherited = dep->inherited_libraries(); |
| 200 for (std::set<const Target*>::const_iterator i = inherited.begin(); | 178 for (std::set<const Target*>::const_iterator i = inherited.begin(); |
| 201 i != inherited.end(); ++i) | 179 i != inherited.end(); ++i) |
| 202 inherited_libraries_.insert(*i); | 180 inherited_libraries_.insert(*i); |
| 203 | 181 |
| 204 // Inherited library settings. | 182 // Inherited library settings. |
| 205 all_lib_dirs_.append(dep->all_lib_dirs()); | 183 all_lib_dirs_.append(dep->all_lib_dirs()); |
| 206 all_libs_.append(dep->all_libs()); | 184 all_libs_.append(dep->all_libs()); |
| 207 } | 185 } |
| 208 } | 186 } |
| 209 | 187 |
| 210 // Forward direct dependent configs if requested. | 188 // Forward direct dependent configs if requested. |
| 211 for (size_t dep = 0; dep < forward_dependent_configs_.size(); dep++) { | 189 for (size_t dep = 0; dep < forward_dependent_configs_.size(); dep++) { |
| 212 const Target* from_target = forward_dependent_configs_[dep].ptr; | 190 const Target* from_target = forward_dependent_configs_[dep].ptr; |
| 213 | 191 |
| 214 // The forward_dependent_configs_ must be in the deps already, so we | 192 // The forward_dependent_configs_ must be in the deps already, so we |
| 215 // don't need to bother copying to our configs, only forwarding. | 193 // don't need to bother copying to our configs, only forwarding. |
| 216 DCHECK(std::find_if(deps_.begin(), deps_.end(), | 194 DCHECK(std::find_if(deps_.begin(), deps_.end(), |
| 217 LabelPtrPtrEquals<Target>(from_target)) != | 195 LabelPtrPtrEquals<Target>(from_target)) != |
| 218 deps_.end()); | 196 deps_.end()); |
| 219 direct_dependent_configs_.insert( | 197 direct_dependent_configs_.insert( |
| 220 direct_dependent_configs_.end(), | 198 direct_dependent_configs_.end(), |
| 221 from_target->direct_dependent_configs().begin(), | 199 from_target->direct_dependent_configs().begin(), |
| 222 from_target->direct_dependent_configs().end()); | 200 from_target->direct_dependent_configs().end()); |
| 223 } | 201 } |
| 224 } | 202 } |
| OLD | NEW |