forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
binary_target_generator.cc
182 lines (152 loc) · 4.96 KB
/
binary_target_generator.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "tools/gn/binary_target_generator.h"
#include "tools/gn/config_values_generator.h"
#include "tools/gn/deps_iterator.h"
#include "tools/gn/err.h"
#include "tools/gn/filesystem_utils.h"
#include "tools/gn/functions.h"
#include "tools/gn/scope.h"
#include "tools/gn/settings.h"
#include "tools/gn/value_extractors.h"
#include "tools/gn/variables.h"
BinaryTargetGenerator::BinaryTargetGenerator(
Target* target,
Scope* scope,
const FunctionCallNode* function_call,
Target::OutputType type,
Err* err)
: TargetGenerator(target, scope, function_call, err),
output_type_(type) {
}
BinaryTargetGenerator::~BinaryTargetGenerator() = default;
void BinaryTargetGenerator::DoRun() {
target_->set_output_type(output_type_);
if (!FillOutputName())
return;
if (!FillOutputPrefixOverride())
return;
if (!FillOutputDir())
return;
if (!FillOutputExtension())
return;
if (!FillSources())
return;
if (!FillPublic())
return;
if (!FillFriends())
return;
if (!FillCheckIncludes())
return;
if (!FillConfigs())
return;
if (!FillAllowCircularIncludesFrom())
return;
if (!FillCompleteStaticLib())
return;
// Config values (compiler flags, etc.) set directly on this target.
ConfigValuesGenerator gen(&target_->config_values(), scope_,
scope_->GetSourceDir(), err_);
gen.Run();
if (err_->has_error())
return;
}
bool BinaryTargetGenerator::FillCompleteStaticLib() {
if (target_->output_type() == Target::STATIC_LIBRARY) {
const Value* value = scope_->GetValue(variables::kCompleteStaticLib, true);
if (!value)
return true;
if (!value->VerifyTypeIs(Value::BOOLEAN, err_))
return false;
target_->set_complete_static_lib(value->boolean_value());
}
return true;
}
bool BinaryTargetGenerator::FillFriends() {
const Value* value = scope_->GetValue(variables::kFriend, true);
if (value) {
return ExtractListOfLabelPatterns(*value, scope_->GetSourceDir(),
&target_->friends(), err_);
}
return true;
}
bool BinaryTargetGenerator::FillOutputName() {
const Value* value = scope_->GetValue(variables::kOutputName, true);
if (!value)
return true;
if (!value->VerifyTypeIs(Value::STRING, err_))
return false;
target_->set_output_name(value->string_value());
return true;
}
bool BinaryTargetGenerator::FillOutputPrefixOverride() {
const Value* value = scope_->GetValue(variables::kOutputPrefixOverride, true);
if (!value)
return true;
if (!value->VerifyTypeIs(Value::BOOLEAN, err_))
return false;
target_->set_output_prefix_override(value->boolean_value());
return true;
}
bool BinaryTargetGenerator::FillOutputDir() {
const Value* value = scope_->GetValue(variables::kOutputDir, true);
if (!value)
return true;
if (!value->VerifyTypeIs(Value::STRING, err_))
return false;
if (value->string_value().empty())
return true; // Treat empty string as the default and do nothing.
const BuildSettings* build_settings = scope_->settings()->build_settings();
SourceDir dir = scope_->GetSourceDir().ResolveRelativeDir(
*value, err_, build_settings->root_path_utf8());
if (err_->has_error())
return false;
if (!EnsureStringIsInOutputDir(build_settings->build_dir(),
dir.value(), value->origin(), err_))
return false;
target_->set_output_dir(dir);
return true;
}
bool BinaryTargetGenerator::FillOutputExtension() {
const Value* value = scope_->GetValue(variables::kOutputExtension, true);
if (!value)
return true;
if (!value->VerifyTypeIs(Value::STRING, err_))
return false;
target_->set_output_extension(value->string_value());
return true;
}
bool BinaryTargetGenerator::FillAllowCircularIncludesFrom() {
const Value* value = scope_->GetValue(
variables::kAllowCircularIncludesFrom, true);
if (!value)
return true;
UniqueVector<Label> circular;
ExtractListOfUniqueLabels(*value, scope_->GetSourceDir(),
ToolchainLabelForScope(scope_), &circular, err_);
if (err_->has_error())
return false;
// Validate that all circular includes entries are in the deps.
for (const auto& cur : circular) {
bool found_dep = false;
for (const auto& dep_pair : target_->GetDeps(Target::DEPS_LINKED)) {
if (dep_pair.label == cur) {
found_dep = true;
break;
}
}
if (!found_dep) {
*err_ = Err(*value, "Label not in deps.",
"The label \"" + cur.GetUserVisibleName(false) +
"\"\nwas not in the deps of this target. "
"allow_circular_includes_from only allows\ntargets present in the "
"deps.");
return false;
}
}
// Add to the set.
for (const auto& cur : circular)
target_->allow_circular_includes_from().insert(cur);
return true;
}