summaryrefslogtreecommitdiffstats
path: root/source-builder/sb/version.py
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2015-12-03 22:22:17 +1100
committerChris Johns <chrisj@rtems.org>2015-12-03 22:25:00 +1100
commit47d703fd8c952f9a684a0a41faad81f5983acaaf (patch)
treedfcce9cf0e0979d95a4147499d04ab557909fedf /source-builder/sb/version.py
parentAdd RTEMS 4.12 build set (diff)
downloadrtems-source-builder-47d703fd8c952f9a684a0a41faad81f5983acaaf.tar.bz2
sb. Add VERSION support for releasing the RSB.
Add support to release the RSB by adding the VERSION file. The file is a single line with the version. Fix the reports to include the version. Update the INI file support to include the details of the build. Show the GIT or released version when the command starts. Closes #2480.
Diffstat (limited to 'source-builder/sb/version.py')
-rw-r--r--source-builder/sb/version.py66
1 files changed, 61 insertions, 5 deletions
diff --git a/source-builder/sb/version.py b/source-builder/sb/version.py
index 802fafa..95b58cf 100644
--- a/source-builder/sb/version.py
+++ b/source-builder/sb/version.py
@@ -1,6 +1,6 @@
#
# RTEMS Tools Project (http://www.rtems.org/)
-# Copyright 2010-2014 Chris Johns (chrisj@rtems.org)
+# Copyright 2010-2015 Chris Johns (chrisj@rtems.org)
# All rights reserved.
#
# This file is part of the RTEMS Tools package in 'rtems-tools'.
@@ -18,17 +18,73 @@
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
-# Manage paths locally. The internally the path is in Unix or shell format and
-# we convert to the native format when performing operations at the Python
-# level. This allows macro expansion to work.
+# To release the RSB create a git archive and then add a suitable VERSION file
+# to the top directory.
#
+import sys
+
+import error
+import git
+import path
+
major = 4
minor = 11
revision = 0
+#
+# Default to an internal string.
+#
+_version_str = '%d.%d.%d' % (major, minor, revision)
+_released = False
+_git = False
+
+def _top():
+ top = path.dirname(sys.argv[0])
+ if len(top) == 0:
+ top = '.'
+ return top
+
+def _load_released_version():
+ global _released
+ global _version_str
+ top = _top()
+ for ver in [top, '..']:
+ if path.exists(path.join(ver, 'VERSION')):
+ try:
+ with open(path.join(ver, 'VERSION')) as v:
+ _version_str = v.readline().strip()
+ v.close()
+ _released = True
+ except:
+ raise error.general('Cannot access the VERSION file')
+ return _released
+
+def _load_git_version():
+ global _git
+ global _version_str
+ repo = git.repo(_top())
+ if repo.valid():
+ head = repo.head()
+ if repo.dirty():
+ modified = ' modified'
+ else:
+ modified = ''
+ _version_str = '%d.%d.%d (%s%s)' % (major, minor, revision, head[0:12], modified)
+ _git = True
+ return _git
+
+def released():
+ return _load_released_version()
+
+def version_control():
+ return _load_git_version()
+
def str():
- return '%d.%d.%d'% (major, minor, revision)
+ if not _released and not _git:
+ if not _load_released_version():
+ _load_git_version()
+ return _version_str
if __name__ == '__main__':
print 'major = %d' % (major)