source: rtems-source-builder/source-builder/sb/version.py @ 4dce089

4.11
Last change on this file since 4dce089 was 4dce089, checked in by Chris Johns <chrisj@…>, on Dec 11, 2015 at 7:28:26 AM

A VERSION file may have no hashes.

  • Property mode set to 100644
File size: 3.0 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
30import sources
31
32#
33# Default to an internal string.
34#
35_version = '4.11'
36_revision = 'not_released'
37_version_str = '%s.%s' % (_version, _revision)
38_released = False
39_git = False
40
41def _top():
42    top = path.dirname(sys.argv[0])
43    if len(top) == 0:
44        top = '.'
45    return top
46
47def _load_released_version_config():
48    top = _top()
49    for ver in [top, '..']:
50        if path.exists(path.join(ver, 'VERSION')):
51            import ConfigParser
52            v = ConfigParser.SafeConfigParser()
53            v.read(path.join(ver, 'VERSION'))
54            return v
55    return None
56
57def _load_released_version():
58    global _released
59    global _version_str
60    v = _load_released_version_config()
61    if v is not None:
62        _version_str = v.get('version', 'release')
63        _released = True
64    return _released
65
66def _load_git_version():
67    global _git
68    global _version_str
69    repo = git.repo(_top())
70    if repo.valid():
71        head = repo.head()
72        if repo.dirty():
73            modified = ' modified'
74        else:
75            modified = ''
76        _version_str = '%s (%s%s)' % (_version, head[0:12], modified)
77        _git = True
78    return _git
79
80def released():
81    return _load_released_version()
82
83def version_control():
84    return _load_git_version()
85
86def str():
87    if not _released and not _git:
88        if not _load_released_version():
89            _load_git_version()
90    return _version_str
91
92def load_release_hashes(macros):
93    def hash_error(msg):
94        raise error.general(msg)
95
96    if released():
97        v = _load_released_version_config()
98        if v is not None:
99            try:
100                hashes = v.items('hashes')
101            except:
102                hashes = []
103            for hash in hashes:
104                hs = hash[1].split()
105                if len(hs) != 2:
106                    raise error.general('invalid release hash in VERSION')
107                sources.hash((hs[0], hash[0], hs[1]), macros, hash_error)
108
109if __name__ == '__main__':
110    print 'Version: %s' % (str())
Note: See TracBrowser for help on using the repository browser.