Skip to content

Commit 4b99ec3

Browse files
titusfortneraignas
andauthored
fix(rules): allow path separators in 'main' attribute (#3790)
Before we would fail when there are target separators present in the value of the `main` attribute. This PR adds a test and fixes this by declaring the bootstrap output as a sibling of the executable. Fixes #3789 --------- Co-authored-by: Ignas Anikevicius <240938+aignas@users.noreply.github.com>
1 parent dc9c1ab commit 4b99ec3

3 files changed

Lines changed: 34 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ END_UNRELEASED_TEMPLATE
8080
* (pypi) Fix `importlib.metadata.files` by ensuring `RECORD` is included in
8181
installed wheel targets, except when built from sdist
8282
([#3024](https://github.com/bazel-contrib/rules_python/issues/3024)).
83+
* (windows) Fix `py_test`/`py_binary` failure when the target name contains
84+
path separators; the bootstrap stub is now declared as a sibling of the
85+
`.exe` launcher
86+
([#3789](https://github.com/bazel-contrib/rules_python/issues/3789)).
8387

8488

8589
{#v0-0-0-added}

python/private/py_executable.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ WARNING: Target: {}
424424

425425
# On Windows, the main executable has an "exe" extension, so
426426
# here we re-use the un-extensioned name for the bootstrap output.
427-
bootstrap_output = ctx.actions.declare_file(base_executable_name)
427+
bootstrap_output = ctx.actions.declare_file(base_executable_name, sibling = executable)
428428

429429
# The launcher looks for the non-zip executable next to
430430
# itself, so add it to the default outputs.

tests/base_rules/py_executable_base_tests.bzl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,35 @@ def _test_py_runtime_info_provided_impl(env, target):
496496

497497
_tests.append(_test_py_runtime_info_provided)
498498

499+
def _test_windows_target_with_path_separators(name, config):
500+
rt_util.helper_target(
501+
config.rule,
502+
name = name + "/nested_subject",
503+
srcs = ["main.py"],
504+
main = "main.py",
505+
)
506+
analysis_test(
507+
name = name,
508+
impl = _test_windows_target_with_path_separators_impl,
509+
target = name + "/nested_subject",
510+
config_settings = {
511+
"//command_line_option:cpu": "windows_x86_64",
512+
"//command_line_option:crosstool_top": CROSSTOOL_TOP,
513+
"//command_line_option:extra_execution_platforms": [platform_targets.WINDOWS_X86_64],
514+
"//command_line_option:extra_toolchains": [CC_TOOLCHAIN],
515+
"//command_line_option:platforms": [platform_targets.WINDOWS_X86_64],
516+
},
517+
attr_values = {},
518+
)
519+
520+
def _test_windows_target_with_path_separators_impl(env, target):
521+
target = env.expect.that_target(target)
522+
target.runfiles().contains_predicate(matching.str_endswith(
523+
target.meta.format_str("/{name}"),
524+
))
525+
526+
_tests.append(_test_windows_target_with_path_separators)
527+
499528
# =====
500529
# You were gonna add a test at the end, weren't you?
501530
# Nope. Please keep them sorted; put it in its alphabetical location.

0 commit comments

Comments
 (0)