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 | |
---|
25 | import sys |
---|
26 | |
---|
27 | import error |
---|
28 | import git |
---|
29 | import path |
---|
30 | |
---|
31 | major = 4 |
---|
32 | minor = 11 |
---|
33 | revision = 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 | |
---|
42 | def _top(): |
---|
43 | top = path.dirname(sys.argv[0]) |
---|
44 | if len(top) == 0: |
---|
45 | top = '.' |
---|
46 | return top |
---|
47 | |
---|
48 | def _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 | |
---|
63 | def _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 | |
---|
77 | def released(): |
---|
78 | return _load_released_version() |
---|
79 | |
---|
80 | def version_control(): |
---|
81 | return _load_git_version() |
---|
82 | |
---|
83 | def str(): |
---|
84 | if not _released and not _git: |
---|
85 | if not _load_released_version(): |
---|
86 | _load_git_version() |
---|
87 | return _version_str |
---|
88 | |
---|
89 | if __name__ == '__main__': |
---|
90 | print 'major = %d' % (major) |
---|
91 | print 'minor = %d' % (minor) |
---|
92 | print 'revision = %d' % (revision) |
---|
93 | print 'Version: %s' % (str()) |
---|