Skip to content

Commit 078bdd8

Browse files
authored
[layer_tools/generate_args_for_image] Inject extra argument to the given callback (#2088)
When using a transition we need to give a callback function to compute a path specific for this transition. This information is not available from the context (ctx) and the given file. We need to have a way to inject this extra information. Example with an architecture specific transition: ```starlark def _to_arch_path(ctx, f, arch = None): """Returns the architecture specific path of the given file f.""" return paths.join( paths.dirname(f.short_path), arch, paths.basename(f.short_path), ) def _xxx_impl(ctx): ... # image is an attribute with a 1:2+ transition for image_target in ctx.attr.image: image = ... [ImageInfo].container_parts arch = ... ... img_args, img_inputs = generate_args_for_image( ctx, image, _to_arch_path, arch = arch, ) ... symlinks.update({ _to_arch_path(ctx, i, arch = arch): i for i in img_inputs }) ... runfiles = ctx.runfiles( files = ... symlinks = symlinks ) ```
1 parent 5436ff9 commit 078bdd8

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

container/layer_tools.bzl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,15 @@ def _file_path(ctx, val):
5959
"""
6060
return val.path
6161

62-
def generate_args_for_image(ctx, image, to_path = _file_path):
62+
def generate_args_for_image(ctx, image, to_path = _file_path, **kwargs):
6363
"""Generates arguments & inputs for the given image.
6464
6565
Args:
6666
ctx: The context.
6767
image: The image parts dictionary as returned by 'get_from_target'.
6868
to_path: A function to transform the string paths as they
6969
are added as arguments.
70+
**kwargs: Arguments to give to the `to_path` function.
7071
7172
Returns:
7273
The arguments to call the pusher, digester & flatenner with to load
@@ -77,7 +78,7 @@ def generate_args_for_image(ctx, image, to_path = _file_path):
7778
uncompressed_layers = image.get("unzipped_layer", [])
7879
digest_files = image.get("blobsum", [])
7980
diff_id_files = image.get("diff_id", [])
80-
args = ["--config={}".format(to_path(ctx, image["config"]))]
81+
args = ["--config={}".format(to_path(ctx, image["config"], **kwargs))]
8182
inputs = [image["config"]]
8283
inputs += compressed_layers
8384
inputs += uncompressed_layers
@@ -89,18 +90,18 @@ def generate_args_for_image(ctx, image, to_path = _file_path):
8990
diff_id_file = diff_id_files[i]
9091
args.append(
9192
"--layer={},{},{},{}".format(
92-
to_path(ctx, compressed_layer),
93-
to_path(ctx, uncompressed_layer),
94-
to_path(ctx, digest_file),
95-
to_path(ctx, diff_id_file),
93+
to_path(ctx, compressed_layer, **kwargs),
94+
to_path(ctx, uncompressed_layer, **kwargs),
95+
to_path(ctx, digest_file, **kwargs),
96+
to_path(ctx, diff_id_file, **kwargs),
9697
),
9798
)
9899
if image.get("legacy"):
99100
inputs.append(image["legacy"])
100-
args.append("--tarball={}".format(to_path(ctx, image["legacy"])))
101+
args.append("--tarball={}".format(to_path(ctx, image["legacy"], **kwargs)))
101102
if image["manifest"]:
102103
inputs.append(image["manifest"])
103-
args.append("--manifest={}".format(to_path(ctx, image["manifest"])))
104+
args.append("--manifest={}".format(to_path(ctx, image["manifest"], **kwargs)))
104105
return args, inputs
105106

106107
def get_from_target(ctx, name, attr_target):

0 commit comments

Comments
 (0)