Skip to content

Commit

Permalink
Python: Automatically conform to PEP440 for version numbers. ported f…
Browse files Browse the repository at this point in the history
…rom Unicorn Python binding
  • Loading branch information
aquynh committed Feb 1, 2017
1 parent bd2077c commit 9edf92c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
32 changes: 31 additions & 1 deletion bindings/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from setuptools.command.bdist_egg import bdist_egg

SYSTEM = sys.platform
VERSION = '4.0.0'

# adapted from commit e504b81 of Nguyen Tan Cong
# Reference: https://docs.python.org/2/library/platform.html#cross-platform
Expand All @@ -27,6 +26,36 @@
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':
VERSIONED_LIBRARY_FILE = "libcapstone.4.dylib"
LIBRARY_FILE = "libcapstone.dylib"
Expand Down Expand Up @@ -69,6 +98,7 @@ def copy_sources():
src.extend(glob.glob(os.path.join(BUILD_DIR, "RELEASE_NOTES")))
src.extend(glob.glob(os.path.join(BUILD_DIR, "make.sh")))
src.extend(glob.glob(os.path.join(BUILD_DIR, "CMakeLists.txt")))
src.extend(glob.glob(os.path.join(BUILD_DIR, "pkgconfig.mk")))

for filename in src:
outpath = os.path.join(SRC_DIR, os.path.basename(filename))
Expand Down
5 changes: 4 additions & 1 deletion pkgconfig.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ PKG_MAJOR = 4
PKG_MINOR = 0

# version bugfix level. Example: PKG_EXTRA = 1
PKG_EXTRA =
PKG_EXTRA = 0

# version tag. Examples: rc1, b2, post1
PKG_TAG = rc1

0 comments on commit 9edf92c

Please sign in to comment.