source: rtems-source-builder/source-builder/sb/version.py @ 47d703fd

4.104.95
Last change on this file since 47d703fd was 47d703fd, checked in by Chris Johns <chrisj@…>, on 12/03/15 at 11:22:17

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.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1#
2# RTEMS Tools Project (http://www.rtems.org/)
3# Copyright 2010-2015 Chris Johns (chrisj@rtems.org)
4# All rights reserved.
5#
6# This file is part of the RTEMS Tools package in 'rtems-tools'.
7#
8# Permission to use, copy, modify, and/or distribute this software for any
9# purpose with or without fee is hereby granted, provided that the above
10# copyright notice and this permission notice appear in all copies.
11#
12# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20#
21# To release the RSB create a git archive and then add a suitable VERSION file
22# to the top directory.
23#
24
25import sys
26
27import error
28import git
29import path
30
31major = 4
32minor = 11
33revision = 0
34
35#
36# Default to an internal string.
37#
38_version_str =  '%d.%d.%d' % (major, minor, revision)
39_released = False
40_git = False
41
42def _top():
43    top = path.dirname(sys.argv[0])
44    if len(top) == 0:
45        top = '.'
46    return top
47
48def _load_released_version():
49    global _released
50    global _version_str
51    top = _top()
52    for ver in [top, '..']:
53        if path.exists(path.join(ver, 'VERSION')):
54            try:
55                with open(path.join(ver, 'VERSION')) as v:
56                    _version_str = v.readline().strip()
57                v.close()
58                _released = True
59            except:
60                raise error.general('Cannot access the VERSION file')
61    return _released
62
63def _load_git_version():
64    global _git
65    global _version_str
66    repo = git.repo(_top())
67    if repo.valid():
68        head = repo.head()
69        if repo.dirty():
70            modified = ' modified'
71        else:
72            modified = ''
73        _version_str = '%d.%d.%d (%s%s)' % (major, minor, revision, head[0:12], modified)
74        _git = True
75    return _git
76
77def released():
78    return _load_released_version()
79
80def version_control():
81    return _load_git_version()
82
83def str():
84    if not _released and not _git:
85        if not _load_released_version():
86            _load_git_version()
87    return _version_str
88
89if __name__ == '__main__':
90    print 'major = %d' % (major)
91    print 'minor = %d' % (minor)
92    print 'revision = %d' % (revision)
93    print 'Version: %s' % (str())
Note: See TracBrowser for help on using the repository browser.