Skip to content

Commit 62dfd7d

Browse files
paulmonzooba
authored andcommitted
bpo-35920: Windows 10 ARM32 platform support (GH-11774)
1 parent 8c3ecc6 commit 62dfd7d

File tree

17 files changed

+134
-15
lines changed

17 files changed

+134
-15
lines changed

Doc/library/platform.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,21 @@ Windows Platform
216216
later (support for this was added in Python 2.6). It obviously
217217
only runs on Win32 compatible platforms.
218218

219+
.. function:: win32_edition()
220+
221+
Returns a string representing the current Windows edition. Possible
222+
values include but are not limited to ``'Enterprise'``, ``'IoTUAP'``,
223+
``'ServerStandard'``, and ``'nanoserver'``.
224+
225+
.. versionadded:: 3.8
226+
227+
.. function:: win32_is_iot()
228+
229+
Returns True if the windows edition returned by win32_edition is recognized
230+
as an IoT edition.
231+
232+
.. versionadded:: 3.8
233+
219234

220235
Mac OS Platform
221236
---------------

Lib/distutils/_msvccompiler.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,24 @@ def _find_vc2017():
8989

9090
return None, None
9191

92+
PLAT_SPEC_TO_RUNTIME = {
93+
'x86' : 'x86',
94+
'x86_amd64' : 'x64',
95+
'x86_arm' : 'arm',
96+
}
97+
9298
def _find_vcvarsall(plat_spec):
9399
_, best_dir = _find_vc2017()
94100
vcruntime = None
95-
vcruntime_plat = 'x64' if 'amd64' in plat_spec else 'x86'
101+
102+
if plat_spec in PLAT_SPEC_TO_RUNTIME:
103+
vcruntime_plat = PLAT_SPEC_TO_RUNTIME[plat_spec]
104+
else:
105+
vcruntime_plat = 'x64' if 'amd64' in plat_spec else 'x86'
106+
96107
if best_dir:
97108
vcredist = os.path.join(best_dir, "..", "..", "redist", "MSVC", "**",
98-
"Microsoft.VC141.CRT", "vcruntime140.dll")
109+
vcruntime_plat, "Microsoft.VC141.CRT", "vcruntime140.dll")
99110
try:
100111
import glob
101112
vcruntime = glob.glob(vcredist, recursive=True)[-1]
@@ -178,6 +189,7 @@ def _find_exe(exe, paths=None):
178189
PLAT_TO_VCVARS = {
179190
'win32' : 'x86',
180191
'win-amd64' : 'x86_amd64',
192+
'win-arm32' : 'x86_arm',
181193
}
182194

183195
# A set containing the DLLs that are guaranteed to be available for

Lib/distutils/spawn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ def _spawn_nt(cmd, search_path=1, verbose=0, dry_run=0):
8181
"command %r failed with exit status %d" % (cmd, rc))
8282

8383
if sys.platform == 'darwin':
84-
from distutils import sysconfig
8584
_cfg_target = None
8685
_cfg_target_split = None
8786

@@ -95,6 +94,7 @@ def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0):
9594
if sys.platform == 'darwin':
9695
global _cfg_target, _cfg_target_split
9796
if _cfg_target is None:
97+
from distutils import sysconfig
9898
_cfg_target = sysconfig.get_config_var(
9999
'MACOSX_DEPLOYMENT_TARGET') or ''
100100
if _cfg_target:

Lib/distutils/sysconfig.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import sys
1616

1717
from .errors import DistutilsPlatformError
18+
from .util import get_platform, get_host_platform
1819

1920
# These are needed in a couple of spots, so just compute them once.
2021
PREFIX = os.path.normpath(sys.prefix)

Lib/distutils/util.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from distutils import log
1616
from distutils.errors import DistutilsByteCompileError
1717

18-
def get_platform ():
18+
def get_host_platform():
1919
"""Return a string that identifies the current platform. This is used mainly to
2020
distinguish platform-specific build directories and platform-specific built
2121
distributions. Typically includes the OS name and version and the
@@ -38,6 +38,8 @@ def get_platform ():
3838
if os.name == 'nt':
3939
if 'amd64' in sys.version.lower():
4040
return 'win-amd64'
41+
if '(arm)' in sys.version.lower():
42+
return 'win-arm32'
4143
return sys.platform
4244

4345
# Set for cross builds explicitly
@@ -90,8 +92,16 @@ def get_platform ():
9092

9193
return "%s-%s-%s" % (osname, release, machine)
9294

93-
# get_platform ()
94-
95+
def get_platform():
96+
if os.name == 'nt':
97+
TARGET_TO_PLAT = {
98+
'x86' : 'win32',
99+
'x64' : 'win-amd64',
100+
'arm' : 'win-arm32',
101+
}
102+
return TARGET_TO_PLAT.get(os.environ.get('VSCMD_ARG_TGT_ARCH')) or get_host_platform()
103+
else:
104+
return get_host_platform()
95105

96106
def convert_path (pathname):
97107
"""Return 'pathname' as a name that will work on the native filesystem,

Lib/platform.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,27 @@ def _syscmd_ver(system='', release='', version='',
334334
(6, None): "post2012ServerR2",
335335
}
336336

337+
def win32_is_iot():
338+
return win32_edition() in ('IoTUAP', 'NanoServer', 'WindowsCoreHeadless', 'IoTEdgeOS')
339+
340+
def win32_edition():
341+
try:
342+
try:
343+
import winreg
344+
except ImportError:
345+
import _winreg as winreg
346+
except ImportError:
347+
pass
348+
else:
349+
try:
350+
cvkey = r'SOFTWARE\Microsoft\Windows NT\CurrentVersion'
351+
with winreg.OpenKeyEx(winreg.HKEY_LOCAL_MACHINE, cvkey) as key:
352+
return winreg.QueryValueEx(key, 'EditionId')[0]
353+
except OSError:
354+
pass
355+
356+
return None
357+
337358
def win32_ver(release='', version='', csd='', ptype=''):
338359
try:
339360
from sys import getwindowsversion

Lib/sysconfig.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,8 @@ def get_platform():
626626
if os.name == 'nt':
627627
if 'amd64' in sys.version.lower():
628628
return 'win-amd64'
629+
if '(arm)' in sys.version.lower():
630+
return 'win-arm32'
629631
return sys.platform
630632

631633
if os.name != "posix" or not hasattr(os, 'uname'):

Lib/test/test_codecs.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,26 @@ def check(input, expect):
2727
self.assertEqual(coder(input), (expect, len(input)))
2828
return check
2929

30+
# On small versions of Windows like Windows IoT or Windows Nano Server not all codepages are present
31+
def is_code_page_present(cp):
32+
from ctypes import POINTER, WINFUNCTYPE, windll, WinError, Structure, WinDLL
33+
from ctypes.wintypes import BOOL, UINT, BYTE, WCHAR, UINT, DWORD
34+
35+
MAX_LEADBYTES = 12 # 5 ranges, 2 bytes ea., 0 term.
36+
MAX_DEFAULTCHAR = 2 # single or double byte
37+
MAX_PATH = 260
38+
class CPINFOEXW(ctypes.Structure):
39+
_fields_ = [("MaxCharSize", UINT),
40+
("DefaultChar", BYTE*MAX_DEFAULTCHAR),
41+
("LeadByte", BYTE*MAX_LEADBYTES),
42+
("UnicodeDefaultChar", WCHAR),
43+
("CodePage", UINT),
44+
("CodePageName", WCHAR*MAX_PATH)]
45+
46+
prototype = WINFUNCTYPE(BOOL, UINT, DWORD, POINTER(CPINFOEXW))
47+
GetCPInfoEx = prototype(("GetCPInfoExW", WinDLL("kernel32")))
48+
info = CPINFOEXW()
49+
return GetCPInfoEx(cp, 0, info)
3050

3151
class Queue(object):
3252
"""
@@ -3078,9 +3098,19 @@ def test_multibyte_encoding(self):
30783098
def test_code_page_decode_flags(self):
30793099
# Issue #36312: For some code pages (e.g. UTF-7) flags for
30803100
# MultiByteToWideChar() must be set to 0.
3101+
if support.verbose:
3102+
sys.stdout.write('\n')
30813103
for cp in (50220, 50221, 50222, 50225, 50227, 50229,
30823104
*range(57002, 57011+1), 65000):
3083-
self.assertEqual(codecs.code_page_decode(cp, b'abc'), ('abc', 3))
3105+
# On small versions of Windows like Windows IoT
3106+
# not all codepages are present.
3107+
# A missing codepage causes an OSError exception
3108+
# so check for the codepage before decoding
3109+
if is_code_page_present(cp):
3110+
self.assertEqual(codecs.code_page_decode(cp, b'abc'), ('abc', 3), f'cp{cp}')
3111+
else:
3112+
if support.verbose:
3113+
print(f" skipping cp={cp}")
30843114
self.assertEqual(codecs.code_page_decode(42, b'abc'),
30853115
('\uf061\uf062\uf063', 3))
30863116

Lib/test/test_mimetypes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import unittest
77

88
from test import support
9+
from platform import win32_edition
910

1011
# Tell it we don't know about external files:
1112
mimetypes.knownfiles = []
@@ -116,6 +117,8 @@ def tearDown(self):
116117
mimetypes.types_map.clear()
117118
mimetypes.types_map.update(self.original_types_map)
118119

120+
@unittest.skipIf(win32_edition() in ('NanoServer', 'WindowsCoreHeadless', 'IoTEdgeOS'),
121+
"MIME types registry keys unavailable")
119122
def test_registry_parsing(self):
120123
# the original, minimum contents of the MIME database in the
121124
# Windows registry is undocumented AFAIK.

Lib/test/test_os.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import uuid
2929
import warnings
3030
from test import support
31+
from platform import win32_is_iot
3132

3233
try:
3334
import resource
@@ -2439,7 +2440,7 @@ def test_bad_fd(self):
24392440
# Return None when an fd doesn't actually exist.
24402441
self.assertIsNone(os.device_encoding(123456))
24412442

2442-
@unittest.skipUnless(os.isatty(0) and (sys.platform.startswith('win') or
2443+
@unittest.skipUnless(os.isatty(0) and not win32_is_iot() and (sys.platform.startswith('win') or
24432444
(hasattr(locale, 'nl_langinfo') and hasattr(locale, 'CODESET'))),
24442445
'test requires a tty and either Windows or nl_langinfo(CODESET)')
24452446
def test_device_encoding(self):

0 commit comments

Comments
 (0)