| 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 "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "tools/gn/build_settings.h" | 9 #include "tools/gn/build_settings.h" |
| 10 #include "tools/gn/config.h" | 10 #include "tools/gn/config.h" |
| 11 #include "tools/gn/config_values_generator.h" | 11 #include "tools/gn/config_values_generator.h" |
| 12 #include "tools/gn/err.h" | 12 #include "tools/gn/err.h" |
| 13 #include "tools/gn/filesystem_utils.h" | 13 #include "tools/gn/filesystem_utils.h" |
| 14 #include "tools/gn/functions.h" | 14 #include "tools/gn/functions.h" |
| 15 #include "tools/gn/input_file.h" | 15 #include "tools/gn/input_file.h" |
| 16 #include "tools/gn/item_node.h" | 16 #include "tools/gn/item_node.h" |
| 17 #include "tools/gn/ninja_target_writer.h" | 17 #include "tools/gn/ninja_target_writer.h" |
| 18 #include "tools/gn/parse_tree.h" | 18 #include "tools/gn/parse_tree.h" |
| 19 #include "tools/gn/scheduler.h" | 19 #include "tools/gn/scheduler.h" |
| 20 #include "tools/gn/scope.h" | 20 #include "tools/gn/scope.h" |
| 21 #include "tools/gn/target_manager.h" | 21 #include "tools/gn/target_manager.h" |
| 22 #include "tools/gn/token.h" | 22 #include "tools/gn/token.h" |
| 23 #include "tools/gn/value.h" | 23 #include "tools/gn/value.h" |
| 24 #include "tools/gn/value_extractors.h" | 24 #include "tools/gn/value_extractors.h" |
| 25 #include "tools/gn/variables.h" |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 bool TypeHasConfigs(Target::OutputType type) { | 29 bool TypeHasConfigs(Target::OutputType type) { |
| 29 return type == Target::EXECUTABLE || | 30 return type == Target::EXECUTABLE || |
| 30 type == Target::SHARED_LIBRARY || | 31 type == Target::SHARED_LIBRARY || |
| 31 type == Target::STATIC_LIBRARY || | 32 type == Target::STATIC_LIBRARY || |
| 32 type == Target::LOADABLE_MODULE; | 33 type == Target::LOADABLE_MODULE; |
| 33 } | 34 } |
| 34 | 35 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 FillSources(); | 92 FillSources(); |
| 92 if (TypeHasData(output_type)) | 93 if (TypeHasData(output_type)) |
| 93 FillData(); | 94 FillData(); |
| 94 if (output_type == Target::CUSTOM) { | 95 if (output_type == Target::CUSTOM) { |
| 95 FillScript(); | 96 FillScript(); |
| 96 FillScriptArgs(); | 97 FillScriptArgs(); |
| 97 } | 98 } |
| 98 if (TypeHasOutputs(output_type)) | 99 if (TypeHasOutputs(output_type)) |
| 99 FillOutputs(); | 100 FillOutputs(); |
| 100 FillDependencies(); // All types have dependencies. | 101 FillDependencies(); // All types have dependencies. |
| 102 FillDataDependencies(); // All types have dependencies. |
| 101 | 103 |
| 102 if (TypeHasConfigValues(output_type)) { | 104 if (TypeHasConfigValues(output_type)) { |
| 103 ConfigValuesGenerator gen(&target_->config_values(), scope_, | 105 ConfigValuesGenerator gen(&target_->config_values(), scope_, |
| 104 function_token_, input_directory_, err_); | 106 function_token_, input_directory_, err_); |
| 105 gen.Run(); | 107 gen.Run(); |
| 106 if (err_->has_error()) | 108 if (err_->has_error()) |
| 107 return; | 109 return; |
| 108 } | 110 } |
| 109 | 111 |
| 110 if (TypeHasDestDir(output_type)) | 112 if (TypeHasDestDir(output_type)) |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 dest_configs[i] = Config::GetConfig( | 203 dest_configs[i] = Config::GetConfig( |
| 202 scope_->settings(), | 204 scope_->settings(), |
| 203 value->list_value()[i].origin()->GetRange(), | 205 value->list_value()[i].origin()->GetRange(), |
| 204 labels[i], target_, err_); | 206 labels[i], target_, err_); |
| 205 if (err_->has_error()) | 207 if (err_->has_error()) |
| 206 return; | 208 return; |
| 207 } | 209 } |
| 208 (target_->*setter)(&dest_configs); | 210 (target_->*setter)(&dest_configs); |
| 209 } | 211 } |
| 210 | 212 |
| 213 void TargetGenerator::FillGenericDeps( |
| 214 const char* var_name, |
| 215 void (Target::*setter)(std::vector<const Target*>*)) { |
| 216 const Value* value = scope_->GetValue(var_name, true); |
| 217 if (!value) |
| 218 return; |
| 219 |
| 220 std::vector<Label> labels; |
| 221 if (!ExtractListOfLabels(*value, input_directory_, |
| 222 ToolchainLabelForScope(scope_), &labels, err_)) |
| 223 return; |
| 224 |
| 225 std::vector<const Target*> dest_deps; |
| 226 dest_deps.resize(labels.size()); |
| 227 for (size_t i = 0; i < labels.size(); i++) { |
| 228 dest_deps[i] = GetBuildSettings()->target_manager().GetTarget( |
| 229 labels[i], value->list_value()[i].origin()->GetRange(), target_, err_); |
| 230 if (err_->has_error()) |
| 231 return; |
| 232 } |
| 233 |
| 234 (target_->*setter)(&dest_deps); |
| 235 } |
| 236 |
| 211 void TargetGenerator::FillConfigs() { | 237 void TargetGenerator::FillConfigs() { |
| 212 FillGenericConfigs("configs", &Target::swap_in_configs); | 238 FillGenericConfigs(variables::kConfigs, &Target::swap_in_configs); |
| 213 } | 239 } |
| 214 | 240 |
| 215 void TargetGenerator::FillAllDependentConfigs() { | 241 void TargetGenerator::FillAllDependentConfigs() { |
| 216 FillGenericConfigs("all_dependent_configs", | 242 FillGenericConfigs(variables::kAllDependentConfigs, |
| 217 &Target::swap_in_all_dependent_configs); | 243 &Target::swap_in_all_dependent_configs); |
| 218 } | 244 } |
| 219 | 245 |
| 220 void TargetGenerator::FillDirectDependentConfigs() { | 246 void TargetGenerator::FillDirectDependentConfigs() { |
| 221 FillGenericConfigs("direct_dependent_configs", | 247 FillGenericConfigs(variables::kDirectDependentConfigs, |
| 222 &Target::swap_in_direct_dependent_configs); | 248 &Target::swap_in_direct_dependent_configs); |
| 223 } | 249 } |
| 224 | 250 |
| 225 void TargetGenerator::FillSources() { | 251 void TargetGenerator::FillSources() { |
| 226 const Value* value = scope_->GetValue("sources", true); | 252 const Value* value = scope_->GetValue(variables::kSources, true); |
| 227 if (!value) | 253 if (!value) |
| 228 return; | 254 return; |
| 229 | 255 |
| 230 Target::FileList dest_sources; | 256 Target::FileList dest_sources; |
| 231 if (!ExtractListOfRelativeFiles(*value, input_directory_, &dest_sources, | 257 if (!ExtractListOfRelativeFiles(*value, input_directory_, &dest_sources, |
| 232 err_)) | 258 err_)) |
| 233 return; | 259 return; |
| 234 target_->swap_in_sources(&dest_sources); | 260 target_->swap_in_sources(&dest_sources); |
| 235 } | 261 } |
| 236 | 262 |
| 237 void TargetGenerator::FillData() { | 263 void TargetGenerator::FillData() { |
| 264 // TODO(brettW) hook this up to the constant when we have cleaned up |
| 265 // how data files are used. |
| 238 const Value* value = scope_->GetValue("data", true); | 266 const Value* value = scope_->GetValue("data", true); |
| 239 if (!value) | 267 if (!value) |
| 240 return; | 268 return; |
| 241 | 269 |
| 242 Target::FileList dest_data; | 270 Target::FileList dest_data; |
| 243 if (!ExtractListOfRelativeFiles(*value, input_directory_, &dest_data, | 271 if (!ExtractListOfRelativeFiles(*value, input_directory_, &dest_data, |
| 244 err_)) | 272 err_)) |
| 245 return; | 273 return; |
| 246 target_->swap_in_data(&dest_data); | 274 target_->swap_in_data(&dest_data); |
| 247 } | 275 } |
| 248 | 276 |
| 249 void TargetGenerator::FillDependencies() { | 277 void TargetGenerator::FillDependencies() { |
| 250 const Value* value = scope_->GetValue("deps", true); | 278 FillGenericDeps(variables::kDeps, &Target::swap_in_deps); |
| 251 if (!value) | 279 } |
| 252 return; | |
| 253 | 280 |
| 254 std::vector<Label> labels; | 281 void TargetGenerator::FillDataDependencies() { |
| 255 if (!ExtractListOfLabels(*value, input_directory_, | 282 FillGenericDeps(variables::kDatadeps, &Target::swap_in_datadeps); |
| 256 ToolchainLabelForScope(scope_), &labels, err_)) | |
| 257 return; | |
| 258 | |
| 259 std::vector<const Target*> dest_deps; | |
| 260 dest_deps.resize(labels.size()); | |
| 261 for (size_t i = 0; i < labels.size(); i++) { | |
| 262 dest_deps[i] = GetBuildSettings()->target_manager().GetTarget( | |
| 263 labels[i], value->list_value()[i].origin()->GetRange(), target_, err_); | |
| 264 if (err_->has_error()) | |
| 265 return; | |
| 266 } | |
| 267 | |
| 268 target_->swap_in_deps(&dest_deps); | |
| 269 } | 283 } |
| 270 | 284 |
| 271 void TargetGenerator::FillDestDir() { | 285 void TargetGenerator::FillDestDir() { |
| 272 // Destdir is required for all targets that use it. | 286 // Destdir is required for all targets that use it. |
| 273 const Value* value = scope_->GetValue("destdir", true); | 287 const Value* value = scope_->GetValue("destdir", true); |
| 274 if (!value) { | 288 if (!value) { |
| 275 *err_ = Err(function_token_, "This target type requires a \"destdir\"."); | 289 *err_ = Err(function_token_, "This target type requires a \"destdir\"."); |
| 276 return; | 290 return; |
| 277 } | 291 } |
| 278 if (!value->VerifyTypeIs(Value::STRING, err_)) | 292 if (!value->VerifyTypeIs(Value::STRING, err_)) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 GetBuildSettings()->build_dir(), | 341 GetBuildSettings()->build_dir(), |
| 328 outputs[i].value(), value->list_value()[i], err_)) | 342 outputs[i].value(), value->list_value()[i], err_)) |
| 329 return; | 343 return; |
| 330 } | 344 } |
| 331 target_->swap_in_outputs(&outputs); | 345 target_->swap_in_outputs(&outputs); |
| 332 } | 346 } |
| 333 | 347 |
| 334 const BuildSettings* TargetGenerator::GetBuildSettings() const { | 348 const BuildSettings* TargetGenerator::GetBuildSettings() const { |
| 335 return scope_->settings()->build_settings(); | 349 return scope_->settings()->build_settings(); |
| 336 } | 350 } |
| OLD | NEW |