Skip to content

Commit 5b390b9

Browse files
committed
Add support for tvOS and watchOS.
1 parent 77b2c93 commit 5b390b9

39 files changed

+920
-121
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ iOS/testbed/Python.xcframework/ios-*/Python.framework
8080
iOS/testbed/iOSTestbed.xcodeproj/project.xcworkspace
8181
iOS/testbed/iOSTestbed.xcodeproj/xcuserdata
8282
iOS/testbed/iOSTestbed.xcodeproj/xcshareddata
83+
tvOS/Frameworks
84+
tvOS/Resources/Info.plist
85+
watchOS/Frameworks
86+
watchOS/Resources/Info.plist
8387
Mac/Makefile
8488
Mac/PythonLauncher/Info.plist
8589
Mac/PythonLauncher/Makefile

Lib/platform.py

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,54 @@ def ios_ver(system="", release="", model="", is_simulator=False):
521521
return IOSVersionInfo(system, release, model, is_simulator)
522522

523523

524+
# A namedtuple for tvOS version information.
525+
TVOSVersionInfo = collections.namedtuple(
526+
"TVOSVersionInfo",
527+
["system", "release", "model", "is_simulator"]
528+
)
529+
530+
531+
def tvos_ver(system="", release="", model="", is_simulator=False):
532+
"""Get tvOS version information, and return it as a namedtuple:
533+
(system, release, model, is_simulator).
534+
535+
If values can't be determined, they are set to values provided as
536+
parameters.
537+
"""
538+
if sys.platform == "tvos":
539+
# TODO: Can the iOS implementation be used here?
540+
import _ios_support
541+
result = _ios_support.get_platform_ios()
542+
if result is not None:
543+
return TVOSVersionInfo(*result)
544+
545+
return TVOSVersionInfo(system, release, model, is_simulator)
546+
547+
548+
# A namedtuple for watchOS version information.
549+
WatchOSVersionInfo = collections.namedtuple(
550+
"WatchOSVersionInfo",
551+
["system", "release", "model", "is_simulator"]
552+
)
553+
554+
555+
def watchos_ver(system="", release="", model="", is_simulator=False):
556+
"""Get watchOS version information, and return it as a namedtuple:
557+
(system, release, model, is_simulator).
558+
559+
If values can't be determined, they are set to values provided as
560+
parameters.
561+
"""
562+
if sys.platform == "watchos":
563+
# TODO: Can the iOS implementation be used here?
564+
import _ios_support
565+
result = _ios_support.get_platform_ios()
566+
if result is not None:
567+
return WatchOSVersionInfo(*result)
568+
569+
return WatchOSVersionInfo(system, release, model, is_simulator)
570+
571+
524572
def _java_getprop(name, default):
525573
"""This private helper is deprecated in 3.13 and will be removed in 3.15"""
526574
from java.lang import System
@@ -884,14 +932,25 @@ def get_OpenVMS():
884932
csid, cpu_number = vms_lib.getsyi('SYI$_CPU', 0)
885933
return 'Alpha' if cpu_number >= 128 else 'VAX'
886934

887-
# On the iOS simulator, os.uname returns the architecture as uname.machine.
888-
# On device it returns the model name for some reason; but there's only one
889-
# CPU architecture for iOS devices, so we know the right answer.
935+
# On the iOS/tvOS/watchOS simulator, os.uname returns the architecture as
936+
# uname.machine. On device it returns the model name for some reason; but
937+
# there's only one CPU architecture for devices, so we know the right
938+
# answer.
890939
def get_ios():
891940
if sys.implementation._multiarch.endswith("simulator"):
892941
return os.uname().machine
893942
return 'arm64'
894943

944+
def get_tvos():
945+
if sys.implementation._multiarch.endswith("simulator"):
946+
return os.uname().machine
947+
return 'arm64'
948+
949+
def get_watchos():
950+
if sys.implementation._multiarch.endswith("simulator"):
951+
return os.uname().machine
952+
return 'arm64_32'
953+
895954
def from_subprocess():
896955
"""
897956
Fall back to `uname -p`
@@ -1051,9 +1110,13 @@ def uname():
10511110
system = 'Android'
10521111
release = android_ver().release
10531112

1054-
# Normalize responses on iOS
1113+
# Normalize responses on Apple mobile platforms
10551114
if sys.platform == 'ios':
10561115
system, release, _, _ = ios_ver()
1116+
if sys.platform == 'tvos':
1117+
system, release, _, _ = tvos_ver()
1118+
if sys.platform == 'watchos':
1119+
system, release, _, _ = watchos_ver()
10571120

10581121
vals = system, node, release, version, machine
10591122
# Replace 'unknown' values with the more portable ''
@@ -1343,6 +1406,10 @@ def platform(aliased=False, terse=False):
13431406
# macOS and iOS both report as a "Darwin" kernel
13441407
if sys.platform == "ios":
13451408
system, release, _, _ = ios_ver()
1409+
elif sys.platform == "tvos":
1410+
system, release, _, _ = tvos_ver()
1411+
elif sys.platform == "watchos":
1412+
system, release, _, _ = watchos_ver()
13461413
else:
13471414
macos_release = mac_ver()[0]
13481415
if macos_release:

Lib/sysconfig/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,14 @@ def get_platform():
719719
release = get_config_vars().get("IPHONEOS_DEPLOYMENT_TARGET", "13.0")
720720
osname = sys.platform
721721
machine = sys.implementation._multiarch
722+
elif sys.platform == "tvos":
723+
release = get_config_vars().get("TVOS_DEPLOYMENT_TARGET", "9.0")
724+
osname = sys.platform
725+
machine = sys.implementation._multiarch
726+
elif sys.platform == "watchos":
727+
release = get_config_vars().get("WATCHOS_DEPLOYMENT_TARGET", "4.0")
728+
osname = sys.platform
729+
machine = sys.implementation._multiarch
722730
else:
723731
import _osx_support
724732
osname, release, machine = _osx_support.get_platform_osx(

Misc/platform_triplet.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,26 @@ PLATFORM_TRIPLET=arm64-iphonesimulator
257257
# else
258258
PLATFORM_TRIPLET=arm64-iphoneos
259259
# endif
260+
# elif defined(TARGET_OS_TV) && TARGET_OS_TV
261+
# if defined(TARGET_OS_SIMULATOR) && TARGET_OS_SIMULATOR
262+
# if __x86_64__
263+
PLATFORM_TRIPLET=x86_64-appletvsimulator
264+
# else
265+
PLATFORM_TRIPLET=arm64-appletvsimulator
266+
# endif
267+
# else
268+
PLATFORM_TRIPLET=arm64-appletvos
269+
# endif
270+
# elif defined(TARGET_OS_WATCH) && TARGET_OS_WATCH
271+
# if defined(TARGET_OS_SIMULATOR) && TARGET_OS_SIMULATOR
272+
# if __x86_64__
273+
PLATFORM_TRIPLET=x86_64-watchsimulator
274+
# else
275+
PLATFORM_TRIPLET=arm64-watchsimulator
276+
# endif
277+
# else
278+
PLATFORM_TRIPLET=arm64_32-watchos
279+
# endif
260280
// Older macOS SDKs do not define TARGET_OS_OSX
261281
# elif !defined(TARGET_OS_OSX) || TARGET_OS_OSX
262282
PLATFORM_TRIPLET=darwin

0 commit comments

Comments
 (0)