lazily compute VESION; write a pybindgen/version.py file in configure

This commit is contained in:
Gustavo J. A. M. Carneiro
2007-06-01 15:31:13 +01:00
parent 46205844b0
commit 90bf6801c4
2 changed files with 30 additions and 5 deletions
+2
View File
@@ -4,6 +4,8 @@ def build(bld):
obj = bld.create_obj('py')
obj.find_sources_in_dirs('.')
# commented, triggers a WAF bug (Issue #40)
#obj.source.append('version.py')
obj.inst_dir = 'pybindgen'
obj = bld.create_obj('py')
+28 -5
View File
@@ -3,6 +3,7 @@
import Params
from Params import fatal
import Utils
import os
import pproc as subprocess
import shutil
@@ -11,17 +12,18 @@ def get_version_from_bzr():
import bzrlib.tag, bzrlib.branch
branch = bzrlib.branch.Branch.open('file://' + os.getcwd())
tags = bzrlib.tag.BasicTags(branch)
current_rev = branch.revision_history()[-1]
current_rev = branch.last_revision()
for tag, revid in tags.get_tag_dict().iteritems():
if revid == current_rev:
return str(tag)
return str("bzr_r%i" % (branch.revno(),))
try:
VERSION = get_version_from_bzr()
except ImportError:
VERSION = 'unknown'
def get_version():
try:
return get_version_from_bzr()
except ImportError:
return 'unknown'
APPNAME='pybindgen'
srcdir = '.'
@@ -52,6 +54,27 @@ def configure(conf):
"(Hint: if you do not have a debugging Python library installed"
" try using the configure option '--debug-level release')")
## Write a pybindgen/version.py file containing the project version
version = get_version()
version_lst = version.split('.')
configfile = 'pybindgen/version.py'
lst = Utils.split_path(configfile)
base = [conf.m_blddir, conf.env.variant()] + lst[:-1]
dir_ = Utils.join_path(*base)
try:
os.makedirs(dir_)
except OSError:
pass
fname = Utils.join_path(dir_, lst[-1])
dest = open(fname, 'w')
if len(version_lst) > 1:
dest.write('__version__ = (%s)\n' % (', '.join(version.split('.')),))
else:
dest.write('__version__ = "%s"\n' % (version,))
dest.close()
def build(bld):
if Params.g_commands['check']:
bld.add_subdirs('tests')