Skip to content

Commit

Permalink
Add support for tvOS and watchOS.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Jul 30, 2024
1 parent 1f35fc0 commit ffd63e4
Show file tree
Hide file tree
Showing 33 changed files with 908 additions and 121 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ iOS/testbed/Python.xcframework/ios-*/Python.framework
iOS/testbed/iOSTestbed.xcodeproj/project.xcworkspace
iOS/testbed/iOSTestbed.xcodeproj/xcuserdata
iOS/testbed/iOSTestbed.xcodeproj/xcshareddata
tvOS/Frameworks
tvOS/Resources/Info.plist
watchOS/Frameworks
watchOS/Resources/Info.plist
Mac/Makefile
Mac/PythonLauncher/Info.plist
Mac/PythonLauncher/Makefile
Expand Down
75 changes: 71 additions & 4 deletions Lib/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,54 @@ def ios_ver(system="", release="", model="", is_simulator=False):
return IOSVersionInfo(system, release, model, is_simulator)


# A namedtuple for tvOS version information.
TVOSVersionInfo = collections.namedtuple(
"TVOSVersionInfo",
["system", "release", "model", "is_simulator"]
)


def tvos_ver(system="", release="", model="", is_simulator=False):
"""Get tvOS version information, and return it as a namedtuple:
(system, release, model, is_simulator).
If values can't be determined, they are set to values provided as
parameters.
"""
if sys.platform == "tvos":
# TODO: Can the iOS implementation be used here?
import _ios_support
result = _ios_support.get_platform_ios()
if result is not None:
return TVOSVersionInfo(*result)

return TVOSVersionInfo(system, release, model, is_simulator)


# A namedtuple for watchOS version information.
WatchOSVersionInfo = collections.namedtuple(
"WatchOSVersionInfo",
["system", "release", "model", "is_simulator"]
)


def watchos_ver(system="", release="", model="", is_simulator=False):
"""Get watchOS version information, and return it as a namedtuple:
(system, release, model, is_simulator).
If values can't be determined, they are set to values provided as
parameters.
"""
if sys.platform == "watchos":
# TODO: Can the iOS implementation be used here?
import _ios_support
result = _ios_support.get_platform_ios()
if result is not None:
return WatchOSVersionInfo(*result)

return WatchOSVersionInfo(system, release, model, is_simulator)


def _java_getprop(name, default):
"""This private helper is deprecated in 3.13 and will be removed in 3.15"""
from java.lang import System
Expand Down Expand Up @@ -884,14 +932,25 @@ def get_OpenVMS():
csid, cpu_number = vms_lib.getsyi('SYI$_CPU', 0)
return 'Alpha' if cpu_number >= 128 else 'VAX'

# On the iOS simulator, os.uname returns the architecture as uname.machine.
# On device it returns the model name for some reason; but there's only one
# CPU architecture for iOS devices, so we know the right answer.
# On the iOS/tvOS/watchOS simulator, os.uname returns the architecture as
# uname.machine. On device it returns the model name for some reason; but
# there's only one CPU architecture for devices, so we know the right
# answer.
def get_ios():
if sys.implementation._multiarch.endswith("simulator"):
return os.uname().machine
return 'arm64'

def get_tvos():
if sys.implementation._multiarch.endswith("simulator"):
return os.uname().machine
return 'arm64'

def get_watchos():
if sys.implementation._multiarch.endswith("simulator"):
return os.uname().machine
return 'arm64_32'

def from_subprocess():
"""
Fall back to `uname -p`
Expand Down Expand Up @@ -1051,9 +1110,13 @@ def uname():
system = 'Android'
release = android_ver().release

# Normalize responses on iOS
# Normalize responses on Apple mobile platforms
if sys.platform == 'ios':
system, release, _, _ = ios_ver()
if sys.platform == 'tvos':
system, release, _, _ = tvos_ver()
if sys.platform == 'watchos':
system, release, _, _ = watchos_ver()

vals = system, node, release, version, machine
# Replace 'unknown' values with the more portable ''
Expand Down Expand Up @@ -1343,6 +1406,10 @@ def platform(aliased=False, terse=False):
# macOS and iOS both report as a "Darwin" kernel
if sys.platform == "ios":
system, release, _, _ = ios_ver()
elif sys.platform == "tvos":
system, release, _, _ = tvos_ver()
elif sys.platform == "watchos":
system, release, _, _ = watchos_ver()
else:
macos_release = mac_ver()[0]
if macos_release:
Expand Down
8 changes: 8 additions & 0 deletions Lib/sysconfig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,14 @@ def get_platform():
release = get_config_vars().get("IPHONEOS_DEPLOYMENT_TARGET", "13.0")
osname = sys.platform
machine = sys.implementation._multiarch
elif sys.platform == "tvos":
release = get_config_vars().get("TVOS_DEPLOYMENT_TARGET", "9.0")
osname = sys.platform
machine = sys.implementation._multiarch
elif sys.platform == "watchos":
release = get_config_vars().get("WATCHOS_DEPLOYMENT_TARGET", "4.0")
osname = sys.platform
machine = sys.implementation._multiarch
else:
import _osx_support
osname, release, machine = _osx_support.get_platform_osx(
Expand Down
20 changes: 20 additions & 0 deletions Misc/platform_triplet.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,26 @@ PLATFORM_TRIPLET=arm64-iphonesimulator
# else
PLATFORM_TRIPLET=arm64-iphoneos
# endif
# elif defined(TARGET_OS_TV) && TARGET_OS_TV
# if defined(TARGET_OS_SIMULATOR) && TARGET_OS_SIMULATOR
# if __x86_64__
PLATFORM_TRIPLET=x86_64-appletvsimulator
# else
PLATFORM_TRIPLET=arm64-appletvsimulator
# endif
# else
PLATFORM_TRIPLET=arm64-appletvos
# endif
# elif defined(TARGET_OS_WATCH) && TARGET_OS_WATCH
# if defined(TARGET_OS_SIMULATOR) && TARGET_OS_SIMULATOR
# if __x86_64__
PLATFORM_TRIPLET=x86_64-watchsimulator
# else
PLATFORM_TRIPLET=arm64-watchsimulator
# endif
# else
PLATFORM_TRIPLET=arm64_32-watchos
# endif
// Older macOS SDKs do not define TARGET_OS_OSX
# elif !defined(TARGET_OS_OSX) || TARGET_OS_OSX
PLATFORM_TRIPLET=darwin
Expand Down
Loading

0 comments on commit ffd63e4

Please sign in to comment.