Skip to content

Commit

Permalink
Let rules_jsonnet use its own provider (#172)
Browse files Browse the repository at this point in the history
Right now it uses struct() to declare information that's yielded, but
this makes it annoying to use, especially when using it in combination
with other rules that do use providers.
  • Loading branch information
EdSchouten committed Apr 3, 2024
1 parent 8f4598f commit 748567f
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions jsonnet/jsonnet.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ def _setup_deps(deps):
transitive_sources = []
imports = []
for dep in deps:
transitive_sources.append(dep.transitive_jsonnet_files)
imports.append(dep.imports)
transitive_sources.append(dep[JsonnetLibraryInfo].transitive_jsonnet_files)
imports.append(dep[JsonnetLibraryInfo].imports)

return struct(
imports = depset(transitive = imports),
transitive_sources = depset(transitive = transitive_sources, order = "postorder"),
)

JsonnetLibraryInfo = provider()

def _jsonnet_library_impl(ctx):
"""Implementation of the jsonnet_library rule."""
depinfo = _setup_deps(ctx.attr.deps)
Expand All @@ -88,15 +90,19 @@ def _jsonnet_library_impl(ctx):
transitive = [dep.data_runfiles.files for dep in ctx.attr.deps],
)

return struct(
files = depset(),
imports = imports,
runfiles = ctx.runfiles(
transitive_files = transitive_data,
collect_data = True,
return [
DefaultInfo(
files = depset(),
runfiles = ctx.runfiles(
transitive_files = transitive_data,
collect_data = True,
),
),
transitive_jsonnet_files = sources,
)
JsonnetLibraryInfo(
imports = imports,
transitive_jsonnet_files = sources,
),
]

def _jsonnet_toolchain(ctx):
return struct(
Expand Down Expand Up @@ -433,13 +439,13 @@ def _jsonnet_to_json_test_impl(ctx):
stamp_inputs
)

return struct(
return [DefaultInfo(
runfiles = ctx.runfiles(
files = test_inputs,
transitive_files = transitive_data,
collect_data = True,
),
)
)]

_jsonnet_common_attrs = {
"data": attr.label_list(
Expand All @@ -457,7 +463,7 @@ _jsonnet_common_attrs = {
),
"deps": attr.label_list(
doc = "List of targets that are required by the `srcs` Jsonnet files.",
providers = ["transitive_jsonnet_files"],
providers = [JsonnetLibraryInfo],
allow_files = False,
),
}
Expand Down

0 comments on commit 748567f

Please sign in to comment.