forked from pantsbuild/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plumb in a native toolchain subsystem
- Loading branch information
1 parent
5ed218e
commit 5a6ad48
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/python/pants/backend/python/subsystems/python_native_toolchain.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,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') |
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