Skip to content

Commit 4ae1f90

Browse files
authored
fix(windows): make remaining paths use rlocation (#361)
1 parent 8b6e083 commit 4ae1f90

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

bazel/container_structure_test.bzl

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,41 @@ _attrs = {
1919
"_windows_constraint": attr.label(default = "@platforms//os:windows"),
2020
}
2121

22-
CMD = """\
23-
#!/usr/bin/env bash
24-
25-
{BASH_RLOCATION_FUNCTION}
22+
CMD_HEAD = [
23+
"#!/usr/bin/env bash",
24+
"# This script generated by container_structure_test.bzl",
25+
BASH_RLOCATION_FUNCTION,
26+
]
2627

28+
CMD = """\
2729
readonly st=$(rlocation {st_path})
2830
readonly yq=$(rlocation {yq_path})
31+
readonly image=$(rlocation {image_path})
2932
3033
# When the image points to a folder, we can read the index.json file inside
31-
if [[ -d "{image_path}" ]]; then
32-
readonly DIGEST=$("$yq" eval '.manifests[0].digest | sub(":"; "-")' "{image_path}/index.json")
33-
exec "$st" test {fixed_args} --default-image-tag "registry.structure_test.oci.local/image:$DIGEST" $@
34+
if [[ -d "$image" ]]; then
35+
readonly DIGEST=$("$yq" eval '.manifests[0].digest | sub(":"; "-")' "$image/index.json")
36+
exec "$st" test --driver {driver} {fixed_args} --default-image-tag "registry.structure_test.oci.local/image:$DIGEST" $@
3437
else
35-
exec "$st" test {fixed_args} $@
38+
exec "$st" test --driver {driver} {fixed_args} $@
3639
fi
3740
"""
3841

3942
def _structure_test_impl(ctx):
40-
fixed_args = ["--driver", ctx.attr.driver]
43+
fixed_args = []
4144
test_bin = ctx.toolchains["@container_structure_test//bazel:structure_test_toolchain_type"].st_info.binary
4245
yq_bin = ctx.toolchains["@aspect_bazel_lib//lib:yq_toolchain_type"].yqinfo.bin
4346

44-
image_path = ctx.file.image.short_path
47+
image_path = to_rlocation_path(ctx, ctx.file.image)
48+
4549
# Prefer to use a tarball if we are given one, as it works with more 'driver' types.
4650
if image_path.endswith(".tar"):
47-
fixed_args.extend(["--image", image_path])
51+
fixed_args.extend(["--image", "$(rlocation %s)" % image_path])
4852
else:
4953
# https://github.com/GoogleContainerTools/container-structure-test/blob/5e347b66fcd06325e3caac75ef7dc999f1a9b614/cmd/container-structure-test/app/cmd/test.go#L110
5054
if ctx.attr.driver != "docker":
5155
fail("when the 'driver' attribute is not 'docker', then the image must be a .tar file")
52-
fixed_args.extend(["--image-from-oci-layout", image_path])
56+
fixed_args.extend(["--image-from-oci-layout", "$(rlocation %s)" % image_path])
5357
fixed_args.extend(["--default-image-tag", "registry.structure_test.oci.local/image:$DIGEST"])
5458

5559
for arg in ctx.files.configs:
@@ -58,10 +62,10 @@ def _structure_test_impl(ctx):
5862
bash_launcher = ctx.actions.declare_file("%s.sh" % ctx.label.name)
5963
ctx.actions.write(
6064
bash_launcher,
61-
content = CMD.format(
62-
BASH_RLOCATION_FUNCTION = BASH_RLOCATION_FUNCTION,
65+
content = "\n".join(CMD_HEAD) + CMD.format(
6366
st_path = to_rlocation_path(ctx, test_bin),
6467
yq_path = to_rlocation_path(ctx, yq_bin),
68+
driver = ctx.attr.driver,
6569
image_path = image_path,
6670
fixed_args = " ".join(fixed_args),
6771
),
@@ -70,11 +74,13 @@ def _structure_test_impl(ctx):
7074

7175
is_windows = ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo])
7276
launcher = create_windows_native_launcher_script(ctx, bash_launcher) if is_windows else bash_launcher
73-
7477
runfiles = ctx.runfiles(
7578
files = ctx.files.image + ctx.files.configs + [
76-
bash_launcher, test_bin, yq_bin
77-
]).merge(ctx.attr._runfiles.default_runfiles)
79+
bash_launcher,
80+
test_bin,
81+
yq_bin,
82+
],
83+
).merge(ctx.attr._runfiles.default_runfiles)
7884

7985
return DefaultInfo(runfiles = runfiles, executable = launcher)
8086

0 commit comments

Comments
 (0)