Add option for inhibiting the core build while installing the python components. Add option for loading the core from a custom path. (#1089)

This commit is contained in:
Audrey Dutcher 2018-02-20 05:11:19 -08:00 committed by Nguyen Anh Quynh
parent 1a1077db01
commit 10c4aa807d
3 changed files with 18 additions and 4 deletions

View File

@ -8,10 +8,18 @@ compile C code. On Linux, this is usually easy, but on Windows, this involves
installing Visual Studio and using the "Developer Command Prompt" to perform the
installation. See BUILDING.txt for more information.
By default, attempting to install the python bindings will trigger a build of
the capstone native core. If this is undesirable for whatever reason, for
instance, you already have a globally installed copy of libcapstone, you may
inhibit the build by setting the environment variable LIBCAPSTONE_PATH. The
exact value is not checked, just setting it will inhibit the build. During
execution, this variable may be set to the path of a directory containing a
specific version of libcapstone you would like to use.
If you don't want to build your own copy of Capstone, you can use a precompiled
binary distribution from PyPI. Saying `pip install capstone` should
automatically obtain an appropriate copy for your system. If it does not, please
open an issue at https://github.com/aquynh/capstone and tag @rhelmot - they
open an issue at https://github.com/aquynh/capstone and tag @rhelmot - she
will fix this, probably!
--------------------------------------------------------------------------------

View File

@ -230,19 +230,22 @@ def _load_lib(path):
_cs = None
# Loading attempts, in order
# - user-provided environment variable
# - pkg_resources can get us the path to the local libraries
# - we can get the path to the local libraries by parsing our filename
# - global load
# - python's lib directory
# - last-gasp attempt at some hardcoded paths on darwin and linux
_path_list = [pkg_resources.resource_filename(__name__, 'lib'),
_path_list = [os.getenv('LIBCAPSTONE_PATH', None),
pkg_resources.resource_filename(__name__, 'lib'),
join(split(__file__)[0], 'lib'),
'',
distutils.sysconfig.get_python_lib(),
"/usr/local/lib/" if sys.platform == 'darwin' else '/usr/lib64']
for _path in _path_list:
if _path is None: continue
_cs = _load_lib(_path)
if _cs is not None: break
else:

View File

@ -156,8 +156,11 @@ class custom_sdist(sdist):
class custom_build(build):
def run(self):
log.info('Building C extensions')
build_libraries()
if 'LIBCAPSTONE_PATH' in os.environ:
log.info('Skipping building C extensions since LIBCAPSTONE_PATH is set')
else:
log.info('Building C extensions')
build_libraries()
return build.run(self)