File tree Expand file tree Collapse file tree 6 files changed +39
-1
lines changed Expand file tree Collapse file tree 6 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 99bazel_dep (name = "rules_license" , version = "1.0.0" )
1010bazel_dep (name = "rules_python" , version = "1.0.0" )
1111bazel_dep (name = "bazel_skylib" , version = "1.7.1" )
12+ bazel_dep (name = "aspect_bazel_lib" , version = "2.14.0" )
1213
1314# Only for development
1415bazel_dep (name = "platforms" , version = "0.0.10" , dev_dependency = True )
Original file line number Diff line number Diff line change @@ -81,3 +81,12 @@ http_archive(
8181load ("@rules_cc//cc:repositories.bzl" , "rules_cc_dependencies" )
8282
8383rules_cc_dependencies ()
84+
85+ http_archive (
86+ name = "aspect_bazel_lib" ,
87+ sha256 = "40ba9d0f62deac87195723f0f891a9803a7b720d7b89206981ca5570ef9df15b" ,
88+ strip_prefix = "bazel-lib-2.14.0" ,
89+ url = "https://github.com/bazel-contrib/bazel-lib/releases/download/v2.14.0/bazel-lib-v2.14.0.tar.gz" ,
90+ )
91+
92+ aspect_bazel_lib_dependencies ()
Original file line number Diff line number Diff line change @@ -72,6 +72,7 @@ genrule(
7272 deps = [
7373 ":rules_pkg_lib" ,
7474 "//toolchains/rpm:standard_package" ,
75+ "@aspect_bazel_lib//lib:expand_make_vars" ,
7576 ],
7677 )
7778 for rule , src in ORDER
Original file line number Diff line number Diff line change 1313# limitations under the License.
1414"""Rules for making .tar files."""
1515
16+ load ("@aspect_bazel_lib//lib:expand_make_vars.bzl" , "expand_variables" )
1617load ("//pkg:providers.bzl" , "PackageVariablesInfo" )
1718load (
1819 "//pkg/private:pkg_files.bzl" ,
@@ -119,8 +120,14 @@ def _pkg_tar_impl(ctx):
119120
120121 # Now we begin processing the files.
121122 path_mapper = None
123+ expanded_remap_paths = {}
122124 if ctx .attr .remap_paths :
123- path_mapper = lambda path : _remap (ctx .attr .remap_paths , path )
125+ for prefix , replacement in ctx .attr .remap_paths .items ():
126+ expanded_prefix = expand_variables (ctx , prefix )
127+ expanded_replacement = expand_variables (ctx , replacement )
128+ expanded_remap_paths [expanded_prefix ] = expanded_replacement
129+
130+ path_mapper = lambda path : _remap (expanded_remap_paths , path )
124131
125132 mapping_context = create_mapping_context_from_ctx (
126133 ctx ,
Original file line number Diff line number Diff line change @@ -464,6 +464,7 @@ py_test(
464464 ":test-pkg-tar-from-pkg-files-with-attributes" ,
465465 ":test-pkg-tar-with-attributes" ,
466466 ":test-remap-paths-tree-artifact" ,
467+ ":test-remap-paths-variables" ,
467468 ":test-respect-externally-defined-duplicates.tar" ,
468469 ":test-tar-compression_level--1" ,
469470 ":test-tar-compression_level-3" ,
@@ -626,6 +627,16 @@ pkg_tar(
626627 },
627628)
628629
630+ pkg_tar (
631+ name = "test-remap-paths-variables" ,
632+ srcs = [
633+ ":tree_artifact_to_rename" ,
634+ ],
635+ remap_paths = {
636+ "/rename_me" : "$(COMPILATION_MODE)" ,
637+ },
638+ )
639+
629640#
630641# Test with symlinks
631642#
Original file line number Diff line number Diff line change @@ -285,6 +285,15 @@ def test_remap_paths_tree_artifact(self):
285285 ]
286286 self .assertTarFileContent ('test-remap-paths-tree-artifact.tar' , content )
287287
288+ def test_remap_paths_make_variables (self ):
289+ content = [
290+ {'name' : 'fastbuild' , 'isdir' : True },
291+ {'name' : 'fastbuild/a' },
292+ {'name' : 'fastbuild/rename_me' , 'isdir' : True },
293+ {'name' : 'fastbuild/rename_me/should_not_rename' },
294+ ]
295+ self .assertTarFileContent ('test-remap-paths-variables.tar' , content )
296+
288297 def test_externally_defined_duplicate_structure (self ):
289298 content = [
290299 {'name' : './a' },
You can’t perform that action at this time.
0 commit comments