Esempio n. 1
0
def translate_host_platform(
    platform_constraint: PlatformConstraint,
    binary_util: BinaryUtil,
) -> HostPlatform:
    # This method attempts to provide a uname function to BinaryUtil.host_platform() so that the
    # download urls can be calculated. For platforms that are different than the current host, we try
    # to "spoof" the most appropriate value.
    if Platform.current == Platform.darwin:
        darwin_uname: Any = os.uname
        linux_uname: Any = lambda: ("linux", None, None, None, "x86_64")
    else:
        assert Platform.current == Platform.linux
        darwin_uname = lambda: (
            "darwin",
            None,
            get_closest_mac_host_platform_pair(),
            None,
            "x86_64",
        )
        linux_uname = os.uname

    return cast(
        HostPlatform,
        match(
            platform_constraint,
            {
                PlatformConstraint.none:
                lambda: HostPlatform.empty,
                PlatformConstraint.darwin:
                lambda: binary_util.host_platform(uname=darwin_uname()),
                PlatformConstraint.linux:
                lambda: binary_util.host_platform(uname=linux_uname()),
            },
        )(),
    )
Esempio n. 2
0
 def get_macos_version(darwin_version: Optional[str]) -> Optional[str]:
     host, version = get_closest_mac_host_platform_pair(
         darwin_version, platform_name_map=platform_name_map
     )
     if host is not None:
         self.assertEqual("mac", host)
     return version
Esempio n. 3
0
 def _host_platform(self):
     uname_result = self._uname_func()
     sysname, _, release, _, machine = uname_result
     os_id_key = sysname.lower()
     try:
         os_id_fun = self._ID_BY_OS[os_id_key]
         os_id_tuple = os_id_fun(release, machine)
     except KeyError:
         # TODO: test this!
         raise self.MissingMachineInfo(
             "Pants could not resolve binaries for the current host: platform '{}' was not recognized. "
             "Recognized platforms are: [{}].".format(
                 os_id_key, ', '.join(sorted(self._ID_BY_OS.keys()))))
     try:
         os_name, arch_or_version = self._path_by_id[os_id_tuple]
         return HostPlatform(os_name, arch_or_version)
     except KeyError:
         # In the case of MacOS, arch_or_version represents a version, and newer releases
         # can run binaries built for older releases.
         # It's better to allow that as a fallback, than for Pants to be broken on each new version
         # of MacOS until we get around to adding binaries for that new version, and modifying config
         # appropriately.
         # If some future version of MacOS cannot run binaries built for a previous
         # release, then we're no worse off than we were before (except that the error will be
         # less obvious), and we can fix it by pushing appropriate binaries and modifying
         # SUPPORTED_PLATFORM_NORMALIZED_NAMES appropriately.  This is only likely to happen with a
         # major architecture change, so we'll have plenty of warning.
         if os_id_tuple[0] == 'darwin':
             os_name, version = get_closest_mac_host_platform_pair(
                 os_id_tuple[1])
             if os_name is not None and version is not None:
                 return HostPlatform(os_name, version)
         # We fail early here because we need the host_platform to identify where to download
         # binaries to.
         raise self.MissingMachineInfo(
             "Pants could not resolve binaries for the current host. Update --binaries-path-by-id to "
             "find binaries for the current host platform {}.\n"
             "--binaries-path-by-id was: {}.".format(
                 os_id_tuple, self._path_by_id))
Esempio n. 4
0
 def _host_platform(self):
   uname_result = self._uname_func()
   sysname, _, release, _, machine = uname_result
   os_id_key = sysname.lower()
   try:
     os_id_fun = self._ID_BY_OS[os_id_key]
     os_id_tuple = os_id_fun(release, machine)
   except KeyError:
     # TODO: test this!
     raise self.MissingMachineInfo(
       "Pants could not resolve binaries for the current host: platform '{}' was not recognized. "
       "Recognized platforms are: [{}]."
       .format(os_id_key, ', '.join(sorted(self._ID_BY_OS.keys()))))
   try:
     os_name, arch_or_version = self._path_by_id[os_id_tuple]
     return HostPlatform(os_name, arch_or_version)
   except KeyError:
     # In the case of MacOS, arch_or_version represents a version, and newer releases
     # can run binaries built for older releases.
     # It's better to allow that as a fallback, than for Pants to be broken on each new version
     # of MacOS until we get around to adding binaries for that new version, and modifying config
     # appropriately.
     # If some future version of MacOS cannot run binaries built for a previous
     # release, then we're no worse off than we were before (except that the error will be
     # less obvious), and we can fix it by pushing appropriate binaries and modifying
     # SUPPORTED_PLATFORM_NORMALIZED_NAMES appropriately.  This is only likely to happen with a
     # major architecture change, so we'll have plenty of warning.
     if os_id_tuple[0] == 'darwin':
       os_name, version = get_closest_mac_host_platform_pair(os_id_tuple[1])
       if os_name is not None and version is not None:
         return HostPlatform(os_name, version)
     # We fail early here because we need the host_platform to identify where to download
     # binaries to.
     raise self.MissingMachineInfo(
       "Pants could not resolve binaries for the current host. Update --binaries-path-by-id to "
       "find binaries for the current host platform {}.\n"
       "--binaries-path-by-id was: {}."
       .format(os_id_tuple, self._path_by_id))
Esempio n. 5
0
 def get_macos_version(darwin_version):
     host, version = get_closest_mac_host_platform_pair(
         darwin_version, platform_name_map=platform_name_map)
     if host is not None:
         self.assertEqual('mac', host)
     return version
Esempio n. 6
0
 def get_macos_version(darwin_version):
   host, version = get_closest_mac_host_platform_pair(
     darwin_version, platform_name_map=platform_name_map)
   if host is not None:
     self.assertEqual('mac', host)
   return version