Skip to content

Commit

Permalink
Refine #190 (#191)
Browse files Browse the repository at this point in the history
Even though the provided test case did work for situations where files
had mismatching directory names, it didn't work well if one of the
directory names was the prefix of the other.
  • Loading branch information
EdSchouten authored Apr 5, 2024
1 parent 0b1c584 commit ee776a7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
9 changes: 9 additions & 0 deletions examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,12 @@ jsonnet_to_json(
"nested/dir2/file2.json",
],
)

jsonnet_to_json(
name = "multiple_outs_nested_asymmetric",
src = "multiple_outs_nested_asymmetric.jsonnet",
outs = [
"multiple_outs_nested_asymmetric/aaaaa/file.json",
"multiple_outs_nested_asymmetric/file.json",
],
)
4 changes: 4 additions & 0 deletions examples/multiple_outs_nested_asymmetric.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
'aaaaa/file.json': {},
'file.json': {},
}
4 changes: 3 additions & 1 deletion jsonnet/jsonnet.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ def _jsonnet_to_json_impl(ctx):
# directory name that is shared by all output files.
base_dirname = ctx.outputs.outs[0].dirname.split("/")
for output in ctx.outputs.outs[1:]:
for i, (part1, part2) in enumerate(zip(base_dirname, output.dirname.split("/"))):
component_pairs = zip(base_dirname, output.dirname.split("/"))
base_dirname = base_dirname[:len(component_pairs)]
for i, (part1, part2) in enumerate(component_pairs):
if part1 != part2:
base_dirname = base_dirname[:i]
break
Expand Down

0 comments on commit ee776a7

Please sign in to comment.