-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathincremental_library_targets.bzl
More file actions
265 lines (239 loc) · 8.76 KB
/
incremental_library_targets.bzl
File metadata and controls
265 lines (239 loc) · 8.76 KB
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
"""Functions for processing library targets."""
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("@build_bazel_rules_apple//apple:providers.bzl", "AppleDebugOutputsInfo")
load("@build_bazel_rules_swift//swift:swift.bzl", "SwiftInfo", "SwiftProtoInfo")
load("//xcodeproj/internal:build_settings.bzl", "get_product_module_name")
load("//xcodeproj/internal:compilation_providers.bzl", "compilation_providers")
load("//xcodeproj/internal:compiler_args.bzl", "compiler_args")
load("//xcodeproj/internal:configuration.bzl", "calculate_configuration")
load("//xcodeproj/internal:dependencies.bzl", "dependencies")
load(
"//xcodeproj/internal:incremental_xcode_targets.bzl",
xcode_targets = "incremental_xcode_targets",
)
load(
"//xcodeproj/internal:memory_efficiency.bzl",
"EMPTY_TUPLE",
)
load("//xcodeproj/internal:pbxproj_partials.bzl", "pbxproj_partials")
load("//xcodeproj/internal:platforms.bzl", "platforms")
load("//xcodeproj/internal:products.bzl", "products")
load("//xcodeproj/internal:target_id.bzl", "get_id")
load(
"//xcodeproj/internal/files:incremental_input_files.bzl",
input_files = "incremental_input_files",
)
load(
"//xcodeproj/internal/files:incremental_output_files.bzl",
"output_groups",
output_files = "incremental_output_files",
)
load("//xcodeproj/internal/files:linker_input_files.bzl", "linker_input_files")
load(
":incremental_processed_targets.bzl",
processed_targets = "incremental_processed_targets",
)
def _process_incremental_library_target(
*,
ctx,
target,
attrs,
automatic_target_info,
generate_target,
rule_attr,
transitive_infos):
"""Gathers information about a library target.
Args:
ctx: The aspect context.
target: The `Target` to process.
attrs: `dir(ctx.rule.attr)` (as a performance optimization).
automatic_target_info: The `XcodeProjAutomaticTargetProcessingInfo` for
`target`.
generate_target: Whether an Xcode target should be generated for this
target.
rule_attr: `ctx.rule.attr`.
transitive_infos: A `list` of `XcodeProjInfo`s from the transitive
dependencies of `target`.
Returns:
A value from `processed_target`.
"""
bin_dir_path = ctx.bin_dir.path
configuration = calculate_configuration(bin_dir_path = bin_dir_path)
label = automatic_target_info.label
id = get_id(label = label, configuration = configuration)
product_name = rule_attr.name
direct_dependencies, transitive_dependencies = dependencies.collect(
transitive_infos = transitive_infos,
)
cc_info = target[CcInfo]
objc = target[apple_common.Objc] if apple_common.Objc in target else None
swift_info = target[SwiftInfo] if SwiftInfo in target else None
(
target_compilation_providers,
provider_compilation_providers,
) = compilation_providers.collect(
cc_info = cc_info,
objc = objc,
)
linker_inputs = linker_input_files.collect(
automatic_target_info = automatic_target_info,
compilation_providers = target_compilation_providers,
target = target,
)
platform = platforms.collect(ctx = ctx)
actions = ctx.actions
# Value taken from `PRODUCT_TYPE_ENCODED` in `product.bzl`, for
# `com.apple.product-type.library.static`
product_type = "L"
product = products.collect(
actions = actions,
linker_inputs = linker_inputs,
product_name = product_name,
product_type = product_type,
target = target,
)
(target_inputs, provider_inputs) = input_files.collect(
ctx = ctx,
attrs = attrs,
automatic_target_info = automatic_target_info,
label = label,
linker_inputs = linker_inputs,
platform = platform,
rule_attr = rule_attr,
swift_proto_info = (
target[SwiftProtoInfo] if SwiftProtoInfo in target else None
),
transitive_infos = transitive_infos,
)
package_bin_dir = products.calculate_packge_bin_dir(
bin_dir_path = bin_dir_path,
label = label,
)
args = compiler_args.collect(
c_sources = target_inputs.c_sources,
cxx_sources = target_inputs.cxx_sources,
target = target,
)
(
target_build_settings,
swift_debug_settings_file,
params_files,
) = pbxproj_partials.write_target_build_settings(
actions = actions,
apple_generate_dsym = ctx.fragments.cpp.apple_generate_dsym,
colorize = ctx.attr._colorize[BuildSettingInfo].value,
conly_args = args.conly,
cxx_args = args.cxx,
generate_build_settings = generate_target,
generate_swift_debug_settings = bool(args.swift),
name = label.name,
swift_args = args.swift,
tool = ctx.executable._target_build_settings_generator,
)
swift_debug_settings = depset(
[swift_debug_settings_file] if swift_debug_settings_file else None,
transitive = [
info.swift_debug_settings
for info in transitive_infos
] if not swift_debug_settings_file else None,
)
if AppleDebugOutputsInfo in target:
debug_outputs = target[AppleDebugOutputsInfo]
else:
debug_outputs = None
(
target_outputs,
provider_outputs,
target_output_groups_metadata,
) = output_files.collect(
actions = actions,
compile_params_files = params_files,
debug_outputs = debug_outputs,
id = id,
name = label.name,
output_group_info = (
target[OutputGroupInfo] if OutputGroupInfo in target else None
),
product = product,
swift_info = swift_info,
transitive_infos = transitive_infos,
)
target_output_groups = output_groups.collect(
metadata = target_output_groups_metadata,
transitive_infos = transitive_infos,
)
swift_outputs = target_outputs.direct_outputs.swift
if generate_target:
module_name_attribute, module_name = get_product_module_name(
rule_attr = rule_attr,
target = target,
)
if swift_outputs and swift_outputs.indexstore:
indexstores = (swift_outputs.indexstore,)
else:
indexstores = EMPTY_TUPLE
mergeable_infos = depset(
[
struct(
args = args,
id = id,
indexstores = indexstores,
inputs = target_inputs.xcode_inputs,
module_name = module_name,
package_bin_dir = package_bin_dir,
premerged_info = None,
product_file = product.file,
swift_debug_settings = swift_debug_settings,
swiftmodule = (
swift_outputs.module.swiftmodule if swift_outputs else None
),
),
],
)
xcode_target = xcode_targets.make(
build_settings_file = target_build_settings,
configuration = configuration,
direct_dependencies = direct_dependencies,
has_c_params = bool(args.conly),
has_cxx_params = bool(args.cxx),
id = id,
inputs = target_inputs.xcode_inputs,
is_top_level = False,
label = label,
module_name = module_name,
module_name_attribute = module_name_attribute,
outputs = target_outputs,
package_bin_dir = package_bin_dir,
platform = platform,
product = product.xcode_product,
transitive_dependencies = transitive_dependencies,
)
else:
mergeable_infos = depset(
[
# We still set a value to prevent unfocused targets from
# changing which targets _could_ merge. This is filtered out
# in `top_level_targets.bzl`.
struct(
id = None,
premerged_info = None,
swiftmodule = bool(swift_outputs),
),
],
)
xcode_target = None
return processed_targets.make(
compilation_providers = provider_compilation_providers,
direct_dependencies = direct_dependencies,
inputs = provider_inputs,
mergeable_infos = mergeable_infos,
outputs = provider_outputs,
platform = platform.apple_platform,
swift_debug_settings = swift_debug_settings,
target_output_groups = target_output_groups,
transitive_dependencies = transitive_dependencies,
xcode_target = xcode_target,
)
incremental_library_targets = struct(
process = _process_incremental_library_target,
)