-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retrieve named_outputs keys with get_named_outs (#2808)
* Retrieve named_outputs keys with get_named_outs When working with named outputs it is convenient to be able to get the keys from the target after it was created. With this addition, one can do the following: ``` target = genrule( name = "target", outs = { "a": ["a"], "b": ["b"] }, ... ) target = get_named_outs(target) target2 = genrule( name = "target2", srcs = target.a, ... ) ``` This makes easy to re-export a target outs in a filegroup: ``` target = genrule( name = "target", outs = { "a": ["a"], "b": ["b"] }, ... ) fg = filegroup( name = "fg", srcs = get_named_outs(target) | { "c": [":another_rule"] } ) ``` * Output similar to get_outs
- Loading branch information
Showing
5 changed files
with
145 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
nonamedouts = genrule( | ||
name = "nonamedouts", | ||
outs = ["x"], | ||
cmd = """ | ||
echo 'x' > "$OUTS" | ||
""", | ||
) | ||
|
||
gr_getouts = genrule( | ||
name = "genrule_getouts", | ||
outs = { | ||
"wibble": ["wibble_file1"], | ||
"wobble": ["wobble_file1"], | ||
}, | ||
cmd = """ | ||
echo 'wibblewibblewibble' > "$OUTS_WIBBLE" | ||
echo 'wobblewobblewobble' > "$OUTS_WOBBLE" | ||
""", | ||
) | ||
|
||
fg_getouts = filegroup( | ||
name = "filegroup_getouts", | ||
srcs = { | ||
"wibble": [text_file(name = 'wibble_file2', content = 'wibblewibblewibble')], | ||
"wobble": [text_file(name = 'wobble_file2', content = 'wobblewobblewobble')], | ||
}, | ||
) | ||
|
||
def assert_dict(l1, l2): | ||
if l1 != l2: | ||
fail(f"{l1} != {l2}") | ||
|
||
assert_dict({}, get_named_outs(nonamedouts)) | ||
|
||
assert_dict({ | ||
"wibble": ["wibble_file1"], | ||
"wobble": ["wobble_file1"], | ||
}, get_named_outs(gr_getouts)) | ||
|
||
assert_dict({ | ||
"wibble": ["//test/get_outs:wibble_file2"], | ||
"wobble": ["//test/get_outs:wobble_file2"], | ||
}, get_named_outs(fg_getouts)) | ||
|
||
gr_subtargets = { k: [f'{gr_getouts}|{k}'] for k, _ in get_named_outs(gr_getouts).items() } | ||
fg_subtargets = { k: [f'{fg_getouts}|{k}'] for k, _ in get_named_outs(fg_getouts).items() } | ||
|
||
gentest( | ||
name = "get_outs_gr_wibble_test", | ||
data = gr_subtargets.wibble, | ||
labels = ["get_outs"], | ||
no_test_output = True, | ||
test_cmd = """ | ||
$TOOL "$DATA" "wibblewibblewibble" | ||
""", | ||
test_tools = ["//test/build_defs:content_checker"], | ||
) | ||
|
||
gentest( | ||
name = "get_outs_gr_wobble_test", | ||
data = gr_subtargets.wobble, | ||
labels = ["get_outs"], | ||
no_test_output = True, | ||
test_cmd = """ | ||
$TOOL "$DATA" "wobblewobblewobble" | ||
""", | ||
test_tools = ["//test/build_defs:content_checker"], | ||
) | ||
|
||
gentest( | ||
name = "get_outs_fg_wibble_test", | ||
data = fg_subtargets.wibble, | ||
labels = ["get_outs"], | ||
no_test_output = True, | ||
test_cmd = """ | ||
$TOOL "$DATA" "wibblewibblewibble" | ||
""", | ||
test_tools = ["//test/build_defs:content_checker"], | ||
) | ||
|
||
gentest( | ||
name = "get_outs_fg_wobble_test", | ||
data = fg_subtargets.wobble, | ||
labels = ["get_outs"], | ||
no_test_output = True, | ||
test_cmd = """ | ||
$TOOL "$DATA" "wobblewobblewobble" | ||
""", | ||
test_tools = ["//test/build_defs:content_checker"], | ||
) |