Skip to content
This repository was archived by the owner on Dec 29, 2025. It is now read-only.

Commit 3d63f16

Browse files
committed
Implement formatter_composite
1 parent a8c11bb commit 3d63f16

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

WORKSPACE.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ load("@com_github_bazelbuild_buildtools//buildifier:deps.bzl", "buildifier_depen
7373

7474
buildifier_dependencies()
7575

76+
# Rivet Bazel Util
77+
78+
RIVET_BAZEL_UTIL_VERSION = "f0c1bbe0935c3994e4c1ea4b3370a47d8df9819e"
79+
80+
http_archive(
81+
name = "rivet_bazel_util",
82+
sha256 = "fca24b50c6544c0c2146bca6de7b00558c276020e64692b770361d650ed97b6e",
83+
strip_prefix = "rivet-bazel-util-%s" % RIVET_BAZEL_UTIL_VERSION,
84+
url = "https://github.com/rivethealth/rivet-bazel-util/archive/%s.tar.gz" % RIVET_BAZEL_UTIL_VERSION,
85+
)
86+
7687
# Format
7788

7889
load("//file:workspace.bzl", "files")

generate/rules.bzl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,30 @@ format = rule(
145145
implementation = _format_impl,
146146
)
147147

148+
def _formatter_composite_impl(ctx):
149+
formatters = [target[FormatterInfo] for target in ctx.attr.formatters]
150+
fns = [formatter.fn for formatter in formatters]
151+
152+
def _fn(ctx, path, src, formatted):
153+
actions = ctx.actions
154+
name = ctx.attr
155+
for i, fn in enumerate(fns):
156+
tmp = formatted if i == len(fns) - 1 else actions.declare_file("%s.out.%s/%s" % (name, i + 1, src.path))
157+
fn(ctx, path, src, tmp)
158+
src = tmp
159+
160+
formatter_info = FormatterInfo(fn = _fn)
161+
162+
return [formatter_info]
163+
164+
formatter_composite = rule(
165+
attrs = {
166+
"formatters": attr.label_list(mandatory = True, providers = [FormatterInfo]),
167+
},
168+
implementation = _formatter_composite_impl,
169+
provides = [FormatterInfo],
170+
)
171+
148172
def _generate_impl(ctx):
149173
actions = ctx.actions
150174
bash_runfiles = ctx.files._bash_runfiles

0 commit comments

Comments
 (0)