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/deps_iterator.h" |
8 #include "tools/gn/err.h" | 9 #include "tools/gn/err.h" |
9 #include "tools/gn/functions.h" | 10 #include "tools/gn/functions.h" |
10 #include "tools/gn/scope.h" | 11 #include "tools/gn/scope.h" |
11 #include "tools/gn/value_extractors.h" | 12 #include "tools/gn/value_extractors.h" |
12 #include "tools/gn/variables.h" | 13 #include "tools/gn/variables.h" |
13 | 14 |
14 BinaryTargetGenerator::BinaryTargetGenerator( | 15 BinaryTargetGenerator::BinaryTargetGenerator( |
15 Target* target, | 16 Target* target, |
16 Scope* scope, | 17 Scope* scope, |
17 const FunctionCallNode* function_call, | 18 const FunctionCallNode* function_call, |
18 Target::OutputType type, | 19 Target::OutputType type, |
19 Err* err) | 20 Err* err) |
20 : TargetGenerator(target, scope, function_call, err), | 21 : TargetGenerator(target, scope, function_call, err), |
21 output_type_(type) { | 22 output_type_(type) { |
22 } | 23 } |
23 | 24 |
24 BinaryTargetGenerator::~BinaryTargetGenerator() { | 25 BinaryTargetGenerator::~BinaryTargetGenerator() { |
25 } | 26 } |
26 | 27 |
27 void BinaryTargetGenerator::DoRun() { | 28 void BinaryTargetGenerator::DoRun() { |
28 target_->set_output_type(output_type_); | 29 target_->set_output_type(output_type_); |
29 | 30 |
30 FillOutputName(); | 31 if (!FillOutputName()) |
31 if (err_->has_error()) | |
32 return; | 32 return; |
33 | 33 |
34 FillOutputExtension(); | 34 if (!FillOutputExtension()) |
35 if (err_->has_error()) | |
36 return; | 35 return; |
37 | 36 |
38 FillSources(); | 37 if (!FillSources()) |
39 if (err_->has_error()) | |
40 return; | 38 return; |
41 | 39 |
42 FillPublic(); | 40 if (!FillPublic()) |
43 if (err_->has_error()) | |
44 return; | 41 return; |
45 | 42 |
46 FillCheckIncludes(); | 43 if (!FillCheckIncludes()) |
47 if (err_->has_error()) | |
48 return; | 44 return; |
49 | 45 |
50 FillInputs(); | 46 if (!FillInputs()) |
51 if (err_->has_error()) | |
52 return; | 47 return; |
53 | 48 |
54 FillConfigs(); | 49 if (!FillConfigs()) |
55 if (err_->has_error()) | |
56 return; | 50 return; |
57 | 51 |
58 FillAllowCircularIncludesFrom(); | 52 if (!FillAllowCircularIncludesFrom()) |
59 if (err_->has_error()) | |
60 return; | 53 return; |
61 | 54 |
62 FillCompleteStaticLib(); | 55 if (!FillCompleteStaticLib()) |
63 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 |