fix(tar): propagate testonly attr to mtree_spec (#691)

This commit is contained in:
Alex Eagle 2023-12-13 15:21:02 -08:00 committed by GitHub
parent f65019be4e
commit 303779e9ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 0 deletions

View File

@ -99,6 +99,7 @@ bzl_library(
name = "tar",
srcs = ["tar.bzl"],
deps = [
"//lib:utils",
"//lib/private:tar",
"@bazel_skylib//lib:types",
"@bazel_skylib//rules:write_file",

View File

@ -51,6 +51,7 @@ TODO:
load("@bazel_skylib//lib:types.bzl", "types")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("//lib:utils.bzl", "propagate_common_rule_attributes")
load("//lib/private:tar.bzl", _tar = "tar", _tar_lib = "tar_lib")
mtree_spec = rule(
@ -102,6 +103,7 @@ def tar(name, mtree = "auto", **kwargs):
name = mtree_target,
srcs = kwargs["srcs"],
out = "{}.txt".format(mtree_target),
**propagate_common_rule_attributes(kwargs)
)
elif types.is_list(mtree):
write_file(
@ -110,6 +112,7 @@ def tar(name, mtree = "auto", **kwargs):
# Ensure there's a trailing newline, as bsdtar will ignore a last line without one
content = mtree + [""],
newline = "unix",
**propagate_common_rule_attributes(kwargs)
)
else:
mtree_target = mtree

View File

@ -223,6 +223,11 @@ copy_directory(
tar(
name = "dirs",
# Note, testonly should be propagated, proven by
# % bazel query --output=label_kind 'attr("testonly", 1,lib/tests/tar:all)'
# mtree_spec rule //lib/tests/tar:_dirs.mtree
# tar rule //lib/tests/tar:dirs
testonly = True,
srcs = glob(["srcdir/**"]) + [
"treeartifact",
],

View File

@ -11,6 +11,7 @@ def assert_tar_listing(name, actual, expected):
native.genrule(
name = actual_listing,
srcs = [actual],
testonly = True,
outs = ["_{}.listing".format(name)],
cmd = "$(BSDTAR_BIN) -tvf $(execpath {}) >$@".format(actual),
toolchains = ["@bsd_tar_toolchains//:resolved_toolchain"],
@ -18,6 +19,7 @@ def assert_tar_listing(name, actual, expected):
write_file(
name = expected_listing,
testonly = True,
out = "_{}.expected".format(name),
content = expected + [""],
newline = "unix",