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
3 // found in the LICENSE file.
5 #include "tools/gn/binary_target_generator.h"
7 #include "tools/gn/config_values_generator.h"
8 #include "tools/gn/deps_iterator.h"
9 #include "tools/gn/err.h"
10 #include "tools/gn/functions.h"
11 #include "tools/gn/scope.h"
12 #include "tools/gn/value_extractors.h"
13 #include "tools/gn/variables.h"
15 BinaryTargetGenerator::BinaryTargetGenerator(
18 const FunctionCallNode
* function_call
,
19 Target::OutputType type
,
21 : TargetGenerator(target
, scope
, function_call
, err
),
25 BinaryTargetGenerator::~BinaryTargetGenerator() {
28 void BinaryTargetGenerator::DoRun() {
29 target_
->set_output_type(output_type_
);
31 if (!FillOutputName())
34 if (!FillOutputExtension())
43 if (!FillCheckIncludes())
52 if (!FillAllowCircularIncludesFrom())
55 if (!FillCompleteStaticLib())
58 // Config values (compiler flags, etc.) set directly on this target.
59 ConfigValuesGenerator
gen(&target_
->config_values(), scope_
,
60 scope_
->GetSourceDir(), err_
);
62 if (err_
->has_error())
66 bool BinaryTargetGenerator::FillCheckIncludes() {
67 const Value
* value
= scope_
->GetValue(variables::kCheckIncludes
, true);
70 if (!value
->VerifyTypeIs(Value::BOOLEAN
, err_
))
72 target_
->set_check_includes(value
->boolean_value());
76 bool BinaryTargetGenerator::FillCompleteStaticLib() {
77 if (target_
->output_type() == Target::STATIC_LIBRARY
) {
78 const Value
* value
= scope_
->GetValue(variables::kCompleteStaticLib
, true);
81 if (!value
->VerifyTypeIs(Value::BOOLEAN
, err_
))
83 target_
->set_complete_static_lib(value
->boolean_value());
88 bool BinaryTargetGenerator::FillOutputName() {
89 const Value
* value
= scope_
->GetValue(variables::kOutputName
, true);
92 if (!value
->VerifyTypeIs(Value::STRING
, err_
))
94 target_
->set_output_name(value
->string_value());
98 bool BinaryTargetGenerator::FillOutputExtension() {
99 const Value
* value
= scope_
->GetValue(variables::kOutputExtension
, true);
102 if (!value
->VerifyTypeIs(Value::STRING
, err_
))
104 target_
->set_output_extension(value
->string_value());
108 bool BinaryTargetGenerator::FillAllowCircularIncludesFrom() {
109 const Value
* value
= scope_
->GetValue(
110 variables::kAllowCircularIncludesFrom
, true);
114 UniqueVector
<Label
> circular
;
115 ExtractListOfUniqueLabels(*value
, scope_
->GetSourceDir(),
116 ToolchainLabelForScope(scope_
), &circular
, err_
);
117 if (err_
->has_error())
120 // Validate that all circular includes entries are in the deps.
121 for (size_t circular_i
= 0; circular_i
< circular
.size(); circular_i
++) {
122 bool found_dep
= false;
123 for (const auto& dep_pair
: target_
->GetDeps(Target::DEPS_LINKED
)) {
124 if (dep_pair
.label
== circular
[circular_i
]) {
130 *err_
= Err(*value
, "Label not in deps.",
131 "The label \"" + circular
[circular_i
].GetUserVisibleName(false) +
132 "\"\nwas not in the deps of this target. "
133 "allow_circular_includes_from only allows\ntargets present in the "
140 for (size_t i
= 0; i
< circular
.size(); i
++)
141 target_
->allow_circular_includes_from().insert(circular
[i
]);