|
15 | 15 |
|
16 | 16 | load("@rules_testing//lib:analysis_test.bzl", "analysis_test")
|
17 | 17 | load("@rules_testing//lib:test_suite.bzl", "test_suite")
|
18 |
| -load("@rules_testing//lib:util.bzl", rt_util = "util") |
| 18 | +load("@rules_testing//lib:util.bzl", "TestingAspectInfo", rt_util = "util") |
19 | 19 | load("//python/config_settings:transition.bzl", py_binary_transitioned = "py_binary", py_test_transitioned = "py_test")
|
| 20 | +load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility |
20 | 21 |
|
21 | 22 | # NOTE @aignas 2024-06-04: we are using here something that is registered in the MODULE.Bazel
|
22 | 23 | # and if you find tests failing, it could be because of the toolchain resolution issues here.
|
@@ -68,6 +69,80 @@ def _test_py_binary_with_transition_impl(env, target):
|
68 | 69 |
|
69 | 70 | _tests.append(_test_py_binary_with_transition)
|
70 | 71 |
|
| 72 | +def _setup_py_binary_windows(name, *, impl, build_python_zip): |
| 73 | + rt_util.helper_target( |
| 74 | + py_binary_transitioned, |
| 75 | + name = name + "_subject", |
| 76 | + srcs = [name + "_subject.py"], |
| 77 | + python_version = _PYTHON_VERSION, |
| 78 | + ) |
| 79 | + |
| 80 | + analysis_test( |
| 81 | + name = name, |
| 82 | + target = name + "_subject", |
| 83 | + impl = impl, |
| 84 | + config_settings = { |
| 85 | + "//command_line_option:build_python_zip": build_python_zip, |
| 86 | + "//command_line_option:extra_toolchains": "//tests/cc:all", |
| 87 | + "//command_line_option:platforms": str(Label("//tests/support:windows_x86_64")), |
| 88 | + }, |
| 89 | + ) |
| 90 | + |
| 91 | +def _test_py_binary_windows_build_python_zip_false(name): |
| 92 | + _setup_py_binary_windows( |
| 93 | + name, |
| 94 | + build_python_zip = "false", |
| 95 | + impl = _test_py_binary_windows_build_python_zip_false_impl, |
| 96 | + ) |
| 97 | + |
| 98 | +def _test_py_binary_windows_build_python_zip_false_impl(env, target): |
| 99 | + default_outputs = env.expect.that_target(target).default_outputs() |
| 100 | + if IS_BAZEL_7_OR_HIGHER: |
| 101 | + # TODO: These outputs aren't correct. The outputs shouldn't |
| 102 | + # have the "_" prefix on them (those are coming from the underlying |
| 103 | + # wrapped binary). |
| 104 | + env.expect.that_target(target).default_outputs().contains_exactly([ |
| 105 | + "{package}/_{test_name}_subject", |
| 106 | + "{package}/_{test_name}_subject.exe", |
| 107 | + "{package}/{test_name}_subject", |
| 108 | + "{package}/{test_name}_subject.py", |
| 109 | + ]) |
| 110 | + else: |
| 111 | + inner_exe = target[TestingAspectInfo].attrs.target[DefaultInfo].files_to_run.executable |
| 112 | + default_outputs.contains_at_least([ |
| 113 | + inner_exe.short_path, |
| 114 | + ]) |
| 115 | + |
| 116 | +_tests.append(_test_py_binary_windows_build_python_zip_false) |
| 117 | + |
| 118 | +def _test_py_binary_windows_build_python_zip_true(name): |
| 119 | + _setup_py_binary_windows( |
| 120 | + name, |
| 121 | + build_python_zip = "true", |
| 122 | + impl = _test_py_binary_windows_build_python_zip_true_impl, |
| 123 | + ) |
| 124 | + |
| 125 | +def _test_py_binary_windows_build_python_zip_true_impl(env, target): |
| 126 | + default_outputs = env.expect.that_target(target).default_outputs() |
| 127 | + if IS_BAZEL_7_OR_HIGHER: |
| 128 | + # TODO: These outputs aren't correct. The outputs shouldn't |
| 129 | + # have the "_" prefix on them (those are coming from the underlying |
| 130 | + # wrapped binary). |
| 131 | + default_outputs.contains_exactly([ |
| 132 | + "{package}/_{test_name}_subject.exe", |
| 133 | + "{package}/_{test_name}_subject.zip", |
| 134 | + "{package}/{test_name}_subject.py", |
| 135 | + "{package}/{test_name}_subject.zip", |
| 136 | + ]) |
| 137 | + else: |
| 138 | + inner_exe = target[TestingAspectInfo].attrs.target[DefaultInfo].files_to_run.executable |
| 139 | + default_outputs.contains_at_least([ |
| 140 | + "{package}/{test_name}_subject.zip", |
| 141 | + inner_exe.short_path, |
| 142 | + ]) |
| 143 | + |
| 144 | +_tests.append(_test_py_binary_windows_build_python_zip_true) |
| 145 | + |
71 | 146 | def multi_version_test_suite(name):
|
72 | 147 | test_suite(
|
73 | 148 | name = name,
|
|
0 commit comments