From 5d8934f5a96009b7be0fb6fb36b2d446976e4641 Mon Sep 17 00:00:00 2001 From: Andrew Dutcher Date: Wed, 4 Jan 2017 05:50:53 -0800 Subject: [PATCH] Python: Automatically conform to PEP440 for version numbers --- bindings/python/setup.py | 32 +++++++++++++++++++++++++++++++- pkgconfig.mk | 6 +++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/bindings/python/setup.py b/bindings/python/setup.py index ef4b2327..225d5c25 100755 --- a/bindings/python/setup.py +++ b/bindings/python/setup.py @@ -17,7 +17,6 @@ from distutils.command.sdist import sdist from setuptools.command.bdist_egg import bdist_egg SYSTEM = sys.platform -VERSION = '1.0.0' # sys.maxint is 2**31 - 1 on both 32 and 64 bit mingw IS_64BITS = platform.architecture()[0] == '64bit' @@ -37,6 +36,36 @@ HEADERS_DIR = os.path.join(ROOT_DIR, 'unicorn', 'include') SRC_DIR = os.path.join(ROOT_DIR, 'src') BUILD_DIR = SRC_DIR if os.path.exists(SRC_DIR) else os.path.join(ROOT_DIR, '../..') +# Parse version from pkgconfig.mk +VERSION_DATA = {} +with open(os.path.join(BUILD_DIR, 'pkgconfig.mk')) as fp: + lines = fp.readlines() + for line in lines: + line = line.strip() + if len(line) == 0: + continue + if line.startswith('#'): + continue + if '=' not in line: + continue + + k, v = line.split('=', 1) + k = k.strip() + v = v.strip() + if len(k) == 0 or len(v) == 0: + continue + VERSION_DATA[k] = v + +if 'PKG_MAJOR' not in VERSION_DATA or \ + 'PKG_MINOR' not in VERSION_DATA or \ + 'PKG_EXTRA' not in VERSION_DATA: + raise Exception("Malformed pkgconfig.mk") + +if 'PKG_TAG' in VERSION_DATA: + VERSION = '{PKG_MAJOR}.{PKG_MINOR}.{PKG_EXTRA}.{PKG_TAG}'.format(**VERSION_DATA) +else: + VERSION = '{PKG_MAJOR}.{PKG_MINOR}.{PKG_EXTRA}'.format(**VERSION_DATA) + if SYSTEM == 'darwin': LIBRARY_FILE = "libunicorn.dylib" STATIC_LIBRARY_FILE = 'libunicorn.a' @@ -79,6 +108,7 @@ def copy_sources(): src.extend(glob.glob(os.path.join(ROOT_DIR, "../../RELEASE_NOTES"))) src.extend(glob.glob(os.path.join(ROOT_DIR, "../../make.sh"))) src.extend(glob.glob(os.path.join(ROOT_DIR, "../../CMakeLists.txt"))) + src.extend(glob.glob(os.path.join(ROOT_DIR, "../../pkgconfig.mk"))) for filename in src: outpath = os.path.join(SRC_DIR, os.path.basename(filename)) diff --git a/pkgconfig.mk b/pkgconfig.mk index e4374b15..ec2a14c6 100644 --- a/pkgconfig.mk +++ b/pkgconfig.mk @@ -1,9 +1,13 @@ # Package version of Unicorn for Makefile. # To be used to generate unicorn.pc for pkg-config +# Also used to generate python package version # version major & minor PKG_MAJOR = 1 PKG_MINOR = 0 # version bugfix level. Example: PKG_EXTRA = 1 -PKG_EXTRA = +PKG_EXTRA = 0 + +# version tag. Examples: rc1, b2, post1 +PKG_TAG = rc2