Exemple #1
0
  def __init__(self,
               name,
               sources,
               dependencies,
               excludes=None,
               configurations=None,
               exclusives=None):
    """
    :param string name: The name of this target, which combined with this
      build file defines the target :class:`pants.base.address.Address`.
    :param sources: A list of filenames representing the source code
      this library is compiled from.
    :type sources: list of strings
    :param dependencies: List of :class:`pants.base.target.Target` instances
      this target depends on.
    :type dependencies: list of targets
    :param excludes: One or more :class:`pants.targets.exclude.Exclude` instances
      to filter this target's transitive dependencies against.
    :param configurations: One or more ivy configurations to resolve for this target.
      This parameter is not intended for general use.
    :type configurations: tuple of strings
    """
    InternalTarget.__init__(self, name, dependencies, exclusives=exclusives)
    TargetWithSources.__init__(self, name, sources)

    self.add_labels('jvm')
    for source in self.sources:
      rel_path = os.path.join(self.target_base, source)
      TargetWithSources.register_source(rel_path, self)
    self.excludes = maybe_list(excludes or [], Exclude)
    self.configurations = maybe_list(configurations or [])
Exemple #2
0
 def __init__(self, name, sources, exclusives=None):
   """
   :param string name: The name of this target, which combined with this
     build file defines the target :class:`pants.base.address.Address`.
   :param sources: A list of filenames representing the resources
     this library provides.
   """
   # TODO(John Sirois): XXX Review why this is an InternalTarget
   InternalTarget.__init__(self, name, dependencies=None, exclusives=exclusives)
   TargetWithSources.__init__(self, name, sources=sources, exclusives=exclusives)
Exemple #3
0
 def __init__(self, name, dependencies=None, num_sources=0, exclusives=None):
   with ParseContext.temp():
     InternalTarget.__init__(self, name, dependencies, exclusives=exclusives)
     TargetWithSources.__init__(self, name, exclusives=exclusives)
   self.num_sources = num_sources
   self.declared_exclusives = defaultdict(set)
   if exclusives is not None:
     for k in exclusives:
       self.declared_exclusives[k] = set([exclusives[k]])
   self.exclusives = None
Exemple #4
0
    def testSort(self):
        a = MockTarget("a", [])
        b = MockTarget("b", [a])
        c = MockTarget("c", [b])
        d = MockTarget("d", [c, a])
        e = MockTarget("e", [d])

        self.assertEquals(InternalTarget.sort_targets([a, b, c, d, e]), [e, d, c, b, a])
        self.assertEquals(InternalTarget.sort_targets([b, d, a, e, c]), [e, d, c, b, a])
        self.assertEquals(InternalTarget.sort_targets([e, d, c, b, a]), [e, d, c, b, a])
Exemple #5
0
    def test_detect_cycle_direct(self):
        a = MockTarget("a")

        # no cycles yet
        InternalTarget.sort_targets([a])
        a.update_dependencies([a])
        try:
            InternalTarget.sort_targets([a])
            self.fail("Expected a cycle to be detected")
        except InternalTarget.CycleException:
            # expected
            pass
Exemple #6
0
  def __init__(self, name, source, dependencies=None, resources=None, exclusives=None):
    """
    :param string name: The name of this target, which combined with this
      build file defines the target :class:`pants.base.address.Address`.
    :param source: Source of the page in markdown format.
    :param dependencies: List of :class:`pants.base.target.Target` instances
      this target depends on.
    :type dependencies: list of targets
    :param resources: An optional list of Resources objects.
    """
    InternalTarget.__init__(self, name, dependencies, exclusives=exclusives)
    TargetWithSources.__init__(self, name, sources=[source], exclusives=exclusives)

    self.resources = self._resolve_paths(resources) if resources else []
    self._wikis = {}
Exemple #7
0
  def exported_targets(self):
    candidates = set()
    if self.transitive:
      candidates.update(self.context.targets())
    else:
      candidates.update(self.context.target_roots)

      def get_synthetic(lang, target):
        mappings = self.context.products.get(lang).get(target)
        if mappings:
          for key, generated in mappings.items():
            for synthetic in generated:
              yield synthetic

      # Handle the case where a code gen target is in the listed roots and the thus the publishable
      # target is a synthetic twin generated by a code gen task upstream.
      for candidate in self.context.target_roots:
        candidates.update(get_synthetic('java', candidate))
        candidates.update(get_synthetic('scala', candidate))

    def exportable(tgt):
      return tgt in candidates and tgt.is_exported

    return OrderedSet(filter(exportable,
                             reversed(InternalTarget.sort_targets(filter(exportable, candidates)))))
 def _compute_transitive_deps_by_target(self):
   """Map from target to all the targets it depends on, transitively."""
   # Sort from least to most dependent.
   sorted_targets = reversed(InternalTarget.sort_targets(self._context.targets()))
   transitive_deps_by_target = defaultdict(set)
   # Iterate in dep order, to accumulate the transitive deps for each target.
   for target in sorted_targets:
     transitive_deps = set()
     if hasattr(target, 'dependencies'):
       for dep in target.dependencies:
         transitive_deps.update(transitive_deps_by_target.get(dep, []))
         transitive_deps.add(dep)
       transitive_deps_by_target[target] = transitive_deps
   return transitive_deps_by_target
Exemple #9
0
  def _create_chunks(self):
    def discriminator(tgt):
      for group_member in self._group_members:
        if group_member.predicate(tgt):
          return group_member.name
      return None

    # TODO(John Sirois): coalescing should be made available in another spot, InternalTarget is jvm
    # specific, and all we care is that the Targets have dependencies defined
    coalesced = InternalTarget.coalesce_targets(self._targets, discriminator)
    coalesced = list(reversed(coalesced))

    chunks = []
    flavor = None
    chunk_start = 0
    for chunk_num, target in enumerate(coalesced):
      target_flavor = discriminator(target)
      if target_flavor != flavor and chunk_num > chunk_start:
        chunks.append(OrderedSet(coalesced[chunk_start:chunk_num]))
        chunk_start = chunk_num
      flavor = target_flavor
    if chunk_start < len(coalesced):
      chunks.append(OrderedSet(coalesced[chunk_start:]))
    return chunks
Exemple #10
0
 def _order_target_list(self, targets):
   """Orders the targets topologically, from least to most dependent."""
   targets = set(t for t in targets if isinstance(t, Target))
   return filter(targets.__contains__, reversed(InternalTarget.sort_targets(targets)))