Esempio n. 1
0
def GetLastSupportedIphoneSimType(os_version):
    """"Gets the last supported iPhone simulator type of the given OS version.

  Currently, the last supported iPhone simulator type is the last iPhone from
  the output of `xcrun simctl list devicetypes`.

  Args:
    os_version: string, OS version of the new simulator. The format is
      {major}.{minor}, such as 9.3, 10.2.

  Returns:
    a string, the last supported iPhone simulator type.

  Raises:
    ios_errors.SimError: when there is no supported iPhone simulator type.
  """
    supported_sim_types = GetSupportedSimDeviceTypes(ios_constants.OS.IOS)
    supported_sim_types.reverse()
    os_version_float = float(os_version)
    for sim_type in supported_sim_types:
        if sim_type.startswith('iPhone'):
            min_os_version_float = float(
                simtype_profile.SimTypeProfile(sim_type).min_os_version)
            if os_version_float >= min_os_version_float:
                return sim_type
    raise ios_errors.SimError('Can not find supported iPhone simulator type.')
Esempio n. 2
0
def _ValidateSimulatorTypeWithOsVersion(device_type, os_version):
    """Checks if the simulator type with the given os version is valid.

  Args:
    device_type: string, device type of the new simulator. The value corresponds
      to the output of `xcrun simctl list devicetypes`. E.g., iPhone 6, iPad
      Air, etc.
    os_version: string, OS version of the new simulator. The format is
      {major}.{minor}, such as 9.3, 10.2.

  Raises:
    ios_errors.IllegalArgumentError: when the given simulator device type can
        not match the given OS version.
  """
    os_version_float = float(os_version)
    sim_profile = simtype_profile.SimTypeProfile(device_type)
    min_os_version_float = float(sim_profile.min_os_version)
    if min_os_version_float > os_version_float:
        raise ios_errors.IllegalArgumentError(
            'The min OS version of %s is %s. But current OS version is %s' %
            (device_type, min_os_version_float, os_version))
    max_os_version_float = float(sim_profile.max_os_version)
    if max_os_version_float < os_version_float:
        raise ios_errors.IllegalArgumentError(
            'The max OS version of %s is %s. But current OS version is %s' %
            (device_type, max_os_version_float, os_version))
def GetLastSupportedSimOsVersion(os_type=ios_constants.OS.IOS,
                                 device_type=None):
    """Gets the last supported version of given arguments.

  If device_type is given, will return the last supported OS version of the
  device type. Otherwise, will return the last supported OS version of the
  OS type.

  Args:
    os_type: shared.ios_constants.OS, OS type of simulator, such as iOS,
      watchOS, tvOS.
    device_type: string, device type of the new simulator. The value corresponds
      to the output of `xcrun simctl list devicetypes`. E.g., iPhone 6, iPad
      Air, etc.

  Returns:
    a string, the last supported version.

  Raises:
    ios_errors.SimError: when there is no supported OS version of the given OS.
    ios_errors.IllegalArgumentError: when the supported OS version can not match
        the given simulator type.
  """
    supported_os_versions = GetSupportedSimOsVersions(os_type)
    if not supported_os_versions:
        raise ios_errors.SimError('Can not find supported OS version of %s.' %
                                  os_type)
    if not device_type:
        return supported_os_versions[-1]

    max_os_version = simtype_profile.SimTypeProfile(device_type).max_os_version
    # The supported os versions will be from latest to older after reverse().
    supported_os_versions.reverse()
    if not max_os_version:
        return supported_os_versions[0]

    for os_version in supported_os_versions:
        if float(os_version) <= max_os_version:
            return os_version
    raise ios_errors.IllegalArgumentError(
        'The supported OS version %s can not match simulator type %s. Because '
        'its max OS version is %s' %
        (supported_os_versions, device_type, max_os_version))