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
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module(
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "rules_python", version = "1.0.0")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "aspect_bazel_lib", version = "2.21.0")

# Only for development
bazel_dep(name = "platforms", version = "0.0.10", dev_dependency = True)
Expand Down
7 changes: 7 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,10 @@ http_archive(
load("@rules_cc//cc:repositories.bzl", "rules_cc_dependencies")

rules_cc_dependencies()

http_archive(
name = "aspect_bazel_lib",
sha256 = "6d636cfdecc7f5c1a5d82b9790fb5d5d5e8aa6ea8b53a71a75f1ba53c8d29f61",
strip_prefix = "bazel-lib-2.21.0",
url = "https://github.com/bazel-contrib/bazel-lib/releases/download/v2.21.0/bazel-lib-v2.21.0.tar.gz",
)
1 change: 1 addition & 0 deletions doc_build/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ genrule(
deps = [
":rules_pkg_lib",
"//toolchains/rpm:standard_package",
"@aspect_bazel_lib//lib:expand_make_vars",
],
)
for rule, src in ORDER
Expand Down
12 changes: 10 additions & 2 deletions pkg/private/tar/tar.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
"""Rules for making .tar files."""

load("@aspect_bazel_lib//lib:expand_make_vars.bzl", "expand_variables")
load("//pkg:providers.bzl", "PackageVariablesInfo")
load(
"//pkg/private:pkg_files.bzl",
Expand Down Expand Up @@ -104,7 +105,8 @@ def _pkg_tar_impl(ctx):
args.add("--mtime", "portable")
if ctx.attr.modes:
for key in ctx.attr.modes:
args.add("--modes", "%s=%s" % (_quote(key), ctx.attr.modes[key]))
expanded_key = expand_variables(ctx, key)
args.add("--modes", "%s=%s" % (_quote(expanded_key), ctx.attr.modes[key]))
if ctx.attr.owners:
for key in ctx.attr.owners:
args.add("--owners", "%s=%s" % (_quote(key), ctx.attr.owners[key]))
Expand All @@ -119,8 +121,14 @@ def _pkg_tar_impl(ctx):

# Now we begin processing the files.
path_mapper = None
expanded_remap_paths = {}
if ctx.attr.remap_paths:
path_mapper = lambda path: _remap(ctx.attr.remap_paths, path)
for prefix, replacement in ctx.attr.remap_paths.items():
expanded_prefix = expand_variables(ctx, prefix)
expanded_replacement = expand_variables(ctx, replacement)
expanded_remap_paths[expanded_prefix] = expanded_replacement

path_mapper = lambda path: _remap(expanded_remap_paths, path)

mapping_context = create_mapping_context_from_ctx(
ctx,
Expand Down
11 changes: 11 additions & 0 deletions tests/tar/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ py_test(
":test-pkg-tar-from-pkg-files-with-attributes",
":test-pkg-tar-with-attributes",
":test-remap-paths-tree-artifact",
":test-remap-paths-variables",
":test-respect-externally-defined-duplicates.tar",
":test-tar-compression_level--1",
":test-tar-compression_level-3",
Expand Down Expand Up @@ -628,6 +629,16 @@ pkg_tar(
},
)

pkg_tar(
name = "test-remap-paths-variables",
srcs = [
":tree_artifact_to_rename",
],
remap_paths = {
"/rename_me": "$(COMPILATION_MODE)",
},
)

#
# Test with symlinks
#
Expand Down
9 changes: 9 additions & 0 deletions tests/tar/pkg_tar_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,15 @@ def test_remap_paths_tree_artifact(self):
]
self.assertTarFileContent('test-remap-paths-tree-artifact.tar', content)

def test_remap_paths_make_variables(self):
content = [
{'name': 'fastbuild', 'isdir': True},
{'name': 'fastbuild/a'},
{'name': 'fastbuild/rename_me', 'isdir': True},
{'name': 'fastbuild/rename_me/should_not_rename'},
]
self.assertTarFileContent('test-remap-paths-variables.tar', content)

def test_externally_defined_duplicate_structure(self):
content = [
{'name': './a'},
Expand Down