Skip to content

Commit c54ccc6

Browse files
authored
[bazel] Avoid deprecated ctx.outputs.executable and output_to_genfiles (#241742)
Modernize custom Starlark rules in `binary_alias.bzl` and `mlir/tblgen.bzl`: - Declare executable outputs explicitly via `ctx.actions.declare_file` and return them in `DefaultInfo(files = ..., executable = ...)` instead of relying on the deprecated `ctx.outputs.executable` predeclared output. - Remove the deprecated no-op `output_to_genfiles = True` argument from `gentbl_shard_rule`. Assisted-by: Gemini
1 parent c75229f commit c54ccc6

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

‎utils/bazel/llvm-project-overlay/llvm/binary_alias.bzl‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ binary_alias(
1111
"""
1212

1313
def _binary_alias_impl(ctx):
14+
out = ctx.actions.declare_file(ctx.label.name)
1415
ctx.actions.symlink(
1516
target_file = ctx.executable.binary,
16-
output = ctx.outputs.executable,
17+
output = out,
1718
is_executable = True,
1819
)
1920

2021
return [DefaultInfo(
21-
executable = ctx.outputs.executable,
22+
files = depset([out]),
23+
executable = out,
2224
runfiles = ctx.attr.binary[DefaultInfo].default_runfiles,
2325
)]
2426

‎utils/bazel/llvm-project-overlay/mlir/tblgen.bzl‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,9 @@ def _gentbl_test_impl(ctx):
257257

258258
test_args.extend(["-o", "/dev/null"])
259259

260+
exe = ctx.actions.declare_file(ctx.label.name)
260261
ctx.actions.write(
261-
ctx.outputs.executable,
262+
exe,
262263
content = " ".join(test_args),
263264
is_executable = True,
264265
)
@@ -282,7 +283,11 @@ def _gentbl_test_impl(ctx):
282283
source_attributes = ["td_file", "td_srcs"],
283284
dependency_attributes = ["tblgen", "deps"],
284285
),
285-
DefaultInfo(runfiles = runfiles),
286+
DefaultInfo(
287+
files = depset([exe]),
288+
executable = exe,
289+
runfiles = runfiles,
290+
),
286291
]
287292

288293
gentbl_test = rule(
@@ -473,7 +478,6 @@ def _gentbl_shard_impl(ctx):
473478
gentbl_shard_rule = rule(
474479
_gentbl_shard_impl,
475480
doc = "",
476-
output_to_genfiles = True,
477481
attrs = {
478482
"index": attr.int(mandatory = True, doc = ""),
479483
"sharder": attr.label(

0 commit comments

Comments
 (0)