Skip to content

Commit 1cba698

Browse files
authored
feat: Allow explicit file outputs vs extensions in codegen rule (#64)
1 parent 1303f78 commit 1cba698

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

ecsact/private/ecsact_codegen.bzl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ def _ecsact_codegen(ctx):
1919
plugin_info = plugin[EcsactCodegenPluginInfo]
2020
args.add("--plugin", plugin_info.plugin)
2121
plugin_data.extend(plugin_info.data)
22-
for src in ctx.files.srcs:
23-
out_basename = src.basename + "." + plugin_info.output_extension
24-
out_file = ctx.attr.output_directory + "/" + out_basename
25-
outputs.append(ctx.actions.declare_file(out_file))
22+
if len(plugin_info.outputs) == 0:
23+
for src in ctx.files.srcs:
24+
out_basename = src.basename + "." + plugin_info.output_extension
25+
out_file = ctx.attr.output_directory + "/" + out_basename
26+
outputs.append(ctx.actions.declare_file(out_file))
27+
else:
28+
for output in plugin_info.outputs:
29+
out_file = ctx.attr.output_directory + "/" + output
30+
outputs.append(ctx.actions.declare_file(out_file))
2631

2732
args.add("--outdir", outputs[0].dirname)
2833

ecsact/private/ecsact_codegen_plugin.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ EcsactCodegenPluginInfo = provider(
22
doc = "",
33
fields = {
44
"output_extension": "Plugin name. Also used as output file extension. This must match the extension specified by the plugin.",
5+
"outputs": "names of the ecsact files",
56
"plugin": "Path to plugin or name of builtin plugin",
67
"data": "Files needed at runtime",
78
},
@@ -20,6 +21,7 @@ def _ecsact_codegen_plugin(ctx):
2021
return [
2122
EcsactCodegenPluginInfo(
2223
output_extension = ctx.attr.output_extension,
24+
outputs = ctx.attr.outputs,
2325
plugin = plugin_path,
2426
data = data,
2527
),
@@ -29,7 +31,8 @@ ecsact_codegen_plugin = rule(
2931
implementation = _ecsact_codegen_plugin,
3032
doc = "Bazel info necessary for ecsact codegen plugin to be used with `ecsact_codegen`. Default plugins are available at `@ecsact//codegen_plugins:*`.",
3133
attrs = {
32-
"output_extension": attr.string(mandatory = True, doc = "Plugin name. Also used as output file extension. This must match the extension specified by the plugin."),
34+
"output_extension": attr.string(mandatory = False, doc = "Plugin name. Also used as output file extension. This must match the extension specified by the plugin."),
35+
"outputs": attr.string(mandatory = False),
3336
"plugin": attr.label(mandatory = False, allow_single_file = True, doc = "Label to plugin binary"),
3437
"plugin_path": attr.string(mandatory = False, doc = "Path to plugin or name of builtin plugin."),
3538
},

0 commit comments

Comments
 (0)