Python: Automatically conform to PEP440 for version numbers

This commit is contained in:
Andrew Dutcher 2017-01-04 05:50:53 -08:00
parent c2d57c6806
commit 5d8934f5a9
2 changed files with 36 additions and 2 deletions

View file

@ -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))

View file

@ -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