[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / tools / gn / binary_target_generator.cc
blob923d0edd7a95f37ac66538e62a67cefcf68aac52
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(
16 Target* target,
17 Scope* scope,
18 const FunctionCallNode* function_call,
19 Target::OutputType type,
20 Err* err)
21 : TargetGenerator(target, scope, function_call, err),
22 output_type_(type) {
25 BinaryTargetGenerator::~BinaryTargetGenerator() {
28 void BinaryTargetGenerator::DoRun() {
29 target_->set_output_type(output_type_);
31 if (!FillOutputName())
32 return;
34 if (!FillOutputExtension())
35 return;
37 if (!FillSources())
38 return;
40 if (!FillPublic())
41 return;
43 if (!FillCheckIncludes())
44 return;
46 if (!FillInputs())
47 return;
49 if (!FillConfigs())
50 return;
52 if (!FillAllowCircularIncludesFrom())
53 return;
55 if (!FillCompleteStaticLib())
56 return;
58 // Config values (compiler flags, etc.) set directly on this target.
59 ConfigValuesGenerator gen(&target_->config_values(), scope_,
60 scope_->GetSourceDir(), err_);
61 gen.Run();
62 if (err_->has_error())
63 return;
66 bool BinaryTargetGenerator::FillCompleteStaticLib() {
67 if (target_->output_type() == Target::STATIC_LIBRARY) {
68 const Value* value = scope_->GetValue(variables::kCompleteStaticLib, true);
69 if (!value)
70 return true;
71 if (!value->VerifyTypeIs(Value::BOOLEAN, err_))
72 return false;
73 target_->set_complete_static_lib(value->boolean_value());
75 return true;
78 bool BinaryTargetGenerator::FillOutputName() {
79 const Value* value = scope_->GetValue(variables::kOutputName, true);
80 if (!value)
81 return true;
82 if (!value->VerifyTypeIs(Value::STRING, err_))
83 return false;
84 target_->set_output_name(value->string_value());
85 return true;
88 bool BinaryTargetGenerator::FillOutputExtension() {
89 const Value* value = scope_->GetValue(variables::kOutputExtension, true);
90 if (!value)
91 return true;
92 if (!value->VerifyTypeIs(Value::STRING, err_))
93 return false;
94 target_->set_output_extension(value->string_value());
95 return true;
98 bool BinaryTargetGenerator::FillAllowCircularIncludesFrom() {
99 const Value* value = scope_->GetValue(
100 variables::kAllowCircularIncludesFrom, true);
101 if (!value)
102 return true;
104 UniqueVector<Label> circular;
105 ExtractListOfUniqueLabels(*value, scope_->GetSourceDir(),
106 ToolchainLabelForScope(scope_), &circular, err_);
107 if (err_->has_error())
108 return false;
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) {
115 found_dep = true;
116 break;
119 if (!found_dep) {
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 "
124 "deps.");
125 return false;
129 // Add to the set.
130 for (const auto& cur : circular)
131 target_->allow_circular_includes_from().insert(cur);
132 return true;