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 9
9
bazel_dep (name = "rules_license" , version = "1.0.0" )
10
10
bazel_dep (name = "rules_python" , version = "1.0.0" )
11
11
bazel_dep (name = "bazel_skylib" , version = "1.7.1" )
12
+ bazel_dep (name = "aspect_bazel_lib" , version = "2.14.0" )
12
13
13
14
# Only for development
14
15
bazel_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(
81
81
load ("@rules_cc//cc:repositories.bzl" , "rules_cc_dependencies" )
82
82
83
83
rules_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(
72
72
deps = [
73
73
":rules_pkg_lib" ,
74
74
"//toolchains/rpm:standard_package" ,
75
+ "@aspect_bazel_lib//lib:expand_make_vars" ,
75
76
],
76
77
)
77
78
for rule , src in ORDER
Original file line number Diff line number Diff line change 13
13
# limitations under the License.
14
14
"""Rules for making .tar files."""
15
15
16
+ load ("@aspect_bazel_lib//lib:expand_make_vars.bzl" , "expand_variables" )
16
17
load ("//pkg:providers.bzl" , "PackageVariablesInfo" )
17
18
load (
18
19
"//pkg/private:pkg_files.bzl" ,
@@ -119,8 +120,14 @@ def _pkg_tar_impl(ctx):
119
120
120
121
# Now we begin processing the files.
121
122
path_mapper = None
123
+ expanded_remap_paths = {}
122
124
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 )
124
131
125
132
mapping_context = create_mapping_context_from_ctx (
126
133
ctx ,
Original file line number Diff line number Diff line change @@ -464,6 +464,7 @@ py_test(
464
464
":test-pkg-tar-from-pkg-files-with-attributes" ,
465
465
":test-pkg-tar-with-attributes" ,
466
466
":test-remap-paths-tree-artifact" ,
467
+ ":test-remap-paths-variables" ,
467
468
":test-respect-externally-defined-duplicates.tar" ,
468
469
":test-tar-compression_level--1" ,
469
470
":test-tar-compression_level-3" ,
@@ -626,6 +627,16 @@ pkg_tar(
626
627
},
627
628
)
628
629
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
+
629
640
#
630
641
# Test with symlinks
631
642
#
Original file line number Diff line number Diff line change @@ -285,6 +285,15 @@ def test_remap_paths_tree_artifact(self):
285
285
]
286
286
self .assertTarFileContent ('test-remap-paths-tree-artifact.tar' , content )
287
287
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
+
288
297
def test_externally_defined_duplicate_structure (self ):
289
298
content = [
290
299
{'name' : './a' },
You can’t perform that action at this time.
0 commit comments