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" ,
@@ -104,7 +105,8 @@ def _pkg_tar_impl(ctx):
104105 args .add ("--mtime" , "portable" )
105106 if ctx .attr .modes :
106107 for key in ctx .attr .modes :
107- args .add ("--modes" , "%s=%s" % (_quote (key ), ctx .attr .modes [key ]))
108+ expanded_key = expand_variables (ctx , key )
109+ args .add ("--modes" , "%s=%s" % (_quote (expanded_key ), ctx .attr .modes [key ]))
108110 if ctx .attr .owners :
109111 for key in ctx .attr .owners :
110112 args .add ("--owners" , "%s=%s" % (_quote (key ), ctx .attr .owners [key ]))
@@ -119,8 +121,14 @@ def _pkg_tar_impl(ctx):
119121
120122 # Now we begin processing the files.
121123 path_mapper = None
124+ expanded_remap_paths = {}
122125 if ctx .attr .remap_paths :
123- path_mapper = lambda path : _remap (ctx .attr .remap_paths , path )
126+ for prefix , replacement in ctx .attr .remap_paths .items ():
127+ expanded_prefix = expand_variables (ctx , prefix )
128+ expanded_replacement = expand_variables (ctx , replacement )
129+ expanded_remap_paths [expanded_prefix ] = expanded_replacement
130+
131+ path_mapper = lambda path : _remap (expanded_remap_paths , path )
124132
125133 mapping_context = create_mapping_context_from_ctx (
126134 ctx ,
0 commit comments