Skip to content

Commit

Permalink
Replace use of deprecated outputs rule parameter. (carbon-language#…
Browse files Browse the repository at this point in the history
…4074)

Instead compute the output in the implementation and return it via the
`DefaultInfo` provider. This matches the latest docs on how to write
rules producing a file:
https://bazel.build/rules/rules-tutorial#creating_a_file
  • Loading branch information
chandlerc authored Jun 22, 2024
1 parent fa43bde commit aff5b26
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions testing/file_test/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,8 @@ a file which can be accessed as a list. This avoids long argument parsing.

load("@rules_cc//cc:defs.bzl", "cc_test")

DataFilesInfo = provider(
"Data files for this target.",
fields = {
"data_files": "Data files for this target",
},
)

def _tests_as_input_file_rule_impl(ctx):
out = ctx.actions.declare_file(ctx.label.name + ".txt")
data_files = []
for tests in ctx.attr.data:
data_files.extend(
Expand All @@ -26,15 +20,13 @@ def _tests_as_input_file_rule_impl(ctx):
data_files.extend(
[f.path for f in tests[DefaultInfo].files.to_list()],
)
ctx.actions.write(ctx.outputs.data_files, "\n".join(data_files) + "\n")
ctx.actions.write(out, "\n".join(data_files) + "\n")
return [DefaultInfo(files = depset([out]))]

_tests_as_input_file_rule = rule(
attrs = {
"data": attr.label_list(allow_files = True),
},
outputs = {
"data_files": "%{name}.txt",
},
implementation = _tests_as_input_file_rule_impl,
)

Expand Down Expand Up @@ -69,7 +61,7 @@ def file_test(
testonly = 1,
)
args = ["--test_targets_file=$(rootpath :{0})".format(tests_file)] + args
data = [tests_file] + tests + data
data = [":" + tests_file] + tests + data

if prebuilt_binary:
native.sh_test(
Expand Down

0 comments on commit aff5b26

Please sign in to comment.