| 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/action_target_generator.h" | 7 #include "tools/gn/action_target_generator.h" |
| 8 #include "tools/gn/binary_target_generator.h" | 8 #include "tools/gn/binary_target_generator.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" |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 FillForwardDependentConfigs(); | 215 FillForwardDependentConfigs(); |
| 216 if (err_->has_error()) | 216 if (err_->has_error()) |
| 217 return; | 217 return; |
| 218 } | 218 } |
| 219 | 219 |
| 220 void TargetGenerator::FillOutputs() { | 220 void TargetGenerator::FillOutputs() { |
| 221 const Value* value = scope_->GetValue(variables::kOutputs, true); | 221 const Value* value = scope_->GetValue(variables::kOutputs, true); |
| 222 if (!value) | 222 if (!value) |
| 223 return; | 223 return; |
| 224 | 224 |
| 225 std::vector<std::string>& outputs = target_->action_values().outputs(); | 225 SubstitutionList& outputs = target_->action_values().outputs(); |
| 226 if (!ExtractListOfStringValues(*value, &outputs, err_)) | 226 if (!outputs.Parse(*value, err_)) |
| 227 return; | 227 return; |
| 228 | 228 |
| 229 // Check the substitutions used are valid for this purpose. |
| 230 if (!EnsureValidSourcesSubstitutions(outputs.required_types(), |
| 231 value->origin(), err_)) |
| 232 return |
| 233 |
| 229 // Validate that outputs are in the output dir. | 234 // Validate that outputs are in the output dir. |
| 230 bool allow_templates = target_->output_type() == Target::ACTION_FOREACH || | 235 CHECK(outputs.list().size() == value->list_value().size()); |
| 231 target_->output_type() == Target::COPY_FILES; | 236 for (size_t i = 0; i < outputs.list().size(); i++) { |
| 232 CHECK(outputs.size() == value->list_value().size()); | 237 if (!EnsureSubstitutionIsInOutputDir(outputs.list()[i], |
| 233 for (size_t i = 0; i < outputs.size(); i++) { | 238 value->list_value()[i])) |
| 234 if (!EnsureStringIsInOutputDir( | |
| 235 GetBuildSettings()->build_dir(), | |
| 236 outputs[i], value->list_value()[i], allow_templates, err_)) | |
| 237 return; | 239 return; |
| 238 } | 240 } |
| 239 } | 241 } |
| 240 | 242 |
| 243 bool TargetGenerator::EnsureSubstitutionIsInOutputDir( |
| 244 const SubstitutionPattern& pattern, |
| 245 const Value& original_value) { |
| 246 if (pattern.ranges().empty()) { |
| 247 // Pattern is empty, error out (this prevents weirdness below). |
| 248 *err_ = Err(original_value, "This has an empty value in it."); |
| 249 return false; |
| 250 } |
| 251 |
| 252 if (pattern.ranges()[0].type == SUBSTITUTION_LITERAL) { |
| 253 // If the first thing is a literal, it must start with the output dir. |
| 254 if (!EnsureStringIsInOutputDir( |
| 255 GetBuildSettings()->build_dir(), |
| 256 pattern.ranges()[0].literal, original_value, err_)) |
| 257 return false; |
| 258 } else { |
| 259 // Otherwise, the first subrange must be a pattern that expands to |
| 260 // something in the output directory. |
| 261 if (!SubstitutionIsInOutputDir(pattern.ranges()[0].type)) { |
| 262 *err_ = Err(original_value, |
| 263 "File is not inside output directory.", |
| 264 "The given file should be in the output directory. Normally you\n" |
| 265 "would specify\n\"$target_out_dir/foo\" or " |
| 266 "\"{{source_gen_dir}}/foo\"."); |
| 267 return false; |
| 268 } |
| 269 } |
| 270 |
| 271 return true; |
| 272 } |
| 273 |
| 241 void TargetGenerator::FillGenericConfigs(const char* var_name, | 274 void TargetGenerator::FillGenericConfigs(const char* var_name, |
| 242 LabelConfigVector* dest) { | 275 LabelConfigVector* dest) { |
| 243 const Value* value = scope_->GetValue(var_name, true); | 276 const Value* value = scope_->GetValue(var_name, true); |
| 244 if (value) { | 277 if (value) { |
| 245 ExtractListOfLabels(*value, scope_->GetSourceDir(), | 278 ExtractListOfLabels(*value, scope_->GetSourceDir(), |
| 246 ToolchainLabelForScope(scope_), dest, err_); | 279 ToolchainLabelForScope(scope_), dest, err_); |
| 247 } | 280 } |
| 248 } | 281 } |
| 249 | 282 |
| 250 void TargetGenerator::FillGenericDeps(const char* var_name, | 283 void TargetGenerator::FillGenericDeps(const char* var_name, |
| 251 LabelTargetVector* dest) { | 284 LabelTargetVector* dest) { |
| 252 const Value* value = scope_->GetValue(var_name, true); | 285 const Value* value = scope_->GetValue(var_name, true); |
| 253 if (value) { | 286 if (value) { |
| 254 ExtractListOfLabels(*value, scope_->GetSourceDir(), | 287 ExtractListOfLabels(*value, scope_->GetSourceDir(), |
| 255 ToolchainLabelForScope(scope_), dest, err_); | 288 ToolchainLabelForScope(scope_), dest, err_); |
| 256 } | 289 } |
| 257 } | 290 } |
| 258 | 291 |
| 259 void TargetGenerator::FillForwardDependentConfigs() { | 292 void TargetGenerator::FillForwardDependentConfigs() { |
| 260 const Value* value = scope_->GetValue( | 293 const Value* value = scope_->GetValue( |
| 261 variables::kForwardDependentConfigsFrom, true); | 294 variables::kForwardDependentConfigsFrom, true); |
| 262 if (value) { | 295 if (value) { |
| 263 ExtractListOfLabels(*value, scope_->GetSourceDir(), | 296 ExtractListOfLabels(*value, scope_->GetSourceDir(), |
| 264 ToolchainLabelForScope(scope_), | 297 ToolchainLabelForScope(scope_), |
| 265 &target_->forward_dependent_configs(), err_); | 298 &target_->forward_dependent_configs(), err_); |
| 266 } | 299 } |
| 267 } | 300 } |
| OLD | NEW |