Skip to content

Commit 6e571fb

Browse files
committed
feat: build recipe defines and collect transitive sourecs
1 parent e6ffe85 commit 6e571fb

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

ecsact/private/ecsact_build_recipe.bzl

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,28 @@ def _is_cc_source(p):
4949
return False
5050

5151
def _cpp_source_collector_aspect_impl(target, ctx):
52-
sources = []
52+
direct_sources = []
5353
if hasattr(ctx.rule.attr, "srcs"):
5454
for src in ctx.rule.files.srcs:
5555
if _is_cc_source(src.path):
56-
sources.append(src)
56+
direct_sources.append(src)
5757

58-
return [CppSourceCollectorInfo(sources = sources)]
58+
transitive_sources = []
59+
if hasattr(ctx.rule.attr, "deps"):
60+
for dep in ctx.rule.attr.deps:
61+
if CppSourceCollectorInfo in dep:
62+
transitive_sources.append(dep[CppSourceCollectorInfo].sources)
63+
64+
return [
65+
CppSourceCollectorInfo(
66+
sources = depset(direct_sources, transitive = transitive_sources),
67+
),
68+
]
5969

6070
_cpp_source_collector_aspect = aspect(
6171
implementation = _cpp_source_collector_aspect_impl,
6272
attr_aspects = ["deps"],
73+
provides = [CppSourceCollectorInfo],
6374
)
6475

6576
def _strip_external(p):
@@ -98,6 +109,7 @@ def _ecsact_build_recipe(ctx):
98109

99110
sources = []
100111
recipe_data = []
112+
defines_map = {}
101113

102114
source_paths = []
103115

@@ -132,7 +144,7 @@ def _ecsact_build_recipe(ctx):
132144
cc_dep_compilation_contexts.append(cc_info.compilation_context)
133145

134146
source_info = cc_dep[CppSourceCollectorInfo]
135-
for src in source_info.sources:
147+
for src in source_info.sources.to_list():
136148
source_paths.append({
137149
"path": src.path,
138150
"outdir": _source_outdir(src),
@@ -142,6 +154,14 @@ def _ecsact_build_recipe(ctx):
142154

143155
if len(cc_dep_compilation_contexts) > 0:
144156
cc_dep_compilation_context = cc_common.merge_compilation_contexts(compilation_contexts = cc_dep_compilation_contexts)
157+
defines = cc_dep_compilation_context.defines.to_list() + cc_dep_compilation_context.local_defines.to_list()
158+
159+
for d in defines:
160+
pair = d.split("=", 1)
161+
key = pair[0]
162+
value = pair[1] if len(pair) > 1 else ""
163+
164+
defines_map[key] = value
145165

146166
for hdr in cc_dep_compilation_context.headers.to_list():
147167
hdr_prefix = ""
@@ -181,6 +201,7 @@ def _ecsact_build_recipe(ctx):
181201

182202
recipe = {
183203
"name": ctx.attr.name,
204+
"defines": defines_map,
184205
"sources": sources,
185206
"imports": ctx.attr.imports,
186207
"system_libs": ctx.attr.system_libs,
@@ -205,6 +226,7 @@ ecsact_build_recipe = rule(
205226
"srcs": attr.label_list(
206227
allow_files = True,
207228
),
229+
"defines": attr.string_dict(),
208230
"cc_deps": attr.label_list(
209231
providers = [CcInfo],
210232
aspects = [_cpp_source_collector_aspect],

0 commit comments

Comments
 (0)