Skip to content

Commit 5e60be4

Browse files
committed
fix: prevent duplicate sources when creating build recipe
1 parent a9cddfd commit 5e60be4

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

ecsact/private/ecsact_build_recipe.bzl

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@bazel_skylib//lib:paths.bzl", "paths")
12
load("@rules_cc//cc:find_cc_toolchain.bzl", "use_cc_toolchain")
23
load("//ecsact/private:ecsact_codegen_plugin.bzl", "EcsactCodegenPluginInfo")
34

@@ -31,6 +32,17 @@ def _source_outdir(src):
3132
return "include/" + _strip_external(src.dirname)
3233
return _strip_external(src.dirname)
3334

35+
def _dedup_sources(source_paths):
36+
# TODO(zaucy): this is very inefficient, we should properly use depsets
37+
seen = {}
38+
deduped = []
39+
for src in source_paths:
40+
key = (src["outdir"], paths.basename(src["path"]))
41+
if not key in seen:
42+
seen[key] = True
43+
deduped.append(src)
44+
return deduped
45+
3446
def _ecsact_build_recipe(ctx):
3547
# type: (ctx) -> None
3648

@@ -39,8 +51,10 @@ def _ecsact_build_recipe(ctx):
3951
sources = []
4052
recipe_data = []
4153

54+
source_paths = []
55+
4256
for src in ctx.files.srcs:
43-
sources.append({
57+
source_paths.append({
4458
"path": src.path,
4559
"outdir": _source_outdir(src),
4660
"relative_to_cwd": True,
@@ -96,13 +110,15 @@ def _ecsact_build_recipe(ctx):
96110
else:
97111
hdr_prefix_base_idx = hdr.path.rindex("/")
98112
hdr_prefix_base = "/" + hdr.path[:hdr_prefix_base_idx]
99-
sources.append({
113+
source_paths.append({
100114
"path": hdr.path,
101115
"outdir": "include" + hdr_prefix_base,
102116
"relative_to_cwd": True,
103117
})
104118
recipe_data.append(hdr)
105119

120+
sources.extend(_dedup_sources(source_paths))
121+
106122
recipe = {
107123
"name": ctx.attr.name,
108124
"sources": sources,
@@ -141,8 +157,7 @@ ecsact_build_recipe = rule(
141157
"codegen_plugins": attr.label_keyed_string_dict(
142158
providers = [EcsactCodegenPluginInfo],
143159
),
144-
"imports": attr.string_list(
145-
),
160+
"imports": attr.string_list(),
146161
"exports": attr.string_list(
147162
mandatory = True,
148163
),

0 commit comments

Comments
 (0)