From 748567fa79ad728ff420e3be1f5d9e74bc7dc85d Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Wed, 3 Apr 2024 21:03:02 +0200 Subject: [PATCH] Let rules_jsonnet use its own provider (#172) 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. --- jsonnet/jsonnet.bzl | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/jsonnet/jsonnet.bzl b/jsonnet/jsonnet.bzl index a9ec20d..1e92aa5 100644 --- a/jsonnet/jsonnet.bzl +++ b/jsonnet/jsonnet.bzl @@ -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) @@ -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( @@ -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( @@ -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, ), }