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 download |
---|
30 | import error |
---|
31 | import git |
---|
32 | import path |
---|
33 | import sources |
---|
34 | |
---|
35 | # |
---|
36 | # Default to an internal string. |
---|
37 | # |
---|
38 | _version = '4.11' |
---|
39 | _revision = 'not_released' |
---|
40 | _version_str = '%s.%s' % (_version, _revision) |
---|
41 | _released = False |
---|
42 | _git = False |
---|
43 | |
---|
44 | def _top(): |
---|
45 | top = path.dirname(sys.argv[0]) |
---|
46 | if len(top) == 0: |
---|
47 | top = '.' |
---|
48 | return top |
---|
49 | |
---|
50 | def _load_released_version_config(): |
---|
51 | top = _top() |
---|
52 | for ver in [top, '..']: |
---|
53 | if path.exists(path.join(ver, 'VERSION')): |
---|
54 | try: |
---|
55 | import configparser |
---|
56 | except ImportError: |
---|
57 | import ConfigParser as configparser |
---|
58 | v = configparser.SafeConfigParser() |
---|
59 | try: |
---|
60 | v.read(path.join(ver, 'VERSION')) |
---|
61 | except: |
---|
62 | raise error.general('Invalid VERSION file') |
---|
63 | return v |
---|
64 | return None |
---|
65 | |
---|
66 | def _load_released_version(): |
---|
67 | global _released |
---|
68 | global _version_str |
---|
69 | v = _load_released_version_config() |
---|
70 | if v is not None: |
---|
71 | try: |
---|
72 | _version_str = v.get('version', 'release') |
---|
73 | except: |
---|
74 | raise error.general('Invalid VERSION file') |
---|
75 | _released = True |
---|
76 | return _released |
---|
77 | |
---|
78 | def _load_git_version(): |
---|
79 | global _git |
---|
80 | global _version_str |
---|
81 | repo = git.repo(_top()) |
---|
82 | if repo.valid(): |
---|
83 | head = repo.head() |
---|
84 | if repo.dirty(): |
---|
85 | modified = ' modified' |
---|
86 | else: |
---|
87 | modified = '' |
---|
88 | _version_str = '%s (%s%s)' % (_version, head[0:12], modified) |
---|
89 | _git = True |
---|
90 | return _git |
---|
91 | |
---|
92 | def released(): |
---|
93 | return _load_released_version() |
---|
94 | |
---|
95 | def version_control(): |
---|
96 | return _load_git_version() |
---|
97 | |
---|
98 | def str(): |
---|
99 | if not _released and not _git: |
---|
100 | if not _load_released_version(): |
---|
101 | _load_git_version() |
---|
102 | return _version_str |
---|
103 | |
---|
104 | def load_release_settings(macros): |
---|
105 | def setting_error(msg): |
---|
106 | raise error.general(msg) |
---|
107 | |
---|
108 | if released(): |
---|
109 | v = _load_released_version_config() |
---|
110 | if v is not None: |
---|
111 | try: |
---|
112 | hashes = v.items('hashes') |
---|
113 | except: |
---|
114 | hashes = [] |
---|
115 | try: |
---|
116 | release_path = v.get('version', 'release_path', raw = True) |
---|
117 | except: |
---|
118 | release_path = None |
---|
119 | for hash in hashes: |
---|
120 | hs = hash[1].split() |
---|
121 | if len(hs) != 2: |
---|
122 | raise error.general('invalid release hash in VERSION') |
---|
123 | sources.hash((hs[0], hash[0], hs[1]), macros, setting_error) |
---|
124 | download.set_release_path(release_path, macros) |
---|
125 | |
---|
126 | def version(): |
---|
127 | return _version |
---|
128 | |
---|
129 | if __name__ == '__main__': |
---|
130 | print('Version: %s' % (str())) |
---|