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