| 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_generator.h" | 5 #include "tools/gn/target_generator.h" |
| 6 | 6 |
| 7 #include "tools/gn/binary_target_generator.h" | 7 #include "tools/gn/binary_target_generator.h" |
| 8 #include "tools/gn/build_settings.h" | 8 #include "tools/gn/build_settings.h" |
| 9 #include "tools/gn/config.h" | 9 #include "tools/gn/config.h" |
| 10 #include "tools/gn/copy_target_generator.h" | 10 #include "tools/gn/copy_target_generator.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 return; | 137 return; |
| 138 | 138 |
| 139 Target::FileList dest_reqs; | 139 Target::FileList dest_reqs; |
| 140 if (!ExtractListOfRelativeFiles(scope_->settings()->build_settings(), *value, | 140 if (!ExtractListOfRelativeFiles(scope_->settings()->build_settings(), *value, |
| 141 scope_->GetSourceDir(), &dest_reqs, err_)) | 141 scope_->GetSourceDir(), &dest_reqs, err_)) |
| 142 return; | 142 return; |
| 143 target_->source_prereqs().swap(dest_reqs); | 143 target_->source_prereqs().swap(dest_reqs); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void TargetGenerator::FillConfigs() { | 146 void TargetGenerator::FillConfigs() { |
| 147 FillGenericConfigs(variables::kConfigs, &Target::configs); | 147 FillGenericConfigs(variables::kConfigs, &target_->configs()); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void TargetGenerator::FillDependentConfigs() { | 150 void TargetGenerator::FillDependentConfigs() { |
| 151 FillGenericConfigs(variables::kAllDependentConfigs, | 151 FillGenericConfigs(variables::kAllDependentConfigs, |
| 152 &Target::all_dependent_configs); | 152 &target_->all_dependent_configs()); |
| 153 FillGenericConfigs(variables::kDirectDependentConfigs, | 153 FillGenericConfigs(variables::kDirectDependentConfigs, |
| 154 &Target::direct_dependent_configs); | 154 &target_->direct_dependent_configs()); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void TargetGenerator::FillData() { | 157 void TargetGenerator::FillData() { |
| 158 // TODO(brettW) hook this up to the constant when we have cleaned up | 158 // TODO(brettW) hook this up to the constant when we have cleaned up |
| 159 // how data files are used. | 159 // how data files are used. |
| 160 const Value* value = scope_->GetValue(variables::kData, true); | 160 const Value* value = scope_->GetValue(variables::kData, true); |
| 161 if (!value) | 161 if (!value) |
| 162 return; | 162 return; |
| 163 | 163 |
| 164 Target::FileList dest_data; | 164 Target::FileList dest_data; |
| 165 if (!ExtractListOfRelativeFiles(scope_->settings()->build_settings(), *value, | 165 if (!ExtractListOfRelativeFiles(scope_->settings()->build_settings(), *value, |
| 166 scope_->GetSourceDir(), &dest_data, err_)) | 166 scope_->GetSourceDir(), &dest_data, err_)) |
| 167 return; | 167 return; |
| 168 target_->data().swap(dest_data); | 168 target_->data().swap(dest_data); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void TargetGenerator::FillDependencies() { | 171 void TargetGenerator::FillDependencies() { |
| 172 FillGenericDeps(variables::kDeps, &Target::deps); | 172 FillGenericDeps(variables::kDeps, &target_->deps()); |
| 173 FillGenericDeps(variables::kDatadeps, &Target::datadeps); | 173 FillGenericDeps(variables::kDatadeps, &target_->datadeps()); |
| 174 | 174 |
| 175 // This is a list of dependent targets to have their configs fowarded, so | 175 // This is a list of dependent targets to have their configs fowarded, so |
| 176 // it goes here rather than in FillConfigs. | 176 // it goes here rather than in FillConfigs. |
| 177 FillForwardDependentConfigs(); | 177 FillForwardDependentConfigs(); |
| 178 | 178 |
| 179 FillHardDep(); | 179 FillHardDep(); |
| 180 } | 180 } |
| 181 | 181 |
| 182 void TargetGenerator::FillGypFile() { | 182 void TargetGenerator::FillGypFile() { |
| 183 const Value* gyp_file_value = scope_->GetValue(variables::kGypFile, true); | 183 const Value* gyp_file_value = scope_->GetValue(variables::kGypFile, true); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 // TODO(brettw) currently we lock separately for each config, dep, and | 233 // TODO(brettw) currently we lock separately for each config, dep, and |
| 234 // toolchain we add which is bad! Do this in one lock. | 234 // toolchain we add which is bad! Do this in one lock. |
| 235 ItemTree* tree = &GetBuildSettings()->item_tree(); | 235 ItemTree* tree = &GetBuildSettings()->item_tree(); |
| 236 base::AutoLock lock(tree->lock()); | 236 base::AutoLock lock(tree->lock()); |
| 237 ItemNode* tc_node = | 237 ItemNode* tc_node = |
| 238 tree->GetExistingNodeLocked(ToolchainLabelForScope(scope_)); | 238 tree->GetExistingNodeLocked(ToolchainLabelForScope(scope_)); |
| 239 target_->item_node()->AddDependency( | 239 target_->item_node()->AddDependency( |
| 240 GetBuildSettings(), function_token_.range(), tc_node, err_); | 240 GetBuildSettings(), function_token_.range(), tc_node, err_); |
| 241 } | 241 } |
| 242 | 242 |
| 243 void TargetGenerator::FillGenericConfigs( | 243 void TargetGenerator::FillGenericConfigs(const char* var_name, |
| 244 const char* var_name, | 244 LabelConfigVector* dest) { |
| 245 std::vector<const Config*>& (Target::*accessor)()) { | |
| 246 const Value* value = scope_->GetValue(var_name, true); | 245 const Value* value = scope_->GetValue(var_name, true); |
| 247 if (!value) | 246 if (!value) |
| 248 return; | 247 return; |
| 249 | |
| 250 std::vector<Label> labels; | |
| 251 if (!ExtractListOfLabels(*value, scope_->GetSourceDir(), | 248 if (!ExtractListOfLabels(*value, scope_->GetSourceDir(), |
| 252 ToolchainLabelForScope(scope_), &labels, err_)) | 249 ToolchainLabelForScope(scope_), dest, err_)) |
| 253 return; | 250 return; |
| 254 | 251 |
| 255 std::vector<const Config*> dest_configs; | 252 for (size_t i = 0; i < dest->size(); i++) { |
| 256 dest_configs.resize(labels.size()); | 253 LabelConfigPair& cur = (*dest)[i]; |
| 257 for (size_t i = 0; i < labels.size(); i++) { | 254 cur.ptr = Config::GetConfig(scope_->settings(), |
| 258 dest_configs[i] = Config::GetConfig( | 255 value->list_value()[i].origin()->GetRange(), |
| 259 scope_->settings(), | 256 cur.label, target_, err_); |
| 260 value->list_value()[i].origin()->GetRange(), | |
| 261 labels[i], target_, err_); | |
| 262 if (err_->has_error()) | 257 if (err_->has_error()) |
| 263 return; | 258 return; |
| 264 } | 259 } |
| 265 (target_->*accessor)().swap(dest_configs); | |
| 266 } | 260 } |
| 267 | 261 |
| 268 void TargetGenerator::FillGenericDeps( | 262 void TargetGenerator::FillGenericDeps(const char* var_name, |
| 269 const char* var_name, | 263 LabelTargetVector* dest) { |
| 270 std::vector<const Target*>& (Target::*accessor)()) { | |
| 271 const Value* value = scope_->GetValue(var_name, true); | 264 const Value* value = scope_->GetValue(var_name, true); |
| 272 if (!value) | 265 if (!value) |
| 273 return; | 266 return; |
| 274 | |
| 275 std::vector<Label> labels; | |
| 276 if (!ExtractListOfLabels(*value, scope_->GetSourceDir(), | 267 if (!ExtractListOfLabels(*value, scope_->GetSourceDir(), |
| 277 ToolchainLabelForScope(scope_), &labels, err_)) | 268 ToolchainLabelForScope(scope_), dest, err_)) |
| 278 return; | 269 return; |
| 279 | 270 |
| 280 std::vector<const Target*> dest_deps; | 271 for (size_t i = 0; i < dest->size(); i++) { |
| 281 dest_deps.resize(labels.size()); | 272 LabelTargetPair& cur = (*dest)[i]; |
| 282 for (size_t i = 0; i < labels.size(); i++) { | 273 cur.ptr = GetBuildSettings()->target_manager().GetTarget( |
| 283 dest_deps[i] = GetBuildSettings()->target_manager().GetTarget( | 274 cur.label, value->list_value()[i].origin()->GetRange(), target_, err_); |
| 284 labels[i], value->list_value()[i].origin()->GetRange(), target_, err_); | |
| 285 if (err_->has_error()) | 275 if (err_->has_error()) |
| 286 return; | 276 return; |
| 287 } | 277 } |
| 288 | |
| 289 (target_->*accessor)().swap(dest_deps); | |
| 290 } | 278 } |
| 291 | 279 |
| 292 void TargetGenerator::FillForwardDependentConfigs() { | 280 void TargetGenerator::FillForwardDependentConfigs() { |
| 293 const Value* value = scope_->GetValue( | 281 const Value* value = scope_->GetValue( |
| 294 variables::kForwardDependentConfigsFrom, true); | 282 variables::kForwardDependentConfigsFrom, true); |
| 295 if (!value) | 283 if (!value) |
| 296 return; | 284 return; |
| 297 | 285 |
| 298 std::vector<Label> labels; | 286 LabelTargetVector& dest = target_->forward_dependent_configs(); |
| 299 if (!ExtractListOfLabels(*value, scope_->GetSourceDir(), | 287 if (!ExtractListOfLabels(*value, scope_->GetSourceDir(), |
| 300 ToolchainLabelForScope(scope_), &labels, err_)) | 288 ToolchainLabelForScope(scope_), &dest, err_)) |
| 301 return; | 289 return; |
| 302 | 290 |
| 303 const std::vector<const Target*>& deps = target_->deps(); | |
| 304 | |
| 305 // We currently assume that the list is very small and do a brute-force | 291 // We currently assume that the list is very small and do a brute-force |
| 306 // search in the deps for the labeled target. This could be optimized. | 292 // search in the deps for the labeled target. This could be optimized. |
| 293 const LabelTargetVector& deps = target_->deps(); |
| 307 std::vector<const Target*> forward_from_list; | 294 std::vector<const Target*> forward_from_list; |
| 308 for (size_t label_index = 0; label_index < labels.size(); label_index++) { | 295 for (size_t dest_index = 0; dest_index < dest.size(); dest_index++) { |
| 309 const Target* forward_from = NULL; | 296 LabelTargetPair& cur_dest = dest[dest_index]; |
| 310 for (size_t dep_index = 0; dep_index < deps.size(); dep_index++) { | 297 for (size_t dep_index = 0; dep_index < deps.size(); dep_index++) { |
| 311 if (deps[dep_index]->label() == labels[label_index]) { | 298 if (deps[dep_index].label == cur_dest.label) { |
| 312 forward_from = deps[dep_index]; | 299 cur_dest.ptr = deps[dep_index].ptr; |
| 313 break; | 300 break; |
| 314 } | 301 } |
| 315 } | 302 } |
| 316 if (!forward_from) { | 303 if (!cur_dest.ptr) { |
| 317 *err_ = Err(value->list_value()[label_index], | 304 *err_ = Err(cur_dest.origin, |
| 318 "Can't forward from this target.", | 305 "Can't forward from this target.", |
| 319 "forward_dependent_configs_from must contain a list of labels that\n" | 306 "forward_dependent_configs_from must contain a list of labels that\n" |
| 320 "must all appear in the deps of the same target."); | 307 "must all appear in the deps of the same target."); |
| 321 return; | 308 return; |
| 322 } | 309 } |
| 323 | |
| 324 forward_from_list.push_back(forward_from); | |
| 325 } | 310 } |
| 326 | |
| 327 target_->forward_dependent_configs().swap(forward_from_list); | |
| 328 } | 311 } |
| 329 | 312 |
| 330 | 313 |
| 331 | 314 |
| 332 | 315 |
| 333 | 316 |
| OLD | NEW |