Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit 0262656

Browse files
authored
Return providers instead of struct from rule impl functions (#300)
* Return providers instead of struct from rule impl functions * fix buildifier * access default_runfiles via DefaultInfo provider * use transitive_files in the returned provider * tarsitive_files takes in a depset of files
1 parent e6259a4 commit 0262656

2 files changed

Lines changed: 34 additions & 12 deletions

File tree

k8s/object.bzl

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,17 @@ def _impl(ctx):
120120
output = ctx.outputs.executable,
121121
)
122122

123-
return struct(runfiles = ctx.runfiles(files = [
124-
ctx.executable.resolver,
125-
ctx.outputs.substituted,
126-
] + list(ctx.attr.resolver.default_runfiles.files) + all_inputs))
123+
return [
124+
DefaultInfo(
125+
runfiles = ctx.runfiles(
126+
files = [
127+
ctx.executable.resolver,
128+
ctx.outputs.substituted,
129+
] + all_inputs,
130+
transitive_files = ctx.attr.resolver[DefaultInfo].default_runfiles.files,
131+
),
132+
),
133+
]
127134

128135
def _resolve(ctx, string, output):
129136
stamps = [ctx.info_file, ctx.version_file]
@@ -215,12 +222,12 @@ def _common_impl(ctx):
215222
if hasattr(ctx.executable, "resolved"):
216223
substitutions["%{resolve_script}"] = _runfiles(ctx, ctx.executable.resolved)
217224
files += [ctx.executable.resolved]
218-
files += list(ctx.attr.resolved.default_runfiles.files)
225+
files += list(ctx.attr.resolved[DefaultInfo].default_runfiles.files)
219226

220227
if hasattr(ctx.executable, "reversed"):
221228
substitutions["%{reverse_script}"] = _runfiles(ctx, ctx.executable.reversed)
222229
files += [ctx.executable.reversed]
223-
files += list(ctx.attr.reversed.default_runfiles.files)
230+
files += list(ctx.attr.reversed[DefaultInfo].default_runfiles.files)
224231

225232
if hasattr(ctx.files, "unresolved"):
226233
substitutions["%{unresolved}"] = _runfiles(ctx, ctx.file.unresolved)
@@ -232,7 +239,11 @@ def _common_impl(ctx):
232239
output = ctx.outputs.executable,
233240
)
234241

235-
return struct(runfiles = ctx.runfiles(files = files))
242+
return [
243+
DefaultInfo(
244+
runfiles = ctx.runfiles(files = files),
245+
),
246+
]
236247

237248
_common_attrs = {
238249
# We allow cluster to be omitted, and we just
@@ -274,10 +285,17 @@ def _reverse(ctx):
274285
output = ctx.outputs.executable,
275286
)
276287

277-
return struct(runfiles = ctx.runfiles(files = [
278-
ctx.executable.reverser,
279-
ctx.file.template,
280-
] + list(ctx.attr.reverser.default_runfiles.files)))
288+
return [
289+
DefaultInfo(
290+
runfiles = ctx.runfiles(
291+
files = [
292+
ctx.executable.reverser,
293+
ctx.file.template,
294+
],
295+
transitive_files = ctx.attr.reverser[DefaultInfo].default_runfiles.files,
296+
),
297+
),
298+
]
281299

282300
_reversed = rule(
283301
attrs = _add_dicts(

k8s/objects.bzl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ def _run_all_impl(ctx):
3737
for obj in ctx.attr.objects:
3838
runfiles += list(obj.default_runfiles.files)
3939

40-
return struct(runfiles = ctx.runfiles(files = runfiles))
40+
return [
41+
DefaultInfo(
42+
runfiles = ctx.runfiles(files = runfiles),
43+
),
44+
]
4145

4246
_run_all = rule(
4347
attrs = {

0 commit comments

Comments
 (0)