Skip to content

Commit edeb98c

Browse files
fix(bazel): symlink structure_test binary to .exe on Windows (upstream GoogleContainerTools#559)
On Windows the extensionless toolchain binary triggers an "Open With" dialog, so Bazel reports the structure test as PASSED while running zero tests (silent false-pass, issue GoogleContainerTools#557). Declare a .exe symlink and use it as test_bin before its consumers, gated on the existing is_windows computation (which is hoisted up and de-duplicated). Linux/macOS are unaffected. Co-authored-by: peakschris <77508021+peakschris@users.noreply.github.com> Upstream-PR: GoogleContainerTools#559
1 parent 50ebe70 commit edeb98c

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

bazel/container_structure_test.bzl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ def _structure_test_impl(ctx):
5151
test_bin = ctx.toolchains["@container_structure_test//bazel:structure_test_toolchain_type"].st_info.binary
5252
jq_bin = ctx.toolchains["@aspect_bazel_lib//lib:jq_toolchain_type"].jqinfo.bin
5353

54+
# On Windows the downloaded binary has no file extension. Windows requires
55+
# a .exe extension to recognise a file as directly executable — without it,
56+
# invoking the binary from a batch script triggers an "Open With" dialog
57+
# instead of running it. Symlink the binary to <name>.exe so the generated
58+
# launcher scripts can call it without this problem.
59+
is_windows = ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo])
60+
if is_windows and not test_bin.basename.endswith(".exe"):
61+
test_bin_exe = ctx.actions.declare_file(test_bin.basename + ".exe")
62+
ctx.actions.symlink(output = test_bin_exe, target_file = test_bin)
63+
test_bin = test_bin_exe
64+
5465
default_info = ctx.attr.image[DefaultInfo] if DefaultInfo in ctx.attr.image else None
5566
output_group_info = ctx.attr.image[OutputGroupInfo] if OutputGroupInfo in ctx.attr.image else None
5667
image = None
@@ -99,7 +110,6 @@ def _structure_test_impl(ctx):
99110
is_executable = True,
100111
)
101112

102-
is_windows = ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo])
103113
launcher = create_windows_native_launcher_script(ctx, bash_launcher) if is_windows else bash_launcher
104114
runfiles = ctx.runfiles(
105115
files = image_files + ctx.files.configs + [

0 commit comments

Comments
 (0)