| 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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 if (err_->has_error()) | 210 if (err_->has_error()) |
| 211 return; | 211 return; |
| 212 | 212 |
| 213 // This is a list of dependent targets to have their configs fowarded, so | 213 // This is a list of dependent targets to have their configs fowarded, so |
| 214 // it goes here rather than in FillConfigs. | 214 // it goes here rather than in FillConfigs. |
| 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(bool allow_substitutions) { |
| 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; |
| 228 |
| 229 if (!allow_substitutions) { |
| 230 // Verify no substitutions were actually used. |
| 231 if (!outputs.required_types().empty()) { |
| 232 *err_ = Err(*value, "Source expansions not allowed here.", |
| 233 "The outputs of this target used source {{expansions}} but this " |
| 234 "targe type\ndoesn't support them. Just express the outputs " |
| 235 "literally."); |
| 236 return; |
| 237 } |
| 238 } |
| 239 |
| 240 // Check the substitutions used are valid for this purpose. |
| 241 if (!EnsureValidSourcesSubstitutions(outputs.required_types(), |
| 242 value->origin(), err_)) |
| 227 return; | 243 return; |
| 228 | 244 |
| 229 // Validate that outputs are in the output dir. | 245 // Validate that outputs are in the output dir. |
| 230 bool allow_templates = target_->output_type() == Target::ACTION_FOREACH || | 246 CHECK(outputs.list().size() == value->list_value().size()); |
| 231 target_->output_type() == Target::COPY_FILES; | 247 for (size_t i = 0; i < outputs.list().size(); i++) { |
| 232 CHECK(outputs.size() == value->list_value().size()); | 248 if (!EnsureSubstitutionIsInOutputDir(outputs.list()[i], |
| 233 for (size_t i = 0; i < outputs.size(); i++) { | 249 value->list_value()[i])) |
| 234 if (!EnsureStringIsInOutputDir( | |
| 235 GetBuildSettings()->build_dir(), | |
| 236 outputs[i], value->list_value()[i], allow_templates, err_)) | |
| 237 return; | 250 return; |
| 238 } | 251 } |
| 239 } | 252 } |
| 240 | 253 |
| 254 bool TargetGenerator::EnsureSubstitutionIsInOutputDir( |
| 255 const SubstitutionPattern& pattern, |
| 256 const Value& original_value) { |
| 257 if (pattern.ranges().empty()) { |
| 258 // Pattern is empty, error out (this prevents weirdness below). |
| 259 *err_ = Err(original_value, "This has an empty value in it."); |
| 260 return false; |
| 261 } |
| 262 |
| 263 if (pattern.ranges()[0].type == SUBSTITUTION_LITERAL) { |
| 264 // If the first thing is a literal, it must start with the output dir. |
| 265 if (!EnsureStringIsInOutputDir( |
| 266 GetBuildSettings()->build_dir(), |
| 267 pattern.ranges()[0].literal, original_value, err_)) |
| 268 return false; |
| 269 } else { |
| 270 // Otherwise, the first subrange must be a pattern that expands to |
| 271 // something in the output directory. |
| 272 if (!SubstitutionIsInOutputDir(pattern.ranges()[0].type)) { |
| 273 *err_ = Err(original_value, |
| 274 "File is not inside output directory.", |
| 275 "The given file should be in the output directory. Normally you\n" |
| 276 "would specify\n\"$target_out_dir/foo\" or " |
| 277 "\"{{source_gen_dir}}/foo\"."); |
| 278 return false; |
| 279 } |
| 280 } |
| 281 |
| 282 return true; |
| 283 } |
| 284 |
| 241 void TargetGenerator::FillGenericConfigs(const char* var_name, | 285 void TargetGenerator::FillGenericConfigs(const char* var_name, |
| 242 LabelConfigVector* dest) { | 286 LabelConfigVector* dest) { |
| 243 const Value* value = scope_->GetValue(var_name, true); | 287 const Value* value = scope_->GetValue(var_name, true); |
| 244 if (value) { | 288 if (value) { |
| 245 ExtractListOfLabels(*value, scope_->GetSourceDir(), | 289 ExtractListOfLabels(*value, scope_->GetSourceDir(), |
| 246 ToolchainLabelForScope(scope_), dest, err_); | 290 ToolchainLabelForScope(scope_), dest, err_); |
| 247 } | 291 } |
| 248 } | 292 } |
| 249 | 293 |
| 250 void TargetGenerator::FillGenericDeps(const char* var_name, | 294 void TargetGenerator::FillGenericDeps(const char* var_name, |
| 251 LabelTargetVector* dest) { | 295 LabelTargetVector* dest) { |
| 252 const Value* value = scope_->GetValue(var_name, true); | 296 const Value* value = scope_->GetValue(var_name, true); |
| 253 if (value) { | 297 if (value) { |
| 254 ExtractListOfLabels(*value, scope_->GetSourceDir(), | 298 ExtractListOfLabels(*value, scope_->GetSourceDir(), |
| 255 ToolchainLabelForScope(scope_), dest, err_); | 299 ToolchainLabelForScope(scope_), dest, err_); |
| 256 } | 300 } |
| 257 } | 301 } |
| 258 | 302 |
| 259 void TargetGenerator::FillForwardDependentConfigs() { | 303 void TargetGenerator::FillForwardDependentConfigs() { |
| 260 const Value* value = scope_->GetValue( | 304 const Value* value = scope_->GetValue( |
| 261 variables::kForwardDependentConfigsFrom, true); | 305 variables::kForwardDependentConfigsFrom, true); |
| 262 if (value) { | 306 if (value) { |
| 263 ExtractListOfLabels(*value, scope_->GetSourceDir(), | 307 ExtractListOfLabels(*value, scope_->GetSourceDir(), |
| 264 ToolchainLabelForScope(scope_), | 308 ToolchainLabelForScope(scope_), |
| 265 &target_->forward_dependent_configs(), err_); | 309 &target_->forward_dependent_configs(), err_); |
| 266 } | 310 } |
| 267 } | 311 } |
| OLD | NEW |