Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Rename targets to work with symbolic macros #1020

Merged
merged 2 commits into from
Jan 13, 2025
Merged
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
2 changes: 1 addition & 1 deletion lib/expand_template.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def expand_template(name, template, **kwargs):
**kwargs: other named parameters to `expand_template_rule`.
"""
if types.is_list(template):
write_target = "_{}.tmpl".format(name)
write_target = "{}_tmpl".format(name)
write_file(
name = write_target,
out = "{}.txt".format(write_target),
Expand Down
2 changes: 1 addition & 1 deletion lib/tar.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def tar(name, mtree = "auto", stamp = 0, **kwargs):
stamp: should mtree attribute be stamped
**kwargs: additional named parameters to pass to `tar_rule`
"""
mtree_target = "_{}.mtree".format(name)
mtree_target = "{}_mtree".format(name)
if mtree == "auto":
mtree_spec(
name = mtree_target,
Expand Down
32 changes: 16 additions & 16 deletions lib/testing.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ def assert_contains(name, actual, expected, size = "small", **kwargs):
**kwargs: additional named arguments for the resulting sh_test
"""

test_sh = "_{}_test.sh".format(name)
expected_file = "_{}_expected.txt".format(name)
test_sh = "{}_test.sh".format(name)
expected_file = "{}_expected.txt".format(name)

write_file(
name = "_%s_expected" % name,
name = "{}_expected".format(name),
out = expected_file,
content = [expected],
)

write_file(
name = "_" + name,
name = "{}_gen".format(name),
out = test_sh,
content = [
"#!/usr/bin/env bash",
Expand Down Expand Up @@ -61,22 +61,22 @@ def assert_outputs(name, actual, expected, **kwargs):
fail("expected should be a list of strings, not " + type(expected))

params_file(
name = "_actual_" + name,
name = name + "_actual",
data = [actual],
args = ["$(rootpaths {})".format(actual)],
out = "_{}_outputs.txt".format(name),
out = "{}_outputs.txt".format(name),
)

write_file(
name = "_expected_ " + name,
name = name + "_expected",
content = expected,
out = "_expected_{}.txt".format(name),
out = "{}_expected.txt".format(name),
)

diff_test(
name = name,
file1 = "_expected_ " + name,
file2 = "_actual_" + name,
file1 = name + "_expected",
file2 = name + "_actual",
**kwargs
)

Expand All @@ -97,8 +97,8 @@ def assert_json_matches(name, file1, file2, filter1 = ".", filter2 = ".", **kwar
filter2: a jq filter to apply to file2
**kwargs: additional named arguments for the resulting diff_test
"""
name1 = "_{}_jq1".format(name)
name2 = "_{}_jq2".format(name)
name1 = "{}_jq1".format(name)
name2 = "{}_jq2".format(name)
jq(
name = name1,
srcs = [file1],
Expand Down Expand Up @@ -154,8 +154,8 @@ def assert_archive_contains(name, archive, expected, type = None, **kwargs):
# -v: only print lines which don't match
grep = "grep -F -x -v -f $actual"

script_name = "_gen_assert_" + name
expected_name = "_expected_" + name
script_name = name + "_gen_assert"
expected_name = name + "_expected"

if types.is_list(expected):
write_file(
Expand Down Expand Up @@ -207,8 +207,8 @@ def assert_directory_contains(name, directory, expected, **kwargs):
# -v: only print lines which don't match
grep = "grep -F -x -v -f $actual"

script_name = "_gen_assert_" + name
expected_name = "_expected_" + name
script_name = name + "_gen_assert"
expected_name = name + "_expected"

if types.is_list(expected):
write_file(
Expand Down
18 changes: 9 additions & 9 deletions lib/tests/tar/asserts.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ load("//lib:diff_test.bzl", "diff_test")

# buildifier: disable=function-docstring
def assert_tar_listing(name, actual, expected):
actual_listing = "_{}_listing".format(name)
expected_listing = "_{}_expected".format(name)
actual_listing = "{}_listing".format(name)
expected_listing = "{}_expected".format(name)

native.genrule(
name = actual_listing,
srcs = [actual],
testonly = True,
outs = ["_{}.listing".format(name)],
outs = ["{}.listing".format(name)],
cmd = "$(BSDTAR_BIN) -tvf $(execpath {}) >$@".format(actual),
toolchains = ["@bsd_tar_toolchains//:resolved_toolchain"],
)

write_file(
name = expected_listing,
testonly = True,
out = "_{}.expected".format(name),
out = "{}.expected".format(name),
content = expected + [""],
newline = "unix",
)
Expand All @@ -34,11 +34,11 @@ def assert_tar_listing(name, actual, expected):

# buildifier: disable=function-docstring
def assert_unused_listing(name, actual, expected):
actual_listing = native.package_relative_label("_{}_actual_listing".format(name))
actual_shortnames = native.package_relative_label("_{}_actual_shortnames".format(name))
actual_shortnames_file = native.package_relative_label("_{}.actual_shortnames".format(name))
expected_listing = native.package_relative_label("_{}_expected".format(name))
expected_listing_file = native.package_relative_label("_{}.expected".format(name))
actual_listing = native.package_relative_label("{}_actual_listing".format(name))
actual_shortnames = native.package_relative_label("{}_actual_shortnames".format(name))
actual_shortnames_file = native.package_relative_label("{}.actual_shortnames".format(name))
expected_listing = native.package_relative_label("{}_expected".format(name))
expected_listing_file = native.package_relative_label("{}.expected".format(name))

native.filegroup(
name = actual_listing.name,
Expand Down
Loading