From fa1e969ede02b8a2420fdb907036136ff1feb63c Mon Sep 17 00:00:00 2001 From: Andrew Dutcher Date: Tue, 15 Aug 2017 11:50:01 -0700 Subject: [PATCH] Bundle vex sources in source distribution; warn user when downloading vex manually --- .gitignore | 3 +++ MANIFEST.in | 1 + setup.py | 74 +++++++++++++++++++++++++++++++++++++++++------------ 3 files changed, 61 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 73d4199..7f0dd74 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,6 @@ libpyvex.so *.a pyvex/lib pyvex/include +vex +vex-master +vex-master.tar.gz diff --git a/MANIFEST.in b/MANIFEST.in index 6c5ff77..d82281a 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,3 +2,4 @@ include LICENSE include README.md include make_ffi.py recursive-include pyvex_c *.c *.h *.def Makefile Makefile-msvc LICENSE +recursive-include vex * diff --git a/setup.py b/setup.py index defb8b8..6d019de 100644 --- a/setup.py +++ b/setup.py @@ -6,6 +6,7 @@ import shutil import glob import tarfile import multiprocessing +import time IS_PYTHON2 = sys.version_info < (3, 0) if IS_PYTHON2: @@ -16,6 +17,8 @@ else: import platform PROJECT_DIR = os.path.dirname(os.path.realpath(__file__)) +LIB_DIR = os.path.join(PROJECT_DIR, 'pyvex', 'lib') +INCLUDE_DIR = os.path.join(PROJECT_DIR, 'pyvex', 'include') try: from setuptools import setup @@ -31,6 +34,7 @@ except ImportError: from distutils.util import get_platform from distutils.errors import LibError from distutils.command.build import build as _build +from distutils.command.sdist import sdist as _sdist if sys.platform in ('win32', 'cygwin'): LIBRARY_FILE = 'pyvex.dll' @@ -47,12 +51,25 @@ VEX_LIB_NAME = "vex" # can also be vex-amd64-linux VEX_PATH = os.path.abspath(os.path.join(PROJECT_DIR, '..', 'vex')) if not os.path.exists(VEX_PATH): + VEX_PATH = os.path.join(PROJECT_DIR, 'vex') + +if not os.path.exists(VEX_PATH): + VEX_PATH = os.path.join(PROJECT_DIR, 'vex-master') + +if not os.path.exists(VEX_PATH): + sys.__stderr__.write('###########################################################################\n') + sys.__stderr__.write('WARNING: downloading vex sources directly from github.\n') + sys.__stderr__.write('If this strikes you as a bad idea, please abort and clone the angr/vex repo\n') + sys.__stderr__.write('into the same folder containing the pyvex repo.\n') + sys.__stderr__.write('###########################################################################\n') + sys.__stderr__.flush() + time.sleep(10) + VEX_URL = 'https://github.com/angr/vex/archive/master.tar.gz' - with open('master.tar.gz', 'wb') as v: + with open('vex-master.tar.gz', 'wb') as v: v.write(urlopen(VEX_URL).read()) - with tarfile.open('master.tar.gz') as tar: + with tarfile.open('vex-master.tar.gz') as tar: tar.extractall() - VEX_PATH = os.path.abspath('vex-master') def _build_vex(): e = os.environ.copy() @@ -88,21 +105,36 @@ def _build_pyvex(): raise LibError("Unable to build libpyvex.") def _shuffle_files(): - pyvex_lib_dir = os.path.join(PROJECT_DIR, 'pyvex', 'lib') - pyvex_include_dir = os.path.join(PROJECT_DIR, 'pyvex', 'include') - - shutil.rmtree(pyvex_lib_dir, ignore_errors=True) - shutil.rmtree(pyvex_include_dir, ignore_errors=True) - os.mkdir(pyvex_lib_dir) - os.mkdir(pyvex_include_dir) + shutil.rmtree(LIB_DIR, ignore_errors=True) + shutil.rmtree(INCLUDE_DIR, ignore_errors=True) + os.mkdir(LIB_DIR) + os.mkdir(INCLUDE_DIR) pyvex_c_dir = os.path.join(PROJECT_DIR, 'pyvex_c') - shutil.copy(os.path.join(pyvex_c_dir, LIBRARY_FILE), pyvex_lib_dir) - shutil.copy(os.path.join(pyvex_c_dir, STATIC_LIBRARY_FILE), pyvex_lib_dir) - shutil.copy(os.path.join(pyvex_c_dir, 'pyvex.h'), pyvex_include_dir) + shutil.copy(os.path.join(pyvex_c_dir, LIBRARY_FILE), LIB_DIR) + shutil.copy(os.path.join(pyvex_c_dir, STATIC_LIBRARY_FILE), LIB_DIR) + shutil.copy(os.path.join(pyvex_c_dir, 'pyvex.h'), INCLUDE_DIR) for f in glob.glob(os.path.join(VEX_PATH, 'pub', '*')): - shutil.copy(f, pyvex_include_dir) + shutil.copy(f, INCLUDE_DIR) + +def _clean_bins(): + shutil.rmtree(LIB_DIR, ignore_errors=True) + shutil.rmtree(INCLUDE_DIR, ignore_errors=True) + +def _copy_sources(): + local_vex_path = os.path.join(PROJECT_DIR, 'vex') + assert local_vex_path != VEX_PATH + shutil.rmtree(local_vex_path, ignore_errors=True) + os.mkdir(local_vex_path) + + vex_src = ['LICENSE.GPL', 'LICENSE.README', 'Makefile-gcc', 'Makefile-msvc', 'common.mk', 'pub/*.h', 'priv/*.c', 'priv/*.h', 'auxprogs/*.c'] + for spec in vex_src: + dest_dir = os.path.join(local_vex_path, os.path.dirname(spec)) + if not os.path.isdir(dest_dir): + os.mkdir(dest_dir) + for srcfile in glob.glob(os.path.join(VEX_PATH, spec)): + shutil.copy(srcfile, dest_dir) def _build_ffi(): import make_ffi @@ -119,7 +151,14 @@ class build(_build): self.execute(_shuffle_files, (), msg="Copying libraries and headers") self.execute(_build_ffi, (), msg="Creating CFFI defs file") _build.run(self) -cmdclass = { 'build': build } + +class sdist(_sdist): + def run(self): + self.execute(_clean_bins, (), msg="Removing binaries") + self.execute(_copy_sources, (), msg="Copying VEX sources") + _sdist.run(self) + +cmdclass = { 'build': build, 'sdist': sdist } try: from setuptools.command.develop import develop as _develop @@ -153,8 +192,9 @@ if 'bdist_wheel' in sys.argv and '--plat-name' not in sys.argv: sys.argv.append(name.replace('.', '_').replace('-', '_')) setup( - name="pyvex", version='7.0.0.0rc1', description="A Python interface to libVEX and VEX IR.", - packages=['pyvex', 'pyvex.lift', 'pyvex.lift.util'], + name="pyvex", version='7.0.0.0rc1', description="A Python interface to libVEX and VEX IR", + url='https://github.com/angr/pyvex', + packages=packages, cmdclass=cmdclass, install_requires=[ 'pycparser', 'cffi>=1.0.3', 'archinfo' ], setup_requires=[ 'pycparser', 'cffi>=1.0.3' ],