-
-
Notifications
You must be signed in to change notification settings - Fork 637
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conan (third party) support for ctypes native libraries (#5998)
### Problem The new targets introduced in #5815 have no means of declaring, fetching, and using third party native dependencies. ### Solution Integrate the Conan package manager to fetch packages from a remote package store via a new task, copy the package data to the results directory of `third_party_native_library` targets in play, and create a product that the compile and link tasks can consume. Plumb the directory paths provided by the product through to the command lines of the compile and link steps. ### Result Users can now depend on third party native libraries in their `ctypes_compatible_cpp_library` targets from either conan-center or a remote URI that they specify via an option. ## Some notes - The conan home directory is currently under .pants.d, instead of ~ or ~/.cache/pants. I did this for the short term to make debugging cache problems and other issues as simple as a ./pants clean-all. I don't think the perf loss will be too bad (1-2 seconds). - Some string manipulation could be better done as regex, and I have TODOs for that - I am going to follow up with upstream Conan about getting a flag for cleaner client output so the parse method does not need to be so ugly.
- Loading branch information
1 parent
d3f2005
commit 4aec12c
Showing
20 changed files
with
836 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# coding=utf-8 | ||
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
import logging | ||
import os | ||
|
||
from pex.interpreter import PythonInterpreter | ||
from pex.pex import PEX | ||
from pex.pex_builder import PEXBuilder | ||
from pex.pex_info import PexInfo | ||
|
||
from pants.backend.python.python_requirement import PythonRequirement | ||
from pants.backend.python.tasks.pex_build_util import dump_requirements | ||
from pants.backend.python.tasks.wrapped_pex import WrappedPEX | ||
from pants.base.build_environment import get_pants_cachedir | ||
from pants.subsystem.subsystem import Subsystem | ||
from pants.util.dirutil import safe_concurrent_creation | ||
from pants.util.objects import datatype | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Conan(Subsystem): | ||
"""Pex binary for the conan package manager.""" | ||
options_scope = 'conan' | ||
default_conan_requirements = ( | ||
'conan==1.4.4', | ||
'PyJWT>=1.4.0, <2.0.0', | ||
'requests>=2.7.0, <3.0.0', | ||
'colorama>=0.3.3, <0.4.0', | ||
'PyYAML>=3.11, <3.13.0', | ||
'patch==1.16', | ||
'fasteners>=0.14.1', | ||
'six>=1.10.0', | ||
'node-semver==0.2.0', | ||
'distro>=1.0.2, <1.2.0', | ||
'pylint>=1.8.1, <1.9.0', | ||
'future==0.16.0', | ||
'pygments>=2.0, <3.0', | ||
'astroid>=1.6, <1.7', | ||
'deprecation>=2.0, <2.1' | ||
) | ||
|
||
@classmethod | ||
def implementation_version(cls): | ||
return super(Conan, cls).implementation_version() + [('Conan', 0)] | ||
|
||
@classmethod | ||
def register_options(cls, register): | ||
super(Conan, cls).register_options(register) | ||
register('--conan-requirements', type=list, default=cls.default_conan_requirements, | ||
advanced=True, help='The requirements used to build the conan client pex.') | ||
|
||
class ConanBinary(datatype(['pex'])): | ||
"""A `conan` PEX binary.""" | ||
pass | ||
|
||
def bootstrap_conan(self): | ||
pex_info = PexInfo.default() | ||
pex_info.entry_point = 'conans.conan' | ||
conan_bootstrap_dir = os.path.join(get_pants_cachedir(), 'conan_support') | ||
conan_pex_path = os.path.join(conan_bootstrap_dir, 'conan_binary') | ||
interpreter = PythonInterpreter.get() | ||
if os.path.exists(conan_pex_path): | ||
conan_binary = WrappedPEX(PEX(conan_pex_path, interpreter)) | ||
return self.ConanBinary(pex=conan_binary) | ||
else: | ||
with safe_concurrent_creation(conan_pex_path) as safe_path: | ||
builder = PEXBuilder(safe_path, interpreter, pex_info=pex_info) | ||
reqs = [PythonRequirement(req) for req in self.get_options().conan_requirements] | ||
dump_requirements(builder, interpreter, reqs, logger) | ||
builder.freeze() | ||
conan_binary = WrappedPEX(PEX(conan_pex_path, interpreter)) | ||
return self.ConanBinary(pex=conan_binary) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/python/pants/backend/native/targets/external_native_library.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# coding=utf-8 | ||
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
import re | ||
|
||
from pants.base.payload import Payload | ||
from pants.base.payload_field import PrimitiveField | ||
from pants.base.validation import assert_list | ||
from pants.build_graph.target import Target | ||
|
||
|
||
class ExternalNativeLibrary(Target): | ||
"""A set of Conan package strings to be passed to the Conan package manager.""" | ||
|
||
@classmethod | ||
def alias(cls): | ||
return 'external_native_library' | ||
|
||
def __init__(self, payload=None, packages=None, **kwargs): | ||
""" | ||
:param packages: a list of Conan-style package strings | ||
Example: | ||
lzo/2.10@twitter/stable | ||
""" | ||
payload = payload or Payload() | ||
|
||
assert_list(packages, key_arg='packages') | ||
payload.add_fields({ | ||
'packages': PrimitiveField(packages), | ||
}) | ||
super(ExternalNativeLibrary, self).__init__(payload=payload, **kwargs) | ||
|
||
@property | ||
def packages(self): | ||
return self.payload.packages | ||
|
||
@property | ||
def lib_names(self): | ||
return [re.match(r'^([^\/]+)\/', pkg_name).group(1) for pkg_name in self.payload.packages] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.