Skip to content

Commit 3f794c2

Browse files
committed
move select mappings to constants
1 parent be7e007 commit 3f794c2

File tree

1 file changed

+87
-80
lines changed

1 file changed

+87
-80
lines changed

python/private/pypi/env_marker_setting.bzl

Lines changed: 87 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
44
load("//python/private:toolchain_types.bzl", "TARGET_TOOLCHAIN_TYPE")
55
load(":pep508_evaluate.bzl", "evaluate")
66

7+
# todo: copied from pep508_env.bzl
8+
_os_name_select_map = {
9+
# The "java" value is documented, but with Jython defunct,
10+
# shouldn't occur in practice.
11+
# The osname value is technically a property of the runtime, not the
12+
# targetted OS at runtime, but the distinction shouldn't matter in
13+
# practice.
14+
"@platforms//os:windows": "nt",
15+
"//conditions:default": "posix",
16+
}
17+
718
# TODO @aignas 2025-04-29: this is copied from ./pep508_env.bzl
819
_platform_machine_aliases = {
920
# These pairs mean the same hardware, but different values may be used
@@ -14,88 +25,84 @@ _platform_machine_aliases = {
1425
"i686": "x86_32",
1526
}
1627

28+
# Taken from
29+
# https://docs.python.org/3/library/sys.html#sys.platform
30+
_sys_platform_select_map = {
31+
"@platforms//os:android": "android",
32+
"@platforms//os:emscripten": "emscripten",
33+
# NOTE, the below values here are from the time when the Python
34+
# interpreter is built and it is hard to know for sure, maybe this
35+
# should be something from the toolchain?
36+
"@platforms//os:freebsd": "freebsd8",
37+
"@platforms//os:ios": "ios",
38+
"@platforms//os:linux": "linux",
39+
"@platforms//os:openbsd": "openbsd6",
40+
"@platforms//os:osx": "darwin",
41+
"@platforms//os:wasi": "wasi",
42+
"@platforms//os:windows": "win32",
43+
"//conditions:default": "",
44+
}
45+
46+
# todo: copied from pep508_env.bzl
47+
# TODO: there are many cpus and unfortunately, it doesn't look like
48+
# the value is directly accessible to starlark. It might be possible to
49+
# get it via CcToolchain.cpu though.
50+
_platform_machine_select_map = {
51+
"@platforms//cpu:aarch32": "aarch32",
52+
"@platforms//cpu:aarch64": "aarch64",
53+
"@platforms//cpu:arm": "arm",
54+
"@platforms//cpu:arm64": "arm64",
55+
"@platforms//cpu:arm64_32": "arm64_32",
56+
"@platforms//cpu:arm64e": "arm64e",
57+
"@platforms//cpu:armv6-m": "armv6-m",
58+
"@platforms//cpu:armv7": "armv7",
59+
"@platforms//cpu:armv7-m": "armv7-m",
60+
"@platforms//cpu:armv7e-m": "armv7e-m",
61+
"@platforms//cpu:armv7e-mf": "armv7e-mf",
62+
"@platforms//cpu:armv7k": "armv7k",
63+
"@platforms//cpu:armv8-m": "armv8-m",
64+
"@platforms//cpu:cortex-r52": "cortex-r52",
65+
"@platforms//cpu:cortex-r82": "cortex-r82",
66+
"@platforms//cpu:i386": "i386",
67+
"@platforms//cpu:mips64": "mips64",
68+
"@platforms//cpu:ppc": "ppc",
69+
"@platforms//cpu:ppc32": "ppc32",
70+
"@platforms//cpu:ppc64le": "ppc64le",
71+
"@platforms//cpu:riscv32": "riscv32",
72+
"@platforms//cpu:riscv64": "riscv64",
73+
"@platforms//cpu:s390x": "s390x",
74+
"@platforms//cpu:wasm32": "wasm32",
75+
"@platforms//cpu:wasm64": "wasm64",
76+
"@platforms//cpu:x86_32": "x86_32",
77+
"@platforms//cpu:x86_64": "x86_64",
78+
# The value is empty string if it cannot be determined:
79+
# https://docs.python.org/3/library/platform.html#platform.machine
80+
"//conditions:default": "",
81+
}
82+
83+
# todo: copied from pep508_env.bzl
84+
_platform_system_select_map = {
85+
# See https://peps.python.org/pep-0738/#platform
86+
"@platforms//os:android": "Android",
87+
"@platforms//os:freebsd": "FreeBSD",
88+
# See https://peps.python.org/pep-0730/#platform
89+
"@platforms//os:ios": "iOS", # can also be iPadOS?
90+
"@platforms//os:linux": "Linux",
91+
"@platforms//os:netbsd": "NetBSD",
92+
"@platforms//os:openbsd": "OpenBSD",
93+
"@platforms//os:osx": "Darwin",
94+
"@platforms//os:windows": "Windows",
95+
# The value is empty string if it cannot be determined:
96+
# https://docs.python.org/3/library/platform.html#platform.machine
97+
"//conditions:default": "",
98+
}
99+
17100
def env_marker_setting(**kwargs):
18101
_env_marker_setting(
19-
# todo: copied from pep508_env.bzl
20-
os_name = select({
21-
# The "java" value is documented, but with Jython defunct,
22-
# shouldn't occur in practice.
23-
# The osname value is technically a property of the runtime, not the
24-
# targetted OS at runtime, but the distinction shouldn't matter in
25-
# practice.
26-
"@platforms//os:windows": "nt",
27-
"//conditions:default": "posix",
28-
}),
29-
# todo: copied from pep508_env.bzl
30-
sys_platform = select({
31-
# Taken from
32-
# https://docs.python.org/3/library/sys.html#sys.platform
33-
"@platforms//os:android": "android",
34-
"@platforms//os:emscripten": "emscripten",
35-
# NOTE, the below values here are from the time when the Python
36-
# interpreter is built and it is hard to know for sure, maybe this
37-
# should be something from the toolchain?
38-
"@platforms//os:freebsd": "freebsd8",
39-
"@platforms//os:ios": "ios",
40-
"@platforms//os:linux": "linux",
41-
"@platforms//os:openbsd": "openbsd6",
42-
"@platforms//os:osx": "darwin",
43-
"@platforms//os:wasi": "wasi",
44-
"@platforms//os:windows": "win32",
45-
"//conditions:default": "",
46-
}),
47-
# todo: copied from pep508_env.bzl
48-
# TODO: there are many cpus and unfortunately, it doesn't look like
49-
# the value is directly accessible to starlark. It might be possible to
50-
# get it via CcToolchain.cpu though.
51-
platform_machine = select({
52-
"@platforms//cpu:aarch32": "aarch32",
53-
"@platforms//cpu:aarch64": "aarch64",
54-
"@platforms//cpu:arm": "arm",
55-
"@platforms//cpu:arm64": "arm64",
56-
"@platforms//cpu:arm64_32": "arm64_32",
57-
"@platforms//cpu:arm64e": "arm64e",
58-
"@platforms//cpu:armv6-m": "armv6-m",
59-
"@platforms//cpu:armv7": "armv7",
60-
"@platforms//cpu:armv7-m": "armv7-m",
61-
"@platforms//cpu:armv7e-m": "armv7e-m",
62-
"@platforms//cpu:armv7e-mf": "armv7e-mf",
63-
"@platforms//cpu:armv7k": "armv7k",
64-
"@platforms//cpu:armv8-m": "armv8-m",
65-
"@platforms//cpu:cortex-r52": "cortex-r52",
66-
"@platforms//cpu:cortex-r82": "cortex-r82",
67-
"@platforms//cpu:i386": "i386",
68-
"@platforms//cpu:mips64": "mips64",
69-
"@platforms//cpu:ppc": "ppc",
70-
"@platforms//cpu:ppc32": "ppc32",
71-
"@platforms//cpu:ppc64le": "ppc64le",
72-
"@platforms//cpu:riscv32": "riscv32",
73-
"@platforms//cpu:riscv64": "riscv64",
74-
"@platforms//cpu:s390x": "s390x",
75-
"@platforms//cpu:wasm32": "wasm32",
76-
"@platforms//cpu:wasm64": "wasm64",
77-
"@platforms//cpu:x86_32": "x86_32",
78-
"@platforms//cpu:x86_64": "x86_64",
79-
# The value is empty string if it cannot be determined:
80-
# https://docs.python.org/3/library/platform.html#platform.machine
81-
"//conditions:default": "",
82-
}),
83-
# todo: copied from pep508_env.bzl
84-
platform_system = select({
85-
# See https://peps.python.org/pep-0738/#platform
86-
"@platforms//os:android": "Android",
87-
"@platforms//os:freebsd": "FreeBSD",
88-
# See https://peps.python.org/pep-0730/#platform
89-
"@platforms//os:ios": "iOS", # can also be iPadOS?
90-
"@platforms//os:linux": "Linux",
91-
"@platforms//os:netbsd": "NetBSD",
92-
"@platforms//os:openbsd": "OpenBSD",
93-
"@platforms//os:osx": "Darwin",
94-
"@platforms//os:windows": "Windows",
95-
# The value is empty string if it cannot be determined:
96-
# https://docs.python.org/3/library/platform.html#platform.machine
97-
"//conditions:default": "",
98-
}),
102+
os_name = select(_os_name_select_map),
103+
sys_platform = select(_sys_platform_select_map),
104+
platform_machine = select(_platform_machine_select_map),
105+
platform_system = select(_platform_system_select_map),
99106
**kwargs
100107
)
101108

0 commit comments

Comments
 (0)