source: rtems-source-builder/source-builder/sb/version.py @ f88fcf3

4.11
Last change on this file since f88fcf3 was f88fcf3, checked in by Chris Johns <chrisj@…>, on 03/07/16 at 00:56:02

sb: Update code base to support Python3 and Python2.

Fix Windows support to allow MSYS2 Python to be used.

Updates #2619.

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