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::FillCompleteStaticLib() {
67 if (target_
->output_type() == Target::STATIC_LIBRARY
) {
68 const Value
* value
= scope_
->GetValue(variables::kCompleteStaticLib
, true);
71 if (!value
->VerifyTypeIs(Value::BOOLEAN
, err_
))
73 target_
->set_complete_static_lib(value
->boolean_value());
78 bool BinaryTargetGenerator::FillOutputName() {
79 const Value
* value
= scope_
->GetValue(variables::kOutputName
, true);
82 if (!value
->VerifyTypeIs(Value::STRING
, err_
))
84 target_
->set_output_name(value
->string_value());
88 bool BinaryTargetGenerator::FillOutputExtension() {
89 const Value
* value
= scope_
->GetValue(variables::kOutputExtension
, true);
92 if (!value
->VerifyTypeIs(Value::STRING
, err_
))
94 target_
->set_output_extension(value
->string_value());
98 bool BinaryTargetGenerator::FillAllowCircularIncludesFrom() {
99 const Value
* value
= scope_
->GetValue(
100 variables::kAllowCircularIncludesFrom
, true);
104 UniqueVector
<Label
> circular
;
105 ExtractListOfUniqueLabels(*value
, scope_
->GetSourceDir(),
106 ToolchainLabelForScope(scope_
), &circular
, err_
);
107 if (err_
->has_error())
110 // Validate that all circular includes entries are in the deps.
111 for (const auto& cur
: circular
) {
112 bool found_dep
= false;
113 for (const auto& dep_pair
: target_
->GetDeps(Target::DEPS_LINKED
)) {
114 if (dep_pair
.label
== cur
) {
120 *err_
= Err(*value
, "Label not in deps.",
121 "The label \"" + cur
.GetUserVisibleName(false) +
122 "\"\nwas not in the deps of this target. "
123 "allow_circular_includes_from only allows\ntargets present in the "
130 for (const auto& cur
: circular
)
131 target_
->allow_circular_includes_from().insert(cur
);