예제 #1
0
  def __init__(self, name,
               main=None,
               basename=None,
               source=None,
               dependencies=None,
               excludes=None,
               deploy_excludes=None,
               configurations=None):

    JvmTarget.__init__(self,
                       name=name,
                       sources=[source] if source else None,
                       dependencies=dependencies,
                       excludes=excludes,
                       configurations=configurations)

    if main and not isinstance(main, Compatibility.string):
      raise TargetDefinitionException(self, 'main must be a fully qualified classname')

    if source and not isinstance(source, Compatibility.string):
      raise TargetDefinitionException(self, 'source must be a single relative file path')

    self.main = main
    self.basename = basename or name
    self.deploy_excludes = deploy_excludes or []
예제 #2
0
    def __init__(self, name, dependencies, exclusives=None):
        """name: The name of this module target, addressable via pants via the portion of the spec
        following the colon
    dependencies: one or more JarDependencies this JarLibrary bundles or Pants pointing to other
        JarLibraries or JavaTargets
    exclusives:   An optional map of exclusives tags. See CheckExclusives for details.
    """

        Target.__init__(self, name, exclusives=exclusives)

        if dependencies is None:
            raise TargetDefinitionException(
                self, "A dependencies list must be supplied even if empty.")

        self.add_labels('jars')
        self.dependencies = resolve(dependencies)
        self.dependency_addresses = set()
        for dependency in self.dependencies:
            if hasattr(dependency, 'address'):
                self.dependency_addresses.add(dependency.address)
            # If the dependency is one that supports exclusives, the JarLibrary's
            # exclusives should be added to it.
            if hasattr(dependency, 'declared_exclusives'):
                for k in self.declared_exclusives:
                    dependency.declared_exclusives[
                        k] |= self.declared_exclusives[k]
예제 #3
0
 def __init__(self, name, dependencies=(), sources=None, resources=None):
     InternalTarget.__init__(self, name, dependencies, None)
     TargetWithSources.__init__(self, name)
     if not sources:
         raise TargetDefinitionException(self, 'No sources specified')
     self.name = name
     self.sources = self._resolve_paths(self.target_base, sources)
     self.resources = self._resolve_paths(self.target_base,
                                          resources) if resources else []
예제 #4
0
    def __init__(self, name, binary, bundles, basename=None):
        InternalTarget.__init__(self, name, dependencies=[])

        if not binary:
            raise TargetDefinitionException(self, 'binary is required')

        binaries = list(filter(is_concrete, util.resolve(binary).resolve()))
        if len(binaries) != 1 or not isinstance(binaries[0], JvmBinary):
            raise TargetDefinitionException(
                self, 'must supply exactly 1 JvmBinary, got %s' % binary)
        self.binary = binaries[0]

        self._post_construct(self.update_dependencies, binaries)

        if not bundles:
            raise TargetDefinitionException(self, 'bundles must be specified')

        def is_resolvable(item):
            return hasattr(item, 'resolve')

        def is_bundle(bundle):
            return isinstance(bundle, Bundle)

        def resolve(item):
            return list(item.resolve()) if is_resolvable(item) else [None]

        if is_resolvable(bundles):
            bundles = resolve(bundles)

        self.bundles = []
        try:
            for item in iter(bundles):
                for bundle in resolve(item):
                    if not is_bundle(bundle):
                        raise TypeError()
                    self.bundles.append(bundle)
        except TypeError:
            raise TargetDefinitionException(
                self, 'bundles must be one or more Bundle objects, '
                'got %s' % bundles)

        self.basename = basename or name
예제 #5
0
 def update_dependencies(self, dependencies):
   if dependencies:
     for dependency in dependencies:
       if hasattr(dependency, 'address'):
         self.dependency_addresses.add(dependency.address)
       for resolved_dependency in dependency.resolve():
         if is_concrete(resolved_dependency) and not self.valid_dependency(resolved_dependency):
           raise TargetDefinitionException(self, 'Cannot add %s as a dependency of %s'
                                                 % (resolved_dependency, self))
         self.dependencies.add(resolved_dependency)
         if isinstance(resolved_dependency, InternalTarget):
           self.internal_dependencies.add(resolved_dependency)
         if hasattr(resolved_dependency, '_as_jar_dependencies'):
           self.jar_dependencies.update(resolved_dependency._as_jar_dependencies())
예제 #6
0
    def __init__(self,
                 name,
                 sources=None,
                 java_sources=None,
                 provides=None,
                 dependencies=None,
                 excludes=None,
                 resources=None,
                 exclusives=None):
        """
    :param string name: The name of this target, which combined with this
      build file defines the target :class:`twitter.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 java_sources:
      :class:`twitter.pants.targets.java_library.JavaLibrary` or list of
      JavaLibrary targets this library has a circular dependency on.
      Prefer using dependencies to express non-circular dependencies.
    :param Artifact provides:
      The :class:`twitter.pants.targets.artifact.Artifact`
      to publish that represents this target outside the repo.
    :param dependencies: List of :class:`twitter.pants.base.target.Target` instances
      this target depends on.
    :type dependencies: list of targets
    :param excludes: List of :class:`twitter.pants.targets.exclude.Exclude` instances
      to filter this target's transitive dependencies against.
    :param resources: An optional list of paths (DEPRECATED) or ``resources``
      targets containing resources that belong on this library's classpath.
    :param exclusives: An optional list of exclusives tags.
    """
        super(ScalaLibrary, self).__init__(name,
                                           sources,
                                           provides,
                                           dependencies,
                                           excludes,
                                           exclusives=exclusives)

        if (sources is None) and (resources is None):
            raise TargetDefinitionException(
                self, 'Must specify sources and/or resources.')

        self.resources = resources

        self._java_sources = []
        self._raw_java_sources = util.resolve(java_sources)

        self.add_labels('scala')
예제 #7
0
 def _excludes(self, dep):
     """
 A generator for Exclude objects that will recursively exclude all artifacts
 provided by the given dep.
 """
     if isinstance(dep, JarDependency):
         yield Exclude(dep.org, dep.name)
     elif isinstance(dep, ExportableJvmLibrary):
         if not dep.provides:
             raise TargetDefinitionException(
                 self,
                 'Targets passed to `overrides` must represent published artifacts. %s does not.'
                 % dep)
         yield Exclude(dep.provides.org, dep.provides.name)
     elif isinstance(dep, JarLibrary):
         for d in dep._pre_override_dependencies:
             for exclude in self._excludes(d):
                 yield exclude
예제 #8
0
    def __init__(self, name, dependencies):
        """name: The name of this module target, addressable via pants via the portion of the spec
        following the colon
    dependencies: one or more JarDependencies this JarLibrary bundles or Pants pointing to other
        JarLibraries or JavaTargets
    """

        Target.__init__(self, name)

        if dependencies is None:
            raise TargetDefinitionException(
                self, "A dependencies list must be supplied even if empty.")

        self.add_labels('jars')
        self.dependencies = resolve(dependencies)
        self.dependency_addresses = set()
        for dependency in self.dependencies:
            if hasattr(dependency, 'address'):
                self.dependency_addresses.add(dependency.address)
예제 #9
0
    def __init__(self,
                 name,
                 sources=None,
                 provides=None,
                 dependencies=None,
                 excludes=None,
                 resources=None,
                 exclusives=None):
        """
    :param string name: The name of this target, which combined with this
      build file defines the target :class:`twitter.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 Artifact provides:
      The :class:`twitter.pants.targets.artifact.Artifact`
      to publish that represents this target outside the repo.
    :param dependencies: List of :class:`twitter.pants.base.target.Target` instances
      this target depends on.
    :type dependencies: list of targets
    :param excludes: List of :class:`twitter.pants.targets.exclude.Exclude` instances
      to filter this target's transitive dependencies against.
    :param resources: An optional list of file paths (DEPRECATED) or
      ``resources`` targets (which in turn point to file paths). The paths
      indicate text file resources to place in this module's jar.
    :param exclusives: An optional map of exclusives tags. See CheckExclusives for details.
    """
        super(JavaLibrary, self).__init__(name,
                                          sources,
                                          provides,
                                          dependencies,
                                          excludes,
                                          exclusives=exclusives)

        if (sources is None) and (resources is None):
            raise TargetDefinitionException(
                self, 'Must specify sources and/or resources.')

        self.resources = resources
        self.add_labels('java')
예제 #10
0
    def __init__(self,
                 target_base,
                 name,
                 sources,
                 dependencies,
                 excludes=None,
                 buildflags=None,
                 is_meta=False):
        InternalTarget.__init__(self, name, dependencies, is_meta)
        TargetWithSources.__init__(self, target_base, name, is_meta)

        if sources is None or sources == []:
            raise TargetDefinitionException(self, 'No sources specified')

        self.sources = self._resolve_paths(self.target_base, sources)
        self.excludes = excludes
        self.buildflags = buildflags

        custom_antxml = '%s.xml' % self.name
        buildfile = self.address.buildfile.full_path
        custom_antxml_path = os.path.join(os.path.dirname(buildfile),
                                          custom_antxml)
        self.custom_antxml_path = custom_antxml_path if os.path.exists(
            custom_antxml_path) else None
예제 #11
0
    def __init__(self,
                 name,
                 source=None,
                 dependencies=None,
                 entry_point=None,
                 inherit_path=False,
                 zip_safe=True,
                 repositories=None,
                 indices=None,
                 ignore_errors=False,
                 allow_pypi=False,
                 platforms=(Platform.current(), ),
                 interpreters=(sys.version[:3], )):
        """
      name: target name

      source: the python source file that becomes this binary's __main__ [optional]
              if none specified, drops into an interpreter by default

      dependencies: a list of other PythonLibrary or Pants targets this binary depends upon

      entry_point: the default entry point for this binary (by default drops
                   into the entry point defined by @source)

      inherit_path: inherit the sys.path of the environment that this binary runs in

      zip_safe: whether or not this binary is safe to run in compacted (zip-file) form

      repositories: a list of repositories to query for dependencies

      indices: a list of indices to use for packages

      allow_pypi: whether or not this binary should be allowed to hit pypi for dependency
                  management

      platforms: the platforms to target when building this binary.  by
                 default the current platform.

      interpreters: the interpreter versions to target when building this binary.  by default the
                    current interpreter version (specify in the form: '2.6', '2.7', '3.2' etc.)
    """
        if source is None and dependencies is None:
            raise TargetDefinitionException(
                'ERROR: no source or dependencies declared for target %s' %
                name)
        if source and entry_point:
            raise TargetDefinitionException(
                'Can only declare an entry_point if no source binary is specified.'
            )
        if not isinstance(platforms, (list, tuple)) or not isinstance(
                interpreters, (list, tuple)):
            raise TargetDefinitionException(
                'platforms and interpreters must be lists or tuples.')

        self._entry_point = entry_point
        self._inherit_path = bool(inherit_path)
        self._zip_safe = bool(zip_safe)
        self._platforms = platforms
        self._interpreters = interpreters
        self._repositories = repositories or []
        self._indices = indices or []
        self._allow_pypi = bool(allow_pypi)
        self._ignore_errors = bool(ignore_errors)

        PythonTarget.__init__(self,
                              name, [] if source is None else [source],
                              dependencies=dependencies)
예제 #12
0
    def __init__(
            self,
            name,
            source=None,
            dependencies=None,
            entry_point=None,
            inherit_path=False,  # pex option
            zip_safe=True,  # pex option
            always_write_cache=False,  # pex option
            repositories=None,  # pex option
            indices=None,  # pex option
            ignore_errors=False,  # pex option
            allow_pypi=False,  # pex option
            platforms=(),
            compatibility=None,
            exclusives=None):
        """
    :param name: target name
    :param source: the python source file that becomes this binary's __main__.
      If None specified, drops into an interpreter by default.
    :param dependencies: List of :class:`twitter.pants.base.target.Target` instances
      this target depends on.
    :type dependencies: list of targets
    :param entry_point: the default entry point for this binary.  if None, drops into the entry
      point that is defined by source
    :param inherit_path: inherit the sys.path of the environment that this binary runs in
    :param zip_safe: whether or not this binary is safe to run in compacted (zip-file) form
    :param always_write_cache: whether or not the .deps cache of this PEX file should always
      be written to disk.
    :param repositories: a list of repositories to query for dependencies.
    :param indices: a list of indices to use for packages.
    :param platforms: extra platforms to target when building this binary.
    :param compatibility: either a string or list of strings that represents
      interpreter compatibility for this target, using the Requirement-style format,
      e.g. ``'CPython>=3', or just ['>=2.7','<3']`` for requirements agnostic to interpreter class.
    :param dict exclusives: An optional dict of exclusives tags. See CheckExclusives for details.
    """

        # TODO(John Sirois): Fixup TargetDefinitionException - it has awkward Target base-class
        # initialization requirements right now requiring this Target.__init__.
        Target.__init__(self, name, exclusives=exclusives)

        if source is None and entry_point is None:
            raise TargetDefinitionException(
                self,
                'A python binary target must specify either source or entry_point.'
            )

        PythonTarget.__init__(
            self,
            name,
            [] if source is None else [source],
            compatibility=compatibility,
            dependencies=dependencies,
            exclusives=exclusives,
        )

        if not isinstance(platforms, (list, tuple)) and not isinstance(
                platforms, Compatibility.string):
            raise TargetDefinitionException(
                self, 'platforms must be a list, tuple or string.')

        self._entry_point = entry_point
        self._inherit_path = bool(inherit_path)
        self._zip_safe = bool(zip_safe)
        self._always_write_cache = bool(always_write_cache)
        self._repositories = maybe_list(repositories or [])
        self._indices = maybe_list(indices or [])
        self._ignore_errors = bool(ignore_errors)
        self._platforms = tuple(maybe_list(platforms or []))

        if source and entry_point:
            entry_point_module = entry_point.split(':', 1)[0]
            source_entry_point = self._translate_to_entry_point(
                self.sources[0])
            if entry_point_module != source_entry_point:
                raise TargetDefinitionException(
                    self,
                    'Specified both source and entry_point but they do not agree: %s vs %s'
                    % (source_entry_point, entry_point_module))
예제 #13
0
    def __init__(self,
                 name,
                 sources,
                 provides=None,
                 dependencies=None,
                 excludes=None,
                 compiler=_COMPILER_DEFAULT,
                 language=_LANGUAGE_DEFAULT,
                 rpc_style=_RPC_STYLE_DEFAULT,
                 namespace_map=None,
                 exclusives=None):
        """
    :param string name: The name of this target, which combined with this
      build file defines the target :class:`twitter.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 Artifact provides:
      The :class:`twitter.pants.targets.artifact.Artifact`
      to publish that represents this target outside the repo.
    :param dependencies: List of :class:`twitter.pants.base.target.Target` instances
      this target depends on.
    :type dependencies: list of targets
    :param excludes: List of :class:`twitter.pants.targets.exclude.Exclude` instances
      to filter this target's transitive dependencies against.
    :param compiler: An optional compiler used to compile the thrift files.
    :param language: The language used to generate the output files.
      One of 'java' or 'scala' with a default of 'java'.
    :param rpc_style: An optional rpc style to generate service stubs with.
      One of 'sync', 'finagle' or 'ostrich' with a default of 'sync'.
    :param namespace_map: A dictionary of namespaces to remap (old: new)
    :param exclusives: An optional map of exclusives tags. See CheckExclusives for details.
    """

        # It's critical that provides is set 1st since _provides() is called elsewhere in the
        # constructor flow.
        self._provides = provides

        super(JavaThriftLibrary, self).__init__(name,
                                                sources,
                                                dependencies,
                                                excludes,
                                                exclusives=exclusives)

        self.add_labels('codegen')

        # 'java' shouldn't be here, but is currently required to prevent lots of chunking islands.
        # See comment in goal.py for details.
        self.add_labels('java')

        if dependencies:
            if not isinstance(dependencies, Iterable):
                raise TargetDefinitionException(
                    self,
                    'dependencies must be Iterable but was: %s' % dependencies)
            maybe_list(dependencies,
                       expected_type=(JarDependency, JavaThriftLibrary, Pants),
                       raise_type=partial(TargetDefinitionException, self))

        def check_value_for_arg(arg, value, values):
            if value not in values:
                raise TargetDefinitionException(
                    self, "%s may only be set to %s ('%s' not valid)" %
                    (arg, ', or '.join(map(repr, values)), value))
            return value

        # TODO(John Sirois): The defaults should be grabbed from the workspace config.

        # some gen BUILD files explicitly set this to None
        compiler = compiler or self._COMPILER_DEFAULT
        self.compiler = check_value_for_arg('compiler', compiler,
                                            self._COMPILERS)

        language = language or self._LANGUAGE_DEFAULT
        self.language = check_value_for_arg('language', language,
                                            self._LANGUAGES)

        rpc_style = rpc_style or self._RPC_STYLE_DEFAULT
        self.rpc_style = check_value_for_arg('rpc_style', rpc_style,
                                             self._RPC_STYLES)

        self.namespace_map = namespace_map
예제 #14
0
 def check_value_for_arg(arg, value, values):
     if value not in values:
         raise TargetDefinitionException(
             self, "%s may only be set to %s ('%s' not valid)" %
             (arg, ', or '.join(map(repr, values)), value))
     return value
예제 #15
0
    def __init__(self,
                 name,
                 sources=None,
                 dependencies=None,
                 excludes=None,
                 resources=None,
                 exclusives=None,
                 premain=None,
                 agent_class=None,
                 can_redefine=False,
                 can_retransform=False,
                 can_set_native_method_prefix=False):
        """
    :param string name: The name of this target, which combined with this
      build file defines the target :class:`twitter.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:`twitter.pants.base.target.Target` instances
      this target depends on.
    :type dependencies: list of targets
    :param excludes: List of :class:`twitter.pants.targets.exclude.Exclude` instances
      to filter this target's transitive dependencies against.
    :param resources: An optional list of file paths (DEPRECATED) or
      ``resources`` targets (which in turn point to file paths). The paths
      indicate text file resources to place in this module's jar.
    :param exclusives: An optional map of exclusives tags. See CheckExclusives for details.
    :param string premain: When an agent is specified at JVM launch time this attribute specifies
      the agent class. Exactly one of ``premain`` or ``agent_class`` must be specified.
    :param string agent_class: If an implementation supports a mechanism to start agents sometime
      after the VM has started then this attribute specifies the agent class. Exactly one of
      ``premain`` or ``agent_class`` must be specified.
    :param bool can_redefine: `True` if the ability to redefine classes is needed by this agent;
      `False` by default.
    :param bool can_retransform: `True` if the ability to retransform classes is needed by this
      agent; `False` by default.
    :param bool can_set_native_method_prefix: `True` if the ability to set he native method prefix
      is needed by this agent; `False` by default.
    """

        super(JavaAgent, self).__init__(name,
                                        sources,
                                        provides=None,
                                        dependencies=dependencies,
                                        excludes=excludes,
                                        resources=resources,
                                        exclusives=exclusives)

        if not premain or agent_class:
            raise TargetDefinitionException(
                self, "Must have at least one of 'premain' or 'agent_class' "
                "defined.")
        if premain and not isinstance(premain, Compatibility.string):
            raise TargetDefinitionException(
                self, 'The premain must be a fully qualified class name, '
                'given %s of type %s' % (premain, type(premain)))

        if agent_class and not isinstance(agent_class, Compatibility.string):
            raise TargetDefinitionException(
                self,
                'The agent_class must be a fully qualified class name, given '
                '%s of type %s' % (agent_class, type(agent_class)))

        self._premain = premain
        self._agent_class = agent_class
        self._can_redefine = can_redefine
        self._can_retransform = can_retransform
        self._can_set_native_method_prefix = can_set_native_method_prefix

        self.add_labels('java_agent')