Example #1
0
    def __init__(self,
                 address,
                 payload=None,
                 sources=None,
                 ctypes_native_library=None,
                 strict_deps=None,
                 fatal_warnings=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),
        })

        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(NativeLibrary, self).__init__(address=address,
                                            payload=payload,
                                            **kwargs)
Example #2
0
def build_file_aliases():
    return BuildFileAliases(targets={
        CLibrary.alias(): CLibrary,
        CppLibrary.alias(): CppLibrary,
    },
                            objects={
                                NativeArtifact.alias(): NativeArtifact,
                            })
Example #3
0
def build_file_aliases():
  return BuildFileAliases(
    targets={
      CLibrary.alias(): CLibrary,
      CppLibrary.alias(): CppLibrary,
      ExternalNativeLibrary.alias(): ExternalNativeLibrary,
    },
    objects={
      NativeArtifact.alias(): NativeArtifact,
    }
  )
Example #4
0
def build_file_aliases():
    return BuildFileAliases(
        targets={
            CLibrary.alias(): CLibrary,
            CppLibrary.alias(): CppLibrary,
            ExternalNativeLibrary.alias(): ExternalNativeLibrary,
            PackagedNativeLibrary.alias(): PackagedNativeLibrary,
        },
        objects={
            ConanRequirement.alias(): ConanRequirement,
            NativeArtifact.alias(): NativeArtifact,
        },
    )
Example #5
0
def build_file_aliases():
  return BuildFileAliases(
    targets={
      CLibrary.alias(): CLibrary,
      CppLibrary.alias(): CppLibrary,
      ExternalNativeLibrary.alias(): ExternalNativeLibrary,
      PackagedNativeLibrary.alias(): PackagedNativeLibrary,
    },
    objects={
      ConanRequirement.alias(): ConanRequirement,
      NativeArtifact.alias(): NativeArtifact,
    }
  )
    def test_caching(self):
        cpp = self.create_simple_cpp_library(
            ctypes_native_library=NativeArtifact(lib_name='test'), )

        cpp_compile_task_type = self.synthesize_task_subtype(
            CppCompile, 'cpp_compile_scope')
        context = self.prepare_context_for_compile(
            target_roots=[cpp], for_task_types=[cpp_compile_task_type])

        cpp_compile = cpp_compile_task_type(
            context, os.path.join(self.pants_workdir, 'cpp_compile'))
        cpp_compile.execute()

        link_shared_libraries = self.create_task(context)

        link_shared_libraries.execute()
        link_shared_libraries.execute()
Example #7
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)
Example #8
0
  def __init__(self, address, payload=None, sources=None, ctypes_native_library=None,
               strict_deps=None, fatal_warnings=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),
    })

    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(NativeLibrary, self).__init__(address=address, payload=payload, **kwargs)
Example #9
0
    def test_caching(self):
        cpp = self.create_simple_cpp_library(
            ctypes_native_library=NativeArtifact(lib_name="test"))

        cpp_compile_task_type = self.synthesize_task_subtype(
            CppCompile, "cpp_compile_scope")
        context = self.prepare_context_for_compile(
            target_roots=[cpp],
            for_task_types=[cpp_compile_task_type],
            options={"libc": {
                "enable_libc_search": True
            }},
        )

        cpp_compile = cpp_compile_task_type(
            context, os.path.join(self.pants_workdir, "cpp_compile"))
        cpp_compile.execute()

        link_shared_libraries = self.create_task(context)

        link_shared_libraries.execute()
        link_shared_libraries.execute()
Example #10
0
class TestBuildLocalDistsWithCtypesNativeSources(
        BuildLocalPythonDistributionsTestBase):

    _extra_relevant_task_types = ([
        CCompile,
        CppCompile,
        LinkSharedLibraries,
    ] + BuildLocalPythonDistributionsTestBase._extra_relevant_task_types)

    _dist_specs = OrderedDict([
        ('src/python/plat_specific_c_dist:ctypes_c_library', {
            'key': 'ctypes_c_library',
            'target_type': CLibrary,
            'ctypes_native_library': NativeArtifact(lib_name='c-math-lib'),
            'sources': ['c_math_lib.c', 'c_math_lib.h'],
            'filemap': {
                'src/python/plat_specific_c_dist/c_math_lib.c':
                dedent("""
        #include "c_math_lib.h"
        int add_two(int x) { return x + 2; }
"""),
                'src/python/plat_specific_c_dist/c_math_lib.h':
                dedent("""
        int add_two(int);
"""),
            }
        }),
        ('src/python/plat_specific_c_dist:plat_specific_ctypes_c_dist', {
            'key': 'platform_specific_ctypes_c_dist',
            'target_type': PythonDistribution,
            'sources': ['__init__.py', 'setup.py'],
            'dependencies':
            ['src/python/plat_specific_c_dist:ctypes_c_library'],
            'filemap': {
                'src/python/plat_specific_c_dist/__init__.py':
                '',
                'src/python/plat_specific_c_dist/setup.py':
                dedent("""
        from setuptools import setup, find_packages
        setup(
          name='platform_specific_ctypes_c_dist',
          version='0.0.0',
          packages=find_packages(),
          data_files=[('', ['libc-math-lib.so'])],
        )
      """),
            }
        }),
        ('src/python/plat_specific_cpp_dist:ctypes_cpp_library', {
            'key': 'ctypes_cpp_library',
            'target_type': CppLibrary,
            'ctypes_native_library': NativeArtifact(lib_name='cpp-math-lib'),
            'sources': ['cpp_math_lib.cpp', 'cpp_math_lib.hpp'],
            'filemap': {
                'src/python/plat_specific_cpp_dist/cpp_math_lib.cpp': '',
                'src/python/plat_specific_cpp_dist/cpp_math_lib.hpp': '',
            },
        }),
        ('src/python/plat_specific_cpp_dist:plat_specific_ctypes_cpp_dist', {
            'key':
            'platform_specific_ctypes_cpp_dist',
            'target_type':
            PythonDistribution,
            'sources': ['__init__.py', 'setup.py'],
            'dependencies':
            ['src/python/plat_specific_cpp_dist:ctypes_cpp_library'],
            'filemap': {
                'src/python/plat_specific_cpp_dist/__init__.py':
                '',
                'src/python/plat_specific_cpp_dist/setup.py':
                dedent("""
        from setuptools import setup, find_packages
        setup(
          name='platform_specific_ctypes_cpp_dist',
          version='0.0.0',
          packages=find_packages(),
          data_files=[('', ['libcpp-math-lib.so'])],
        )
      """),
            }
        }),
    ])

    def test_ctypes_c_dist(self):
        platform_specific_dist = self.target_dict[
            'platform_specific_ctypes_c_dist']
        context, synthetic_target, snapshot_version = self._create_distribution_synthetic_target(
            platform_specific_dist,
            extra_targets=[self.target_dict['ctypes_c_library']])
        self.assertEqual([
            'platform_specific_ctypes_c_dist==0.0.0+{}'.format(
                snapshot_version)
        ], [str(x.requirement) for x in synthetic_target.requirements.value])
        local_wheel_products = context.products.get('local_wheels')
        local_wheel = self._retrieve_single_product_at_target_base(
            local_wheel_products, platform_specific_dist)
        self.assertTrue(check_wheel_platform_matches_host(local_wheel))

    def test_ctypes_cpp_dist(self):
        platform_specific_dist = self.target_dict[
            'platform_specific_ctypes_cpp_dist']
        context, synthetic_target, snapshot_version = self._create_distribution_synthetic_target(
            platform_specific_dist,
            extra_targets=[self.target_dict['ctypes_cpp_library']])
        self.assertEqual([
            'platform_specific_ctypes_cpp_dist==0.0.0+{}'.format(
                snapshot_version)
        ], [str(x.requirement) for x in synthetic_target.requirements.value])

        local_wheel_products = context.products.get('local_wheels')
        local_wheel = self._retrieve_single_product_at_target_base(
            local_wheel_products, platform_specific_dist)
        self.assertTrue(check_wheel_platform_matches_host(local_wheel))
Example #11
0
class TestBuildLocalDistsWithCtypesNativeSources(BuildLocalPythonDistributionsTestBase):
    @classproperty
    def run_before_task_types(cls):
        return [CCompile, CppCompile, LinkSharedLibraries] + super().run_before_task_types

    dist_specs = OrderedDict(
        [
            (
                "src/python/plat_specific_c_dist:ctypes_c_library",
                {
                    "key": "ctypes_c_library",
                    "target_type": CLibrary,
                    "ctypes_native_library": NativeArtifact(lib_name="c-math-lib"),
                    "sources": ["c_math_lib.c", "c_math_lib.h"],
                    "filemap": {
                        "c_math_lib.c": """\
#include "c_math_lib.h"
int add_two(int x) { return x + 2; }
        """,
                        "c_math_lib.h": """\
int add_two(int);
        """,
                    },
                },
            ),
            (
                "src/python/plat_specific_c_dist:plat_specific_ctypes_c_dist",
                {
                    "key": "platform_specific_ctypes_c_dist",
                    "target_type": PythonDistribution,
                    "sources": ["__init__.py", "setup.py"],
                    "dependencies": ["src/python/plat_specific_c_dist:ctypes_c_library"],
                    "filemap": {
                        "__init__.py": "",
                        "setup.py": """\
from setuptools import setup, find_packages
setup(
  name='platform_specific_ctypes_c_dist',
  version='0.0.0',
  packages=find_packages(),
  data_files=[('', ['libc-math-lib.so'])],
)
        """,
                    },
                },
            ),
            (
                "src/python/plat_specific_cpp_dist:ctypes_cpp_library",
                {
                    "key": "ctypes_cpp_library",
                    "target_type": CppLibrary,
                    "ctypes_native_library": NativeArtifact(lib_name="cpp-math-lib"),
                    "sources": ["cpp_math_lib.cpp", "cpp_math_lib.hpp"],
                    "filemap": {
                        "cpp_math_lib.cpp": """\
#include "cpp_math_lib.hpp"
int add_two(int x) { return (x++) + 1; }
        """,
                        "cpp_math_lib.hpp": """\
int add_two(int);
        """,
                    },
                },
            ),
            (
                "src/python/plat_specific_cpp_dist:plat_specific_ctypes_cpp_dist",
                {
                    "key": "platform_specific_ctypes_cpp_dist",
                    "target_type": PythonDistribution,
                    "sources": ["__init__.py", "setup.py"],
                    "dependencies": ["src/python/plat_specific_cpp_dist:ctypes_cpp_library"],
                    "filemap": {
                        "__init__.py": "",
                        "setup.py": """\
from setuptools import setup, find_packages
setup(
  name='platform_specific_ctypes_cpp_dist',
  version='0.0.0',
  packages=find_packages(),
  data_files=[('', ['libcpp-math-lib.so'])],
)
        """,
                    },
                },
            ),
        ]
    )

    def test_ctypes_c_dist(self):
        platform_specific_dist = self.target_dict["platform_specific_ctypes_c_dist"]
        self._assert_dist_and_wheel_identity(
            expected_name="platform_specific_ctypes_c_dist",
            expected_version="0.0.0",
            expected_platform=self.ExpectedPlatformType.current,
            dist_target=platform_specific_dist,
            extra_targets=[self.target_dict["ctypes_c_library"]],
        )

    def test_ctypes_cpp_dist(self):
        platform_specific_dist = self.target_dict["platform_specific_ctypes_cpp_dist"]
        self._assert_dist_and_wheel_identity(
            expected_name="platform_specific_ctypes_cpp_dist",
            expected_version="0.0.0",
            expected_platform=self.ExpectedPlatformType.current,
            dist_target=platform_specific_dist,
            extra_targets=[self.target_dict["ctypes_cpp_library"]],
        )

    def test_multiplatform_python_setup_resolve_bypasses_python_setup(self):
        self.set_options_for_scope(
            "python-setup", platforms=["current", "linux-x86_64", "macosx_10_14_x86_64"]
        )
        platform_specific_dist = self.target_dict["platform_specific_ctypes_cpp_dist"]
        self._assert_dist_and_wheel_identity(
            expected_name="platform_specific_ctypes_cpp_dist",
            expected_version="0.0.0",
            expected_platform=self.ExpectedPlatformType.current,
            dist_target=platform_specific_dist,
            extra_targets=[self.target_dict["ctypes_cpp_library"]],
        )

    def test_resolve_for_native_sources_allows_current_platform_only(self):
        platform_specific_dist = self.target_dict["platform_specific_ctypes_cpp_dist"]
        compatible_python_binary_target = self.make_target(
            spec="src/python/plat_specific:bin",
            target_type=PythonBinary,
            dependencies=[platform_specific_dist],
            entry_point="this-will-not-run",
            platforms=["current"],
        )
        self._assert_dist_and_wheel_identity(
            expected_name="platform_specific_ctypes_cpp_dist",
            expected_version="0.0.0",
            expected_platform=self.ExpectedPlatformType.current,
            dist_target=platform_specific_dist,
            extra_targets=[
                self.target_dict["ctypes_cpp_library"],
                compatible_python_binary_target,
            ],
        )
Example #12
0
class TestBuildLocalDistsWithCtypesNativeSources(BuildLocalPythonDistributionsTestBase):

  @classproperty
  def run_before_task_types(cls):
    return [
      CCompile,
      CppCompile,
      LinkSharedLibraries,
    ] + super().run_before_task_types

  dist_specs = OrderedDict([

    ('src/python/plat_specific_c_dist:ctypes_c_library', {
      'key': 'ctypes_c_library',
      'target_type': CLibrary,
      'ctypes_native_library': NativeArtifact(lib_name='c-math-lib'),
      'sources': ['c_math_lib.c', 'c_math_lib.h'],
      'filemap': {
        'c_math_lib.c': """\
#include "c_math_lib.h"
int add_two(int x) { return x + 2; }
        """,
        'c_math_lib.h': """\
int add_two(int);
        """,
      },
    }),

    ('src/python/plat_specific_c_dist:plat_specific_ctypes_c_dist', {
      'key': 'platform_specific_ctypes_c_dist',
      'target_type': PythonDistribution,
      'sources': ['__init__.py', 'setup.py'],
      'dependencies': ['src/python/plat_specific_c_dist:ctypes_c_library'],
      'filemap': {
        '__init__.py': '',
        'setup.py': """\
from setuptools import setup, find_packages
setup(
  name='platform_specific_ctypes_c_dist',
  version='0.0.0',
  packages=find_packages(),
  data_files=[('', ['libc-math-lib.so'])],
)
        """,
      },
    }),

    ('src/python/plat_specific_cpp_dist:ctypes_cpp_library', {
      'key': 'ctypes_cpp_library',
      'target_type': CppLibrary,
      'ctypes_native_library': NativeArtifact(lib_name='cpp-math-lib'),
      'sources': ['cpp_math_lib.cpp', 'cpp_math_lib.hpp'],
      'filemap': {
        'cpp_math_lib.cpp': """\
#include "cpp_math_lib.hpp"
int add_two(int x) { return (x++) + 1; }
        """,
        'cpp_math_lib.hpp': """\
int add_two(int);
        """,
      },
    }),

    ('src/python/plat_specific_cpp_dist:plat_specific_ctypes_cpp_dist', {
      'key': 'platform_specific_ctypes_cpp_dist',
      'target_type': PythonDistribution,
      'sources': ['__init__.py', 'setup.py'],
      'dependencies': ['src/python/plat_specific_cpp_dist:ctypes_cpp_library'],
      'filemap': {
        '__init__.py': '',
        'setup.py': """\
from setuptools import setup, find_packages
setup(
  name='platform_specific_ctypes_cpp_dist',
  version='0.0.0',
  packages=find_packages(),
  data_files=[('', ['libcpp-math-lib.so'])],
)
        """,
      },
    }),

  ])

  def test_ctypes_c_dist(self):
    platform_specific_dist = self.target_dict['platform_specific_ctypes_c_dist']
    self._assert_dist_and_wheel_identity(
      expected_name='platform_specific_ctypes_c_dist',
      expected_version='0.0.0',
      expected_platform=self.ExpectedPlatformType.current,
      dist_target=platform_specific_dist,
      extra_targets=[self.target_dict['ctypes_c_library']],
    )

  def test_ctypes_cpp_dist(self):
    platform_specific_dist = self.target_dict['platform_specific_ctypes_cpp_dist']
    self._assert_dist_and_wheel_identity(
      expected_name='platform_specific_ctypes_cpp_dist',
      expected_version='0.0.0',
      expected_platform=self.ExpectedPlatformType.current,
      dist_target=platform_specific_dist,
      extra_targets=[self.target_dict['ctypes_cpp_library']],
    )

  def test_multiplatform_python_setup_resolve_bypasses_python_setup(self):
    self.set_options_for_scope('python-setup',
                               platforms=['current', 'linux-x86_64', 'macosx_10_14_x86_64'])
    platform_specific_dist = self.target_dict['platform_specific_ctypes_cpp_dist']
    self._assert_dist_and_wheel_identity(
      expected_name='platform_specific_ctypes_cpp_dist',
      expected_version='0.0.0',
      expected_platform=self.ExpectedPlatformType.current,
      dist_target=platform_specific_dist,
      extra_targets=[self.target_dict['ctypes_cpp_library']],
    )

  def test_resolve_for_native_sources_allows_current_platform_only(self):
    platform_specific_dist = self.target_dict['platform_specific_ctypes_cpp_dist']
    compatible_python_binary_target = self.make_target(
      spec='src/python/plat_specific:bin',
      target_type=PythonBinary,
      dependencies=[platform_specific_dist],
      entry_point='this-will-not-run',
      platforms=['current'],
    )
    self._assert_dist_and_wheel_identity(
      expected_name='platform_specific_ctypes_cpp_dist',
      expected_version='0.0.0',
      expected_platform=self.ExpectedPlatformType.current,
      dist_target=platform_specific_dist,
      extra_targets=[
        self.target_dict['ctypes_cpp_library'],
        compatible_python_binary_target,
      ],
    )