| 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/binary_target_generator.h" | 5 #include "tools/gn/binary_target_generator.h" |
| 6 | 6 |
| 7 #include "tools/gn/config_values_generator.h" | 7 #include "tools/gn/config_values_generator.h" |
| 8 #include "tools/gn/err.h" | 8 #include "tools/gn/err.h" |
| 9 #include "tools/gn/functions.h" |
| 9 #include "tools/gn/scope.h" | 10 #include "tools/gn/scope.h" |
| 11 #include "tools/gn/value_extractors.h" |
| 10 #include "tools/gn/variables.h" | 12 #include "tools/gn/variables.h" |
| 11 | 13 |
| 12 BinaryTargetGenerator::BinaryTargetGenerator( | 14 BinaryTargetGenerator::BinaryTargetGenerator( |
| 13 Target* target, | 15 Target* target, |
| 14 Scope* scope, | 16 Scope* scope, |
| 15 const FunctionCallNode* function_call, | 17 const FunctionCallNode* function_call, |
| 16 Target::OutputType type, | 18 Target::OutputType type, |
| 17 Err* err) | 19 Err* err) |
| 18 : TargetGenerator(target, scope, function_call, err), | 20 : TargetGenerator(target, scope, function_call, err), |
| 19 output_type_(type) { | 21 output_type_(type) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 34 return; | 36 return; |
| 35 | 37 |
| 36 FillSources(); | 38 FillSources(); |
| 37 if (err_->has_error()) | 39 if (err_->has_error()) |
| 38 return; | 40 return; |
| 39 | 41 |
| 40 FillPublic(); | 42 FillPublic(); |
| 41 if (err_->has_error()) | 43 if (err_->has_error()) |
| 42 return; | 44 return; |
| 43 | 45 |
| 46 FillCheckIncludes(); |
| 47 if (err_->has_error()) |
| 48 return; |
| 49 |
| 44 FillInputs(); | 50 FillInputs(); |
| 45 if (err_->has_error()) | 51 if (err_->has_error()) |
| 46 return; | 52 return; |
| 47 | 53 |
| 48 FillConfigs(); | 54 FillConfigs(); |
| 49 if (err_->has_error()) | 55 if (err_->has_error()) |
| 50 return; | 56 return; |
| 51 | 57 |
| 58 FillAllowCircularIncludesFrom(); |
| 59 if (err_->has_error()) |
| 60 return; |
| 61 |
| 52 // Config values (compiler flags, etc.) set directly on this target. | 62 // Config values (compiler flags, etc.) set directly on this target. |
| 53 ConfigValuesGenerator gen(&target_->config_values(), scope_, | 63 ConfigValuesGenerator gen(&target_->config_values(), scope_, |
| 54 scope_->GetSourceDir(), err_); | 64 scope_->GetSourceDir(), err_); |
| 55 gen.Run(); | 65 gen.Run(); |
| 56 if (err_->has_error()) | 66 if (err_->has_error()) |
| 57 return; | 67 return; |
| 58 } | 68 } |
| 59 | 69 |
| 70 void BinaryTargetGenerator::FillCheckIncludes() { |
| 71 const Value* value = scope_->GetValue(variables::kCheckIncludes, true); |
| 72 if (!value) |
| 73 return; |
| 74 if (!value->VerifyTypeIs(Value::BOOLEAN, err_)) |
| 75 return; |
| 76 target_->set_check_includes(value->boolean_value()); |
| 77 } |
| 78 |
| 60 void BinaryTargetGenerator::FillOutputName() { | 79 void BinaryTargetGenerator::FillOutputName() { |
| 61 const Value* value = scope_->GetValue(variables::kOutputName, true); | 80 const Value* value = scope_->GetValue(variables::kOutputName, true); |
| 62 if (!value) | 81 if (!value) |
| 63 return; | 82 return; |
| 64 if (!value->VerifyTypeIs(Value::STRING, err_)) | 83 if (!value->VerifyTypeIs(Value::STRING, err_)) |
| 65 return; | 84 return; |
| 66 target_->set_output_name(value->string_value()); | 85 target_->set_output_name(value->string_value()); |
| 67 } | 86 } |
| 68 | 87 |
| 69 void BinaryTargetGenerator::FillOutputExtension() { | 88 void BinaryTargetGenerator::FillOutputExtension() { |
| 70 const Value* value = scope_->GetValue(variables::kOutputExtension, true); | 89 const Value* value = scope_->GetValue(variables::kOutputExtension, true); |
| 71 if (!value) | 90 if (!value) |
| 72 return; | 91 return; |
| 73 if (!value->VerifyTypeIs(Value::STRING, err_)) | 92 if (!value->VerifyTypeIs(Value::STRING, err_)) |
| 74 return; | 93 return; |
| 75 target_->set_output_extension(value->string_value()); | 94 target_->set_output_extension(value->string_value()); |
| 76 } | 95 } |
| 96 |
| 97 void BinaryTargetGenerator::FillAllowCircularIncludesFrom() { |
| 98 const Value* value = scope_->GetValue( |
| 99 variables::kAllowCircularIncludesFrom, true); |
| 100 if (!value) |
| 101 return; |
| 102 |
| 103 UniqueVector<Label> circular; |
| 104 ExtractListOfUniqueLabels(*value, scope_->GetSourceDir(), |
| 105 ToolchainLabelForScope(scope_), &circular, err_); |
| 106 if (err_->has_error()) |
| 107 return; |
| 108 |
| 109 // Validate that all circular includes entries are in the deps. |
| 110 const LabelTargetVector& deps = target_->deps(); |
| 111 for (size_t circular_i = 0; circular_i < circular.size(); circular_i++) { |
| 112 bool found_dep = false; |
| 113 for (size_t dep_i = 0; dep_i < deps.size(); dep_i++) { |
| 114 if (deps[dep_i].label == circular[circular_i]) { |
| 115 found_dep = true; |
| 116 break; |
| 117 } |
| 118 } |
| 119 if (!found_dep) { |
| 120 *err_ = Err(*value, "Label not in deps.", |
| 121 "The label \"" + circular[circular_i].GetUserVisibleName(false) + |
| 122 "\"\nwas not in the deps of this target. " |
| 123 "allow_circular_includes_from only allows\ntargets present in the " |
| 124 "deps."); |
| 125 return; |
| 126 } |
| 127 } |
| 128 |
| 129 // Add to the set. |
| 130 for (size_t i = 0; i < circular.size(); i++) |
| 131 target_->allow_circular_includes_from().insert(circular[i]); |
| 132 } |
| OLD | NEW |