[PATCH 2/2] waf: Fix version.py to support older versions of git.
chrisj at rtems.org
chrisj at rtems.org
Tue Feb 12 23:52:32 UTC 2019
From: Chris Johns <chrisj at rtems.org>
---
common/version.py | 53 ++++++++++++++++++++++++++++++++---------------
wscript | 1 +
2 files changed, 37 insertions(+), 17 deletions(-)
diff --git a/common/version.py b/common/version.py
index 3ba9454..0f37dad 100644
--- a/common/version.py
+++ b/common/version.py
@@ -65,18 +65,37 @@ from __future__ import print_function
import os.path
+import waflib
+
_version = 'invalid'
_date = 'unknown date'
_released = False
-def _pretty_day(day):
+def _pretty_day(ctx, date):
+ ''' Format is YYYY-MM-DD'''
+ import datetime
+ ds = date.split('-')
+ if len(ds) != 3:
+ ctx.fatal('invalid date format from git: %s' % (date))
+ try:
+ year = int(ds[0])
+ except:
+ ctx.fatal('invalid date format from git, converting year: %s' % (date))
+ try:
+ month = int(ds[1])
+ except:
+ ctx.fatal('invalid date format from git, converting month: %s' % (date))
+ try:
+ day = int(ds[2])
+ except:
+ ctx.fatal('invalid date format from git, converting day: %s' % (date))
+ try:
+ when = datetime.date(year, month, day)
+ except:
+ ctx.fatal('invalid date format from git: %s' % (date))
if day == 3:
s = 'rd'
- elif day == 11:
- s = 'th'
- elif day == 12:
- s = 'th'
- elif day == 13:
+ elif day == 11 or day == 12:
s = 'th'
elif day % 10 == 1:
s = 'st'
@@ -84,7 +103,10 @@ def _pretty_day(day):
s = 'nd'
else:
s = 'th'
- return str(day) + s
+ s = when.strftime('%%d%s %%B %%Y' % (s))
+ if day < 10:
+ s = s[1:]
+ return s
def get(ctx, rtems_major_version):
global _version
@@ -122,19 +144,16 @@ def get(ctx, rtems_major_version):
#
# Get date and version from Git
#
- if ctx.exec_command(['git', 'diff-index', '--quiet', 'HEAD']) == 0:
+ if ctx.exec_command([ctx.env.GIT[0], 'diff-index', '--quiet', 'HEAD']) == 0:
modified = ''
else:
modified = '-modified'
- try:
- out = ctx.cmd_and_log(['git', 'log', '-1',
- '--format=%h,%cd', '--date=format:%e,%B,%Y'],
- quiet = True)
- f = out.strip('\n').split(',')
- version = version + '.' + f[0] + modified
- date = _pretty_day(int(f[1])) + ' ' + f[2] + ' ' + f[3]
- except waflib.Build.Errors.WafError:
- date = 'unknown date'
+ out = ctx.cmd_and_log([ctx.env.GIT[0], 'log', '-1',
+ '--format=%h,%cd', '--date=short'],
+ quiet = True)
+ f = out.strip('\n').split(',')
+ version = version + '.' + f[0] + modified
+ date = _pretty_day(ctx, f[1])
_version = version
_date = date
_release = released
diff --git a/wscript b/wscript
index 7cdda9a..06ac034 100644
--- a/wscript
+++ b/wscript
@@ -44,6 +44,7 @@ def options(opt):
docs_waf.cmd_options(opt)
def configure(conf):
+ conf.find_program('git')
for b in building:
conf.recurse(b)
conf.env['BUILD_FROM_TOP'] = 'yes'
--
2.19.1
More information about the devel
mailing list