Skip to content

Commit eff9d4a

Browse files
committed
Add support for tvOS and watchOS.
1 parent 29af6ce commit eff9d4a

39 files changed

+920
-121
lines changed

.gitignore

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

Lib/platform.py

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

530530

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

894-
# On the iOS simulator, os.uname returns the architecture as uname.machine.
895-
# On device it returns the model name for some reason; but there's only one
896-
# CPU architecture for iOS devices, so we know the right answer.
942+
# On the iOS/tvOS/watchOS simulator, os.uname returns the architecture as
943+
# uname.machine. On device it returns the model name for some reason; but
944+
# there's only one CPU architecture for devices, so we know the right
945+
# answer.
897946
def get_ios():
898947
if sys.implementation._multiarch.endswith("simulator"):
899948
return os.uname().machine
900949
return 'arm64'
901950

951+
def get_tvos():
952+
if sys.implementation._multiarch.endswith("simulator"):
953+
return os.uname().machine
954+
return 'arm64'
955+
956+
def get_watchos():
957+
if sys.implementation._multiarch.endswith("simulator"):
958+
return os.uname().machine
959+
return 'arm64_32'
960+
902961
def from_subprocess():
903962
"""
904963
Fall back to `uname -p`
@@ -1058,9 +1117,13 @@ def uname():
10581117
system = 'Android'
10591118
release = android_ver().release
10601119

1061-
# Normalize responses on iOS
1120+
# Normalize responses on Apple mobile platforms
10621121
if sys.platform == 'ios':
10631122
system, release, _, _ = ios_ver()
1123+
if sys.platform == 'tvos':
1124+
system, release, _, _ = tvos_ver()
1125+
if sys.platform == 'watchos':
1126+
system, release, _, _ = watchos_ver()
10641127

10651128
vals = system, node, release, version, machine
10661129
# Replace 'unknown' values with the more portable ''
@@ -1350,6 +1413,10 @@ def platform(aliased=False, terse=False):
13501413
# macOS and iOS both report as a "Darwin" kernel
13511414
if sys.platform == "ios":
13521415
system, release, _, _ = ios_ver()
1416+
elif sys.platform == "tvos":
1417+
system, release, _, _ = tvos_ver()
1418+
elif sys.platform == "watchos":
1419+
system, release, _, _ = watchos_ver()
13531420
else:
13541421
macos_release = mac_ver()[0]
13551422
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)