Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,24 @@ jsonnet_to_json_test(
jsonnet_library(
name = "code_library_lib",
srcs = ["code_library.libsonnet"],
deps = [":workflow"]
data = [":test_str_files"],
deps = [":workflow"],
)

jsonnet_to_json_test(
name = "extvar_code_library_test",
size = "small",
src = "extvar_code_library.jsonnet",
ext_code_libraries = { ":code_library_lib": "codefile" },
ext_code_libraries = {":code_library_lib": "codefile"},
golden = "extvar_files_library_golden.json",
)

jsonnet_to_json_test(
name = "tla_code_library_test",
size = "small",
src = "tla_code_library.jsonnet",
tla_code_libraries = { ":code_library_lib": "tla_code" },
golden = "tla_code_library_golden.json",
tla_code_libraries = {":code_library_lib": "tla_code"},
)

jsonnet_to_json_test(
Expand Down
2 changes: 2 additions & 0 deletions examples/extvar_code_library.jsonnet
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
local codefile = std.extVar('codefile');
local data = importstr 'file.txt';

{
job: codefile.workflow.Job,
shJob: codefile.workflow.ShJob,
data: data,
}
29 changes: 15 additions & 14 deletions examples/extvar_files_library_golden.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"job": {
"deps": [ ],
"inputs": [ ],
"outputs": [ ],
"type": "base"
},
"shJob": {
"command": "",
"deps": [ ],
"inputs": [ ],
"outputs": [ ],
"type": "sh",
"vars": { }
}
"job": {
"deps": [],
"inputs": [],
"outputs": [],
"type": "base"
},
"shJob": {
"command": "",
"deps": [],
"inputs": [],
"outputs": [],
"type": "sh",
"vars": {}
},
"data": "this is great\n"
}
16 changes: 12 additions & 4 deletions jsonnet/jsonnet.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,15 @@ def _jsonnet_to_json_impl(ctx):
outputs.append(compiled_json)
command += [ctx.file.src.path, "-o", compiled_json.path]

transitive_data = depset(transitive = [dep.data_runfiles.files for dep in ctx.attr.deps] +
[l.files for l in jsonnet_tla_code_files.keys()] +
[l.files for l in jsonnet_tla_str_files.keys()])
transitive_data = depset(
transitive =
[dep.data_runfiles.files for dep in ctx.attr.deps] +
[l.files for l in jsonnet_tla_code_files.keys()] +
[l.files for l in jsonnet_tla_str_files.keys()] +
[l[DefaultInfo].data_runfiles.files for l in jsonnet_tla_code_libraries.keys()] +
[l[DefaultInfo].data_runfiles.files for l in jsonnet_ext_code_libraries.keys()],
)

# NB(sparkprime): (1) transitive_data is never used, since runfiles is only
# used when .files is pulled from it. (2) This makes sense - jsonnet does
# not need transitive dependencies to be passed on the commandline. It
Expand Down Expand Up @@ -502,7 +508,9 @@ def _jsonnet_to_json_test_impl(ctx):
transitive_data = depset(
transitive = [dep.data_runfiles.files for dep in ctx.attr.deps] +
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Is there a reason that the jsonnet_ext_code_files & jsonnet_ext_str_files are not included here?

[l.files for l in jsonnet_tla_code_files.keys()] +
[l.files for l in jsonnet_tla_str_files.keys()],
[l.files for l in jsonnet_tla_str_files.keys()] +
[l[DefaultInfo].data_runfiles.files for l in jsonnet_tla_code_libraries.keys()] +
[l[DefaultInfo].data_runfiles.files for l in jsonnet_ext_code_libraries.keys()],
)

test_inputs = (
Expand Down