Skip to content

Commit

Permalink
plumb in a native toolchain subsystem
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicexplorer committed Feb 1, 2018
1 parent 5ed218e commit 5a6ad48
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# coding=utf-8
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

from pants.binaries.binary_util import BinaryUtil
from pants.subsystem.subsystem import Subsystem
from pants.util.memo import memoized_property


class PythonNativeToolchain(object):
"""Represents a self-boostrapping set of binaries and libraries used to
compile native code in for python dists."""

class Factory(Subsystem):
options_scope = 'python-native-toolchain'

@classmethod
def subsystem_dependencies(cls):
return (BinaryUtil.Factory,)

@classmethod
def register_options(cls, register):
register('--supportdir', advanced=True,
help='Find the go distributions under this dir. Used as part '
'of the path to lookup the distribution with '
'--binary-util-baseurls and --pants-bootstrapdir',
default='bin/python-native-toolchain')
register('--clang-version', advanced=True,
help='Clang version used to compile python native extensions. '
'Used as part of the path to lookup the distribution '
'with --binary-util-baseurls and --pants-bootstrapdir',
default='5.0.0')

# NB: create() is an instance method to allow the user to choose global or
# scoped -- It's not unreasonable to imagine different stacks for different
# python versions. Get an instance of this with
# PythonNativeToolchain.Factory.scoped_instance(self).create()!
def create(self):
binary_util = BinaryUtil.Factory.create()
options = self.get_options()
return PythonNativeToolchain(binary_util=binary_util,
relpath=options.supportdir,
clang_version=options.clang_version)

def __init__(self, binary_util, relpath, clang_version):
self._binary_util = binary_util
self._relpath = relpath
self._clang_version = clang_version

@property
def clang_version(self):
return self._clang_version

@memoized_property
def clang_path(self):
return self._binary_util.select_binary(
self._relpath, self.clang_version, 'clang')
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from pex.interpreter import PythonInterpreter

from pants.backend.python.subsystems.python_native_toolchain import PythonNativeToolchain
from pants.backend.python.tasks.pex_build_util import is_local_python_dist
from pants.backend.python.tasks.setup_py import SetupPyRunner
from pants.base.build_environment import get_buildroot
Expand All @@ -21,6 +22,7 @@
from pants.task.task import Task
from pants.util.contextutil import environment_as, temporary_dir
from pants.util.dirutil import safe_mkdir
from pants.util.memo import memoized_property


PANTSSETUP_IMPORT_BOILERPLATE = """
Expand Down Expand Up @@ -48,6 +50,14 @@ def product_types(cls):
def prepare(cls, options, round_manager):
round_manager.require_data(PythonInterpreter)

@classmethod
def subsystem_dependencies(cls):
return super(BuildLocalPythonDistributions, cls).subsystem_dependencies() + (PythonNativeToolchain.Factory,)

@memoized_property
def python_native_toolchain(self):
return PythonNativeToolchain.Factory.scoped_instance(self).create()

@property
def cache_target_dirs(self):
return True
Expand Down

0 comments on commit 5a6ad48

Please sign in to comment.