Skip to content

feat: Allow explicit file outputs vs extensions in codegen rule #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions ecsact/private/ecsact_codegen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ def _ecsact_codegen(ctx):
plugin_info = plugin[EcsactCodegenPluginInfo]
args.add("--plugin", plugin_info.plugin)
plugin_data.extend(plugin_info.data)
for src in ctx.files.srcs:
out_basename = src.basename + "." + plugin_info.output_extension
out_file = ctx.attr.output_directory + "/" + out_basename
outputs.append(ctx.actions.declare_file(out_file))
if len(plugin_info.outputs) == 0:
for src in ctx.files.srcs:
out_basename = src.basename + "." + plugin_info.output_extension
out_file = ctx.attr.output_directory + "/" + out_basename
outputs.append(ctx.actions.declare_file(out_file))
else:
for output in plugin_info.outputs:
out_file = ctx.attr.output_directory + "/" + output
outputs.append(ctx.actions.declare_file(out_file))

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

Expand Down
5 changes: 4 additions & 1 deletion ecsact/private/ecsact_codegen_plugin.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ EcsactCodegenPluginInfo = provider(
doc = "",
fields = {
"output_extension": "Plugin name. Also used as output file extension. This must match the extension specified by the plugin.",
"outputs": "names of the ecsact files",
"plugin": "Path to plugin or name of builtin plugin",
"data": "Files needed at runtime",
},
Expand All @@ -20,6 +21,7 @@ def _ecsact_codegen_plugin(ctx):
return [
EcsactCodegenPluginInfo(
output_extension = ctx.attr.output_extension,
outputs = ctx.attr.outputs,
plugin = plugin_path,
data = data,
),
Expand All @@ -29,7 +31,8 @@ ecsact_codegen_plugin = rule(
implementation = _ecsact_codegen_plugin,
doc = "Bazel info necessary for ecsact codegen plugin to be used with `ecsact_codegen`. Default plugins are available at `@ecsact//codegen_plugins:*`.",
attrs = {
"output_extension": attr.string(mandatory = True, doc = "Plugin name. Also used as output file extension. This must match the extension specified by the plugin."),
"output_extension": attr.string(mandatory = False, doc = "Plugin name. Also used as output file extension. This must match the extension specified by the plugin."),
"outputs": attr.string(mandatory = False),
"plugin": attr.label(mandatory = False, allow_single_file = True, doc = "Label to plugin binary"),
"plugin_path": attr.string(mandatory = False, doc = "Path to plugin or name of builtin plugin."),
},
Expand Down