Exemple #1
0
 def __init__(self, sources, address=None, exports=None, **kwargs):
   payload = Payload()
   payload.add_field('sources', self.create_sources_field(sources,
                                                          sources_rel_path=address.spec_path,
                                                          key_arg='sources'))
   payload.add_field('exports', PrimitivesSetField(exports or []))
   super(SourcesTarget, self).__init__(address=address, payload=payload, **kwargs)
Exemple #2
0
    def test_set_of_primitives_field(self):
        # Should preserve `None` values.
        self.assertEqual(PrimitivesSetField(None).value, None)

        def sopf(underlying):
            return PrimitivesSetField(underlying).fingerprint()

        self.assertEqual(
            sopf({'one', 'two'}),
            sopf({'two', 'one'}),
        )
        self.assertEqual(
            sopf(['one', 'two']),
            sopf(['two', 'one']),
        )
        self.assertEqual(
            sopf(None),
            sopf(None),
        )
        self.assertNotEqual(
            sopf(None),
            sopf(['one']),
        )
        self.assertNotEqual(
            sopf(None),
            sopf([]),
        )
Exemple #3
0
    def test_set_of_primitives_field(self):
        # Should preserve `None` values.
        self.assertEqual(PrimitivesSetField(None).value, None)

        def sopf(underlying):
            return PrimitivesSetField(underlying).fingerprint()

        self.assertEqual(
            sopf({"one", "two"}),
            sopf({"two", "one"}),
        )
        self.assertEqual(
            sopf(["one", "two"]),
            sopf(["two", "one"]),
        )
        self.assertEqual(
            sopf(None),
            sopf(None),
        )
        self.assertNotEqual(
            sopf(None),
            sopf(["one"]),
        )
        self.assertNotEqual(
            sopf(None),
            sopf([]),
        )
Exemple #4
0
 def __init__(self, address=None, payload=None, **kwargs):
     self.address = address  # Set in case a TargetDefinitionException is thrown early
     payload = payload or Payload()
     payload.add_fields(
         {"platform": PrimitiveField(None), "compiler_option_sets": PrimitivesSetField(None)}
     )
     super().__init__(address=address, payload=payload, **kwargs)
Exemple #5
0
 def __init__(self, sources, address=None, exports=None, **kwargs):
     payload = Payload()
     payload.add_field(
         "sources",
         self.create_sources_field(
             sources, sources_rel_path=address.spec_path, key_arg="sources"
         ),
     )
     payload.add_field("exports", PrimitivesSetField(exports or []))
     super().__init__(address=address, payload=payload, **kwargs)
Exemple #6
0
    def __init__(self,
                 address,
                 payload=None,
                 sources=None,
                 ctypes_native_library=None,
                 strict_deps=None,
                 fatal_warnings=None,
                 compiler_option_sets=None,
                 toolchain_variant=None,
                 **kwargs):

        if not payload:
            payload = Payload()
        sources_field = self.create_sources_field(sources,
                                                  address.spec_path,
                                                  key_arg="sources")
        payload.add_fields({
            "sources":
            sources_field,
            "ctypes_native_library":
            ctypes_native_library,
            "strict_deps":
            PrimitiveField(strict_deps),
            "fatal_warnings":
            PrimitiveField(fatal_warnings),
            "compiler_option_sets":
            PrimitivesSetField(compiler_option_sets),
            "toolchain_variant":
            PrimitiveField(toolchain_variant),
        })

        if ctypes_native_library and not isinstance(ctypes_native_library,
                                                    NativeArtifact):
            raise TargetDefinitionException(
                "Target must provide a valid pants '{}' object. Received an object with type '{}' "
                "and value: {}.".format(
                    NativeArtifact.alias(),
                    type(ctypes_native_library).__name__,
                    ctypes_native_library,
                ))

        super().__init__(address=address, payload=payload, **kwargs)
Exemple #7
0
    def __init__(self,
                 address=None,
                 payload=None,
                 sources=None,
                 protoc_plugins=None,
                 **kwargs):
        """
    :param sources: protobuf source files
    :type sources: :class:`pants.source.wrapped_globs.FilesetWithSpec` or list of strings. Paths
                   are relative to the BUILD file's directory.
    """
        payload = payload or Payload()
        payload.add_field(
            'sources',
            self.create_sources_field(sources,
                                      address.spec_path,
                                      key_arg='sources'))
        payload.add_field('protoc_plugins',
                          PrimitivesSetField(protoc_plugins or []))

        super().__init__(payload=payload, address=address, **kwargs)
Exemple #8
0
 def __init__(self, address, payload=None, sources=None, include_relpath=None, lib_relpath=None,
              native_lib_names=None, **kwargs):
   """
   :param sources: Files owned by this target.
   :param str include_relpath: The path where C/C++ headers are located, relative to this target's
                               directory. Libraries depending on this target will be able to
                               #include files relative to this directory.
   :param str lib_relpath: The path where native libraries are located, relative to this target's
                           directory.
   :param list native_lib_names: Strings containing the libraries to add to the linker command
                                 line. These libraries become `-l<name>` arguments, so they must
                                 exist and be named `lib<name>.so` (or `lib<name>.dylib` depending
                                 on the platform) or the linker will exit with an error.
   """
   if not payload:
     payload = Payload()
   payload.add_fields({
     'sources': self.create_sources_field(sources, address.spec_path, key_arg='sources'),
     'include_relpath': PrimitiveField(include_relpath),
     'lib_relpath': PrimitiveField(lib_relpath),
     'native_lib_names': PrimitivesSetField(native_lib_names),
   })
   super().__init__(address=address, payload=payload, **kwargs)
Exemple #9
0
 def sopf(underlying):
     return PrimitivesSetField(underlying).fingerprint()
Exemple #10
0
  def __init__(self,
               address=None,
               payload=None,
               sources=None,
               provides=None,
               excludes=None,
               services=None,
               platform=None,
               strict_deps=None,
               exports=None,
               compiler_option_sets=None,
               zinc_file_manager=None,
               # Some subclasses can have both .java and .scala sources
               # (e.g., JUnitTests, JvmBinary, even ScalaLibrary), so it's convenient
               # to have both plugins settings here, even though for other subclasses
               # (e.g., JavaLibrary) only one will be relevant.
               javac_plugins=None,
               javac_plugin_args=None,
               scalac_plugins=None,
               scalac_plugin_args=None,
               **kwargs):
    """
    :API: public

    :param excludes: List of `exclude <#exclude>`_\\s to filter this target's
      transitive dependencies against.
    :param sources: Source code files to build. Paths are relative to the BUILD
      file's directory.
    :type sources: ``Fileset`` (from globs or rglobs) or list of strings
    :param services: A dict mapping service interface names to the classes owned by this target
                     that implement them.  Keys are fully qualified service class names, values are
                     lists of strings, each string the fully qualified class name of a class owned
                     by this target that implements the service interface and should be
                     discoverable by the jvm service provider discovery mechanism described here:
                     https://docs.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html
    :param str platform: The name of the platform (defined under the jvm-platform subsystem) to use
                         for compilation (that is, a key into the --jvm-platform-platforms
                         dictionary). If unspecified, the platform will default to the first one of
                         these that exist: (1) the default_platform specified for jvm-platform,
                         (2) a platform constructed from whatever java version is returned by
                         DistributionLocator.cached().version.
    :param bool strict_deps: When True, only the directly declared deps of the target will be used
                             at compilation time. This enforces that all direct deps of the target
                             are declared, and can improve compilation speed due to smaller
                             classpaths. Transitive deps are always provided at runtime.
    :param list exports: A list of exported targets, which will be accessible to dependents even
                         with strict_deps turned on. A common use case is for library targets to
                         to export dependencies that it knows its dependents will need. Then any
                         dependents of that library target will have access to those dependencies
                         even when strict_deps is True. Note: exports is transitive, which means
                         dependents have access to the closure of exports. An example will be that
                         if A exports B, and B exports C, then any targets that depends on A will
                         have access to both B and C.
    :param list compiler_option_sets: A list of compiler_option_sets keys for the target. Platform
      dependent.
    :param bool zinc_file_manager: Whether to use zinc provided file manager that allows
                                   transactional rollbacks, but in certain cases may conflict with
                                   user libraries.
    :param javac_plugins: names of compiler plugins to use when compiling this target with javac.
    :param dict javac_plugin_args: Map from javac plugin name to list of arguments for that plugin.
    :param scalac_plugins: names of compiler plugins to use when compiling this target with scalac.
    :param dict scalac_plugin_args: Map from scalac plugin name to list of arguments for that plugin.
    """

    self.address = address  # Set in case a TargetDefinitionException is thrown early
    payload = payload or Payload()
    excludes = ExcludesField(self.assert_list(excludes, expected_type=Exclude, key_arg='excludes'))
    payload.add_fields({
      'sources': self.create_sources_field(sources, address.spec_path, key_arg='sources'),
      'provides': provides,
      'excludes': excludes,
      'platform': PrimitiveField(platform),
      'strict_deps': PrimitiveField(strict_deps),
      'exports': PrimitivesSetField(exports or []),
      'compiler_option_sets': PrimitivesSetField(compiler_option_sets),
      'zinc_file_manager': PrimitiveField(zinc_file_manager),
      'javac_plugins': PrimitivesSetField(javac_plugins or []),
      'javac_plugin_args': PrimitiveField(javac_plugin_args),
      'scalac_plugins': PrimitivesSetField(scalac_plugins or []),
      'scalac_plugin_args': PrimitiveField(scalac_plugin_args),
    })

    super(JvmTarget, self).__init__(address=address, payload=payload, **kwargs)

    # Service info is only used when generating resources, it should not affect, for example, a
    # compile fingerprint or javadoc fingerprint.  As such, its not a payload field.
    self._services = services or {}