Moved generation of pkg_info from setup.py to qmake/make - version.pri refactored suitably. Reimplemented sdist_clean as a new setuptools command

This commit is contained in:
Srivats P. 2014-06-08 19:10:49 +05:30
parent 8f51e6f07a
commit 3b4b5a19b9
7 changed files with 80 additions and 45 deletions

View File

@ -4,6 +4,8 @@ syntax: glob
*.pyc *.pyc
*.o *.o
*.a *.a
*.dll
*.so
*.exe *.exe
*.app *.app
drone drone

4
binding/binding.pro Normal file
View File

@ -0,0 +1,4 @@
TEMPLATE = lib
CONFIG += pkg_info
include(../version.pri)

View File

@ -17,41 +17,42 @@
import json import json
import os import os
import re
import shutil import shutil
import sys import sys
from setuptools import setup from setuptools import Command, setup
from setuptools.command.sdist import sdist as _sdist
def read(fname): def read(fname):
return open(fname).read() return open(os.path.join(os.path.dirname(__file__), fname)).read()
def get_pkg_info(): def ensure_cwd():
info = {}
t = open('../server/version.cpp').read()
info['version'] = re.search('version = "([^"]*)"', t).group(1)
info['revision'] = re.search('revision = "([^"]*)"', t).group(1)
return info
# ------- script starts from here ------- #
if len(sys.argv) >= 2 and sys.argv[1] == 'clean_sdist':
shutil.rmtree('dist', ignore_errors = True)
shutil.rmtree('ostinato.egg-info', ignore_errors = True)
if os.path.exists('pkg_info.json'):
os.remove('pkg_info.json')
sys.exit(0)
if len(sys.argv) >= 2 and sys.argv[1] == 'sdist':
if os.path.split(os.getcwd())[1] != 'binding': if os.path.split(os.getcwd())[1] != 'binding':
print 'This script needs to be run from the binding directory' print 'ERROR: This script needs to be run from the binding directory'
print 'Current Working Directory is %s' % os.getcwd() print 'Current Working Directory is %s' % os.getcwd()
sys.exit(1) sys.exit(1)
pkg_info = get_pkg_info() class sdist(_sdist):
with open('pkg_info.json', 'wt') as f: def run(self):
json.dump(pkg_info, f, indent=4) ensure_cwd()
else: _sdist.run(self)
with open('pkg_info.json') as f:
class sdist_clean(Command):
description = 'clean stuff generated by sdist'
user_options = []
def initialize_options(self):
return
def finalize_options(self):
return
def run(self):
ensure_cwd()
shutil.rmtree('dist', ignore_errors = True)
shutil.rmtree('ostinato.egg-info', ignore_errors = True)
# ------- script starts from here ------- #
with open(os.path.join(os.path.dirname(__file__), 'pkg_info.json')) as f:
pkg_info = json.load(f) pkg_info = json.load(f)
setup(name = 'ostinato', setup(name = 'ostinato',
@ -72,6 +73,9 @@ setup(name = 'ostinato',
'Intended Audience :: Telecommunications Industry', 'Intended Audience :: Telecommunications Industry',
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)', 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
'Topic :: Software Development :: Testing :: Traffic Generation', 'Topic :: Software Development :: Testing :: Traffic Generation',
'Topic :: System :: Networking'] 'Topic :: System :: Networking'],
cmdclass={
'sdist': sdist,
'sdist_clean': sdist_clean},
) )

View File

@ -1,5 +1,5 @@
TEMPLATE = app TEMPLATE = app
CONFIG += qt CONFIG += qt ver_info
macx: TARGET = Ostinato macx: TARGET = Ostinato
win32:RC_FILE = ostinato.rc win32:RC_FILE = ostinato.rc
macx:ICON = icons/logo.icns macx:ICON = icons/logo.icns

View File

@ -6,4 +6,6 @@ SUBDIRS = \
common/ostproto.pro \ common/ostproto.pro \
common/ostprotogui.pro \ common/ostprotogui.pro \
server/drone.pro \ server/drone.pro \
client/ostinato.pro client/ostinato.pro \
binding/binding.pro

View File

@ -1,5 +1,5 @@
TEMPLATE = app TEMPLATE = app
CONFIG += qt CONFIG += qt ver_info
QT += network script QT += network script
QT -= gui QT -= gui
DEFINES += HAVE_REMOTE WPCAP DEFINES += HAVE_REMOTE WPCAP

View File

@ -2,6 +2,8 @@ APP_VERSION = 0.5.1
APP_REVISION = $(shell hg identify -i) APP_REVISION = $(shell hg identify -i)
#uncomment the below line in a source package and fill-in the correct revision #uncomment the below line in a source package and fill-in the correct revision
#APP_REVISION = <rev-hash>@ #APP_REVISION = <rev-hash>@
ver_info {
APP_VERSION_FILE = version.cpp APP_VERSION_FILE = version.cpp
revtarget.target = $$APP_VERSION_FILE revtarget.target = $$APP_VERSION_FILE
win32:revtarget.commands = echo "const char *version = \"$$APP_VERSION\";" \ win32:revtarget.commands = echo "const char *version = \"$$APP_VERSION\";" \
@ -17,3 +19,24 @@ SOURCES += $$APP_VERSION_FILE
QMAKE_EXTRA_TARGETS += revtarget QMAKE_EXTRA_TARGETS += revtarget
POST_TARGETDEPS += $$APP_VERSION_FILE POST_TARGETDEPS += $$APP_VERSION_FILE
QMAKE_DISTCLEAN += $$APP_VERSION_FILE QMAKE_DISTCLEAN += $$APP_VERSION_FILE
}
pkg_info {
PKG_INFO_FILE = pkg_info.json
pkginfo.target = $$PKG_INFO_FILE
pkginfo.CONFIG = recursive
win32:pkginfo.commands = echo "{" \
" \"version\": \"$$APP_VERSION\"," \
" \"revision\": \"$$APP_REVISION\"" \
"}" \
> $$PKG_INFO_FILE
unix:pkginfo.commands = echo "\"{" \
" \\\"version\\\": \\\"$$APP_VERSION\\\"," \
" \\\"revision\\\": \\\"$$APP_REVISION\\\"" \
"}\"" \
> $$PKG_INFO_FILE
QMAKE_EXTRA_TARGETS += pkginfo
POST_TARGETDEPS += $$PKG_INFO_FILE
QMAKE_DISTCLEAN += $$PKG_INFO_FILE
}