From 59deed74849540198ca6b4a82ae3933b1eca9173 Mon Sep 17 00:00:00 2001 From: mio Date: Tue, 5 Oct 2021 14:46:04 +0200 Subject: [PATCH] Simply the setup.py --- bindings/python/setup.py | 37 ++++++++---------------------- bindings/python/unicorn/unicorn.py | 8 ++++--- 2 files changed, 14 insertions(+), 31 deletions(-) diff --git a/bindings/python/setup.py b/bindings/python/setup.py index b42ede8a..3caa0775 100755 --- a/bindings/python/setup.py +++ b/bindings/python/setup.py @@ -33,7 +33,6 @@ VERSION = "2.0.0rc1" if SYSTEM == 'darwin': LIBRARY_FILE = "libunicorn.dylib" - MAC_LIBRARY_FILE = "libunicorn*.dylib" STATIC_LIBRARY_FILE = None elif SYSTEM in ('win32', 'cygwin'): LIBRARY_FILE = "unicorn.dll" @@ -123,46 +122,28 @@ def build_libraries(): if not os.path.exists(BUILD_DIR): os.mkdir(BUILD_DIR) - subprocess.call(['cmake', '-B', BUILD_DIR, '-G', "Visual Studio 16 2019", "-A", plat, "-DCMAKE_BUILD_TYPE=" + conf]) - subprocess.call(['msbuild', 'unicorn.sln', '-m', '-p:Platform=' + plat, '-p:Configuration=' + conf], cwd=BUILD_DIR) + subprocess.check_call(['cmake', '-B', BUILD_DIR, '-G', "Visual Studio 16 2019", "-A", plat, "-DCMAKE_BUILD_TYPE=" + conf]) + subprocess.check_call(['msbuild', 'unicorn.sln', '-m', '-p:Platform=' + plat, '-p:Configuration=' + conf], cwd=BUILD_DIR) obj_dir = os.path.join(BUILD_DIR, conf) shutil.copy(os.path.join(obj_dir, LIBRARY_FILE), LIBS_DIR) shutil.copy(os.path.join(obj_dir, STATIC_LIBRARY_FILE), LIBS_DIR) else: # platform description refs at https://docs.python.org/2/library/sys.html#sys.platform - new_env = dict(os.environ) - new_env['UNICORN_BUILD_CORE_ONLY'] = 'yes' if not os.path.exists(BUILD_DIR): os.mkdir(BUILD_DIR) + conf = 'Debug' if os.getenv('DEBUG', '') else 'Release' + + subprocess.check_call(["cmake", '-B', BUILD_DIR, "-DCMAKE_BUILD_TYPE=" + conf]) os.chdir(BUILD_DIR) - cmd = ['sh', '../cmake.sh'] - if SYSTEM == "cygwin": - if IS_64BITS: - cmd.append('cygwin-mingw64') - else: - cmd.append('cygwin-mingw32') - elif SYSTEM == "win32": - if IS_64BITS: - cmd.append('cross-win64') - else: - cmd.append('cross-win32') - - subprocess.call(cmd, env=new_env) - - if SYSTEM == 'darwin': - for file in glob.glob(MAC_LIBRARY_FILE): - try: - shutil.copy(file, LIBS_DIR, follow_symlinks=False) - except: - shutil.copy(file, LIBS_DIR) - else: - shutil.copy(LIBRARY_FILE, LIBS_DIR) + subprocess.check_call(["make", "-j4"]) + + shutil.copy(LIBRARY_FILE, LIBS_DIR) try: # static library may fail to build on windows if user doesn't have visual studio installed. this is fine. if STATIC_LIBRARY_FILE is not None: shutil.copy(STATIC_LIBRARY_FILE, LIBS_DIR) - except: + except FileNotFoundError: print('Warning: Could not build static library file! This build is not appropriate for a binary distribution') # enforce this if 'upload' in sys.argv: diff --git a/bindings/python/unicorn/unicorn.py b/bindings/python/unicorn/unicorn.py index 34e598bb..58c6ee06 100644 --- a/bindings/python/unicorn/unicorn.py +++ b/bindings/python/unicorn/unicorn.py @@ -61,7 +61,6 @@ def _load_lib(path): _load_win_support(path) lib_file = os.path.join(path, _lib.get(sys.platform, 'libunicorn.so')) - #print('Trying to load shared library', lib_file) dll = ctypes.cdll.LoadLibrary(lib_file) #print('SUCCESS') return dll @@ -101,8 +100,11 @@ __version__ = "%u.%u.%u" % (uc.UC_VERSION_MAJOR, uc.UC_VERSION_MINOR, uc.UC_VERS # setup all the function prototype def _setup_prototype(lib, fname, restype, *argtypes): - getattr(lib, fname).restype = restype - getattr(lib, fname).argtypes = argtypes + try: + getattr(lib, fname).restype = restype + getattr(lib, fname).argtypes = argtypes + except AttributeError: + raise ImportError("ERROR: Fail to setup some function prototypes. Make sure you have cleaned your unicorn1 installation.") ucerr = ctypes.c_int uc_mode = ctypes.c_int