From 48f5a3ca476bc3f24cb856b6f0a294c54ddc883e Mon Sep 17 00:00:00 2001 From: Alexander Afanasyev Date: Fri, 22 Aug 2014 22:33:01 -0700 Subject: [PATCH] build: Enable detailed version information when built from shallow clone or tarball Change-Id: Ie2cc05687f4bce136451d316f32e9bab3e82844a Refs: #1915 --- .gitignore | 2 +- wscript | 42 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index a4d64991..b54981e2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ .lock* **/*.pyc build/ - +VERSION diff --git a/wscript b/wscript index 7a03afd7..ba1c6eb6 100644 --- a/wscript +++ b/wscript @@ -27,6 +27,7 @@ VERSION = "0.2.0" APPNAME = "nfd" BUGREPORT = "http://redmine.named-data.net/projects/nfd" URL = "http://named-data.net/doc/NFD/" +GIT_TAG_PREFIX = "NFD-" from waflib import Logs, Utils, Context @@ -250,16 +251,49 @@ def version(ctx): Context.g_module.VERSION_BASE = Context.g_module.VERSION Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')] + didGetVersion = False try: - cmd = ['git', 'describe', '--match', 'NFD-*'] + cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE, stderr=None, stdin=None) out = p.communicate()[0].strip() - if p.returncode == 0 and out != "": - Context.g_module.VERSION = out[4:] - except: + didGetVersion = (p.returncode == 0 and out != "") + if didGetVersion: + if out.startswith(GIT_TAG_PREFIX): + Context.g_module.VERSION = out[len(GIT_TAG_PREFIX):] + else: + Context.g_module.VERSION = "%s-commit-%s" % (Context.g_module.VERSION_BASE, out) + except OSError: pass + versionFile = ctx.path.find_node('VERSION') + + if not didGetVersion and versionFile is not None: + try: + Context.g_module.VERSION = versionFile.read() + return + except (OSError, IOError): + pass + + # version was obtained from git, update VERSION file if necessary + if versionFile is not None: + try: + version = versionFile.read() + if version == Context.g_module.VERSION: + return # no need to update + except (OSError, IOError): + Logs.warn("VERSION file exists, but not readable") + else: + versionFile = ctx.path.make_node('VERSION') + + if versionFile is None: + return + + try: + versionFile.write(Context.g_module.VERSION) + except (OSError, IOError): + Logs.warn("VERSION file is not writeable") + def dist(ctx): version(ctx)