Exemple #1
0
  def check_build_for_current_platform_only(self, targets):
    """
    Performs a check of whether the current target closure has native sources and if so, ensures
    that Pants is only targeting the current platform.

    :param tgts: a list of :class:`Target` objects.
    :return: a boolean value indicating whether the current target closure has native sources.
    :raises: :class:`pants.base.exceptions.IncompatiblePlatformsError`
    """
    # TODO(#5949): convert this to checking if the closure of python requirements has any
    # platform-specific packages (maybe find the platforms there too?).
    if not self._any_targets_have_native_sources(targets):
      return False

    platforms_with_sources = pex_build_util.targets_by_platform(targets, self._python_setup)
    platform_names = list(platforms_with_sources.keys())

    if not platform_names or platform_names == ['current']:
      return True

    bad_targets = set()
    for platform, targets in platforms_with_sources.items():
      if platform == 'current':
        continue
      bad_targets.update(targets)

    raise IncompatiblePlatformsError(dedent("""\
      Pants doesn't currently support cross-compiling native code.
      The following targets set platforms arguments other than ['current'], which is unsupported for this reason.
      Please either remove the platforms argument from these targets, or set them to exactly ['current'].
      Bad targets:
      {}
      """.format('\n'.join(sorted(target.address.reference() for target in bad_targets)))
    ))
Exemple #2
0
    def check_build_for_current_platform_only(self, targets):
        """
    Performs a check of whether the current target closure has native sources and if so, ensures
    that Pants is only targeting the current platform.

    :param tgts: a list of :class:`Target` objects.
    :return: a boolean value indicating whether the current target closure has native sources.
    :raises: :class:`pants.base.exceptions.IncompatiblePlatformsError`
    """
        if not self._any_targets_have_native_sources(targets):
            return False

        targets_by_platform = pex_build_util.targets_by_platform(
            targets, self._python_setup)
        platforms_with_sources = self._get_targets_by_declared_platform_with_placeholders(
            targets_by_platform)
        platform_names = list(platforms_with_sources.keys())

        if len(platform_names) < 1:
            raise self.PythonNativeCodeError(
                "Error: there should be at least one platform in the target closure, because "
                "we checked that there are native sources.")

        if platform_names == ['current']:
            return True

        raise IncompatiblePlatformsError(
            'The target set contains one or more targets that depend on '
            'native code. Please ensure that the platform arguments in all relevant targets and build '
            'options are compatible with the current platform. Found targets for platforms: {}'
            .format(str(platforms_with_sources)))
Exemple #3
0
def build_for_current_platform_only_check(tgts):
    """
  Performs a check of whether the current target closure has native sources and if so, ensures that
  Pants is only targeting the current platform.

  :param tgts: a list of :class:`Target` objects.
  :return: a boolean value indicating whether the current target closure has native sources.
  """
    if tgt_closure_has_native_sources(filter(is_local_python_dist, tgts)):
        platforms = tgt_closure_platforms(filter(is_python_binary, tgts))
        if len(platforms.keys()) > 1 or not 'current' in platforms.keys():
            raise IncompatiblePlatformsError(
                'The target set contains one or more targets that depend on '
                'native code. Please ensure that the platform arguments in all relevant targets and build '
                'options are compatible with the current platform. Found targets for platforms: {}'
                .format(str(platforms)))
        return True
    return False