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 | |
---|
25 | from __future__ import print_function |
---|
26 | |
---|
27 | import sys |
---|
28 | |
---|
29 | import error |
---|
30 | import git |
---|
31 | import path |
---|
32 | import 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 | |
---|
43 | def _top(): |
---|
44 | top = path.dirname(sys.argv[0]) |
---|
45 | if len(top) == 0: |
---|
46 | top = '.' |
---|
47 | return top |
---|
48 | |
---|
49 | def _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 | |
---|
59 | def _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 | |
---|
68 | def _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 | |
---|
82 | def released(): |
---|
83 | return _load_released_version() |
---|
84 | |
---|
85 | def version_control(): |
---|
86 | return _load_git_version() |
---|
87 | |
---|
88 | def str(): |
---|
89 | if not _released and not _git: |
---|
90 | if not _load_released_version(): |
---|
91 | _load_git_version() |
---|
92 | return _version_str |
---|
93 | |
---|
94 | def 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 | |
---|
111 | if __name__ == '__main__': |
---|
112 | print('Version: %s' % (str())) |
---|