Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ bzl_library(
":py_runtime_info_bzl",
":reexports_bzl",
":rule_builders_bzl",
":version_bzl",
"@bazel_skylib//lib:dicts",
"@bazel_skylib//lib:paths",
"@bazel_skylib//rules:common_settings",
Expand Down
5 changes: 3 additions & 2 deletions python/private/py_runtime_rule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ load(":flags.bzl", "FreeThreadedFlag")
load(":py_internal.bzl", "py_internal")
load(":py_runtime_info.bzl", "DEFAULT_STUB_SHEBANG", "PyRuntimeInfo")
load(":reexports.bzl", "BuiltinPyRuntimeInfo")
load(":version.bzl", "version")

_py_builtins = py_internal

Expand Down Expand Up @@ -387,11 +388,11 @@ def _is_singleton_depset(files):
return _py_builtins.is_singleton_depset(files)

def _interpreter_version_info_from_version_str(version_str):
parts = version_str.split(".")
v = version.parse(version_str)
version_info = {}
parts = list(v.release)
for key in ("major", "minor", "micro"):
if not parts:
break
version_info[key] = parts.pop(0)

return version_info
5 changes: 4 additions & 1 deletion python/private/version.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,8 @@ def parse(version_str, strict = False, _fail = fail):
# https://peps.python.org/pep-0440/#public-version-identifiers
return None

return struct(
# buildifier: disable=uninitialized
self = struct(
epoch = _parse_epoch(parts["epoch"], _fail),
release = _parse_release(parts["release"]),
pre = _parse_pre(parts["pre"]),
Expand All @@ -631,7 +632,9 @@ def parse(version_str, strict = False, _fail = fail):
local = _parse_local(parts["local"], _fail),
string = parts["norm"],
is_prefix = parts["is_prefix"],
key = lambda *a, **k: _version_key(self, *a, **k),
)
return self

def _parse_epoch(value, fail):
if not value:
Expand Down
19 changes: 10 additions & 9 deletions tests/base_rules/py_executable_base_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ load("//python/private:reexports.bzl", "BuiltinPyRuntimeInfo") # buildifier: di
load("//tests/base_rules:base_tests.bzl", "create_base_tests")
load("//tests/base_rules:util.bzl", "WINDOWS_ATTR", pt_util = "util")
load("//tests/support:py_executable_info_subject.bzl", "PyExecutableInfoSubject")
load("//tests/support:support.bzl", "CC_TOOLCHAIN", "CROSSTOOL_TOP", "LINUX_X86_64", "WINDOWS_X86_64")
load("//tests/support:support.bzl", "CC_TOOLCHAIN", "CROSSTOOL_TOP")
load("//tests/support/platforms:platforms.bzl", "platform_targets")

_tests = []

Expand All @@ -46,9 +47,9 @@ def _test_basic_windows(name, config):
"//command_line_option:build_python_zip": "true",
"//command_line_option:cpu": "windows_x86_64",
"//command_line_option:crosstool_top": CROSSTOOL_TOP,
"//command_line_option:extra_execution_platforms": [WINDOWS_X86_64],
"//command_line_option:extra_execution_platforms": [platform_targets.WINDOWS_X86_64],
"//command_line_option:extra_toolchains": [CC_TOOLCHAIN],
"//command_line_option:platforms": [WINDOWS_X86_64],
"//command_line_option:platforms": [platform_targets.WINDOWS_X86_64],
},
attr_values = {},
)
Expand Down Expand Up @@ -89,9 +90,9 @@ def _test_basic_zip(name, config):
"//command_line_option:build_python_zip": "true",
"//command_line_option:cpu": "linux_x86_64",
"//command_line_option:crosstool_top": CROSSTOOL_TOP,
"//command_line_option:extra_execution_platforms": [LINUX_X86_64],
"//command_line_option:extra_execution_platforms": [platform_targets.LINUX_X86_64],
"//command_line_option:extra_toolchains": [CC_TOOLCHAIN],
"//command_line_option:platforms": [LINUX_X86_64],
"//command_line_option:platforms": [platform_targets.LINUX_X86_64],
},
attr_values = {"target_compatible_with": target_compatible_with},
)
Expand Down Expand Up @@ -326,8 +327,8 @@ def _test_main_module_bootstrap_system_python(name, config):
target = name + "_subject",
config_settings = {
labels.BOOTSTRAP_IMPL: "system_python",
"//command_line_option:extra_execution_platforms": ["@bazel_tools//tools:host_platform", LINUX_X86_64],
"//command_line_option:platforms": [LINUX_X86_64],
"//command_line_option:extra_execution_platforms": ["@bazel_tools//tools:host_platform", platform_targets.LINUX_X86_64],
"//command_line_option:platforms": [platform_targets.LINUX_X86_64],
},
)

Expand All @@ -350,8 +351,8 @@ def _test_main_module_bootstrap_script(name, config):
target = name + "_subject",
config_settings = {
labels.BOOTSTRAP_IMPL: "script",
"//command_line_option:extra_execution_platforms": ["@bazel_tools//tools:host_platform", LINUX_X86_64],
"//command_line_option:platforms": [LINUX_X86_64],
"//command_line_option:extra_execution_platforms": ["@bazel_tools//tools:host_platform", platform_targets.LINUX_X86_64],
"//command_line_option:platforms": [platform_targets.LINUX_X86_64],
},
)

Expand Down
11 changes: 6 additions & 5 deletions tests/base_rules/py_test/py_test_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ load(
"create_executable_tests",
)
load("//tests/base_rules:util.bzl", pt_util = "util")
load("//tests/support:support.bzl", "CC_TOOLCHAIN", "CROSSTOOL_TOP", "LINUX_X86_64", "MAC_X86_64")
load("//tests/support:support.bzl", "CC_TOOLCHAIN", "CROSSTOOL_TOP")
load("//tests/support/platforms:platforms.bzl", "platform_targets")

# The Windows CI currently runs as root, which breaks when
# the analysis tests try to install (but not use, because
Expand Down Expand Up @@ -51,9 +52,9 @@ def _test_mac_requires_darwin_for_execution(name, config):
config_settings = {
"//command_line_option:cpu": "darwin_x86_64",
"//command_line_option:crosstool_top": CROSSTOOL_TOP,
"//command_line_option:extra_execution_platforms": [MAC_X86_64],
"//command_line_option:extra_execution_platforms": [platform_targets.MAC_X86_64],
"//command_line_option:extra_toolchains": [CC_TOOLCHAIN],
"//command_line_option:platforms": [MAC_X86_64],
"//command_line_option:platforms": [platform_targets.MAC_X86_64],
},
attr_values = _SKIP_WINDOWS,
)
Expand All @@ -78,9 +79,9 @@ def _test_non_mac_doesnt_require_darwin_for_execution(name, config):
config_settings = {
"//command_line_option:cpu": "k8",
"//command_line_option:crosstool_top": CROSSTOOL_TOP,
"//command_line_option:extra_execution_platforms": [LINUX_X86_64],
"//command_line_option:extra_execution_platforms": [platform_targets.LINUX_X86_64],
"//command_line_option:extra_toolchains": [CC_TOOLCHAIN],
"//command_line_option:platforms": [LINUX_X86_64],
"//command_line_option:platforms": [platform_targets.LINUX_X86_64],
},
attr_values = _SKIP_WINDOWS,
)
Expand Down
3 changes: 2 additions & 1 deletion tests/config_settings/transition/multi_version_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ load("//python:py_info.bzl", "PyInfo")
load("//python:py_test.bzl", "py_test")
load("//python/private:reexports.bzl", "BuiltinPyInfo") # buildifier: disable=bzl-visibility
load("//tests/support:support.bzl", "CC_TOOLCHAIN")
load("//tests/support/platforms:platforms.bzl", "platform_targets")

# NOTE @aignas 2024-06-04: we are using here something that is registered in the MODULE.Bazel
# and if you find tests failing, it could be because of the toolchain resolution issues here.
Expand Down Expand Up @@ -92,7 +93,7 @@ def _setup_py_binary_windows(name, *, impl, build_python_zip):
config_settings = {
"//command_line_option:build_python_zip": build_python_zip,
"//command_line_option:extra_toolchains": CC_TOOLCHAIN,
"//command_line_option:platforms": str(Label("//tests/support:windows_x86_64")),
"//command_line_option:platforms": str(platform_targets.WINDOWS_X86_64),
},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ load("//python:py_runtime.bzl", "py_runtime")
load("//python:py_runtime_pair.bzl", "py_runtime_pair")
load("//python/private:common_labels.bzl", "labels") # buildifier: disable=bzl-visibility
load("//python/private:toolchain_types.bzl", "EXEC_TOOLS_TOOLCHAIN_TYPE", "TARGET_TOOLCHAIN_TYPE") # buildifier: disable=bzl-visibility
load("//tests/support:support.bzl", "LINUX", "MAC")
load("//tests/support/platforms:platforms.bzl", "platform_targets")

_LookupInfo = provider() # buildifier: disable=provider-params

Expand Down Expand Up @@ -126,9 +126,9 @@ def _test_exec_matches_target_python_version(name):
target = name + "_subject",
impl = _test_exec_matches_target_python_version_impl,
config_settings = {
"//command_line_option:extra_execution_platforms": [str(MAC)],
"//command_line_option:extra_execution_platforms": [str(platform_targets.MAC)],
"//command_line_option:extra_toolchains": ["//tests/exec_toolchain_matching:all"],
"//command_line_option:platforms": [str(LINUX)],
"//command_line_option:platforms": [str(platform_targets.LINUX)],
labels.PYTHON_VERSION: "3.12",
},
)
Expand Down
2 changes: 1 addition & 1 deletion tests/pypi/config_settings/config_settings_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ _subject = rule(
)

_flag = struct(
platform = lambda x: ("//command_line_option:platforms", str(Label("//tests/support:" + x))),
platform = lambda x: ("//command_line_option:platforms", str(Label("//tests/support/platforms:" + x))),
pip_whl = lambda x: (str(Label("//python/config_settings:pip_whl")), str(x)),
pip_whl_glibc_version = lambda x: (str(Label("//python/config_settings:pip_whl_glibc_version")), str(x)),
pip_whl_muslc_version = lambda x: (str(Label("//python/config_settings:pip_whl_muslc_version")), str(x)),
Expand Down
69 changes: 0 additions & 69 deletions tests/support/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,82 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# ====================
# NOTE: You probably want to use the constants in test_platforms.bzl
# Otherwise, you'll probably have to manually call Label() on these targets
# to force them to resolve in the proper context.
# ====================

load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load(":sh_py_run_test.bzl", "current_build_settings")

package(
default_visibility = ["//:__subpackages__"],
)

platform(
name = "mac",
constraint_values = [
"@platforms//os:macos",
],
)

platform(
name = "linux",
constraint_values = [
"@platforms//os:linux",
],
)

platform(
name = "windows",
constraint_values = [
"@platforms//os:windows",
],
)

# Used when testing downloading of toolchains for a different platform

platform(
name = "linux_x86_64",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
],
)

platform(
name = "linux_aarch64",
constraint_values = [
"@platforms//cpu:aarch64",
"@platforms//os:linux",
],
)

platform(
name = "mac_x86_64",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:macos",
],
)

platform(
name = "windows_x86_64",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:windows",
],
)

platform(
name = "win_aarch64",
constraint_values = [
"@platforms//os:windows",
"@platforms//cpu:aarch64",
],
)

current_build_settings(
name = "current_build_settings",
)
Expand Down
77 changes: 77 additions & 0 deletions tests/support/platforms/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package(
default_visibility = ["//:__subpackages__"],
)

# ====================
# NOTE: You probably want to use the constants in test_platforms.bzl
# Otherwise, you'll probably have to manually call Label() on these targets
# to force them to resolve in the proper context.
# ====================
platform(
name = "mac",
constraint_values = [
"@platforms//os:macos",
],
)

platform(
name = "linux",
constraint_values = [
"@platforms//os:linux",
],
)

platform(
name = "windows",
constraint_values = [
"@platforms//os:windows",
],
)

platform(
name = "linux_x86_64",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
],
)

platform(
name = "linux_aarch64",
constraint_values = [
"@platforms//cpu:aarch64",
"@platforms//os:linux",
],
)

platform(
name = "mac_x86_64",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:macos",
],
)

platform(
name = "mac_aarch64",
constraint_values = [
"@platforms//cpu:aarch64",
"@platforms//os:macos",
],
)

platform(
name = "windows_x86_64",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:windows",
],
)

platform(
name = "windows_aarch64",
constraint_values = [
"@platforms//os:windows",
"@platforms//cpu:aarch64",
],
)
13 changes: 13 additions & 0 deletions tests/support/platforms/platforms.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Constants and utilities for platforms used for testing."""

platform_targets = struct(
LINUX = Label("//tests/support/platforms:linux"),
LINUX_AARCH64 = Label("//tests/support/platforms:linux_aarch64"),
LINUX_X86_64 = Label("//tests/support/platforms:linux_x86_64"),
MAC = Label("//tests/support/platforms:mac"),
MAC_X86_64 = Label("//tests/support/platforms:mac_x86_64"),
MAC_AARCH64 = Label("//tests/support/platforms:mac_aarch64"),
WINDOWS = Label("//tests/support/platforms:windows"),
WINDOWS_AARCH64 = Label("//tests/support/platforms:windows_aarch64"),
WINDOWS_X86_64 = Label("//tests/support/platforms:windows_x86_64"),
)
7 changes: 0 additions & 7 deletions tests/support/support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@

load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") # buildifier: disable=bzl-visibility

MAC = Label("//tests/support:mac")
MAC_X86_64 = Label("//tests/support:mac_x86_64")
LINUX = Label("//tests/support:linux")
LINUX_X86_64 = Label("//tests/support:linux_x86_64")
WINDOWS = Label("//tests/support:windows")
WINDOWS_X86_64 = Label("//tests/support:windows_x86_64")

PY_TOOLCHAINS = str(Label("//tests/support/py_toolchains:all"))
CC_TOOLCHAIN = str(Label("//tests/support/cc_toolchains:all"))
CROSSTOOL_TOP = Label("//tests/support/cc_toolchains:cc_toolchain_suite")
Expand Down
3 changes: 3 additions & 0 deletions tests/toolchains/multi_platform_resolution/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
load(":resolution_tests.bzl", "resolution_test_suite")

resolution_test_suite(name = "resolution_tests")
Loading