Skip to content

Commit aa4e055

Browse files
committed
wip
1 parent a17aa55 commit aa4e055

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

python/private/pypi/pep508_env.bzl

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@
1616
"""
1717

1818
# See https://stackoverflow.com/questions/45125516/possible-values-for-uname-m
19-
_platform_machine_values = {
20-
"aarch64": "aarch64",
21-
"ppc": "ppc",
22-
"ppc64le": "ppc64le",
23-
"riscv64": "riscv64",
24-
"s390x": "s390x",
25-
"x86_32": "i386",
26-
"x86_64": "x86_64",
27-
}
2819
_platform_system_values = {
2920
"linux": "Linux",
3021
"osx": "Darwin",
@@ -62,6 +53,9 @@ def env(target_platform, *, extra = None):
6253
"platform_release": "",
6354
"platform_version": "",
6455
}
56+
if type(target_platform) == type(""):
57+
target_platform = platform_from_str(target_platform, python_version = "")
58+
6559
if target_platform.abi:
6660
minor_version, _, micro_version = target_platform.abi[3:].partition(".")
6761
micro_version = micro_version or "0"
@@ -72,10 +66,9 @@ def env(target_platform, *, extra = None):
7266
}
7367
if target_platform.os and target_platform.arch:
7468
os = target_platform.os
75-
arch = target_platform.arch
7669
env = env | {
7770
"os_name": _os_name_values.get(os, ""),
78-
"platform_machine": _platform_machine_values.get(arch, ""),
71+
"platform_machine": target_platform.arch,
7972
"platform_system": _platform_system_values.get(os, ""),
8073
"sys_platform": _sys_platform_values.get(os, ""),
8174
}

tests/pypi/pep508/evaluate_tests.bzl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"""Tests for construction of Python version matching config settings."""
1515

1616
load("@rules_testing//lib:test_suite.bzl", "test_suite")
17+
load("//python/private/pypi:pep508_env.bzl", pep508_env = "env") # buildifier: disable=bzl-visibility
1718
load("//python/private/pypi:pep508_evaluate.bzl", "evaluate", "tokenize") # buildifier: disable=bzl-visibility
1819

1920
_tests = []
@@ -234,6 +235,35 @@ def _evaluate_partial_only_extra(env):
234235

235236
_tests.append(_evaluate_partial_only_extra)
236237

238+
def _evaluate_with_aliases(env):
239+
# When
240+
for target_platform, tests in {
241+
# buildifier: @unsorted-dict-items
242+
"osx_aarch64": {
243+
"platform_system == 'Darwin' and platform_machine == 'arm64'": True,
244+
"platform_system == 'Darwin' and platform_machine == 'aarch64'": True,
245+
"platform_system == 'Darwin' and platform_machine == 'amd64'": False,
246+
},
247+
"osx_x86_64": {
248+
"platform_system == 'Darwin' and platform_machine == 'amd64'": True,
249+
"platform_system == 'Darwin' and platform_machine == 'x86_64'": True,
250+
},
251+
"osx_x86_32": {
252+
"platform_system == 'Darwin' and platform_machine == 'i386'": True,
253+
"platform_system == 'Darwin' and platform_machine == 'i686'": True,
254+
"platform_system == 'Darwin' and platform_machine == 'x86_32'": True,
255+
"platform_system == 'Darwin' and platform_machine == 'x86_64'": False,
256+
},
257+
}.items(): # buildifier: @unsorted-dict-items
258+
for input, want in tests.items():
259+
got = evaluate(
260+
input,
261+
env = pep508_env(target_platform),
262+
)
263+
env.expect.that_bool(got).equals(want)
264+
265+
_tests.append(_evaluate_with_aliases)
266+
237267
def evaluate_test_suite(name): # buildifier: disable=function-docstring
238268
test_suite(
239269
name = name,

0 commit comments

Comments
 (0)