forked from googleapis/googleapis
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathload_json.bzl
More file actions
25 lines (20 loc) · 818 Bytes
/
load_json.bzl
File metadata and controls
25 lines (20 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""Helper to load configuration from JSON files."""
def _load_json_impl(repository_ctx):
"""Create a starlark equivalent of a parsed JSON file
Args:
repository_ctx: repository context
"""
json_data = json.decode(repository_ctx.read(repository_ctx.attr.src))
repository_ctx.file("BUILD", "exports_files([ \"json.bzl\"])")
repository_ctx.file("json.bzl", "{}={}".format(
repository_ctx.attr.variable_name,
repr(json_data),
))
load_json = repository_rule(
implementation = _load_json_impl,
attrs = {
"src": attr.label(allow_single_file = True, default = "//:example-file.json", doc = "a JSON file"),
"variable_name": attr.string(default = "version_json", doc = "symbol to define by the contents of the JSON file"),
},
local = True,
)