summaryrefslogtreecommitdiffstats
path: root/meta/conf/distro/include/csl-versions.inc
diff options
context:
space:
mode:
authorChristopher Larson <chris_larson@mentor.com>2012-01-27 11:13:48 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-02-03 16:17:16 +0000
commita29939639b0ad5dfb57fac6588e65c095ed448f6 (patch)
tree2bfe5cfbad19471b1792f703b353f3b1b47adf79 /meta/conf/distro/include/csl-versions.inc
parent79e48d853b540cc2626b957f98f67fc72d98a917 (diff)
downloadpoky-a29939639b0ad5dfb57fac6588e65c095ed448f6.tar.gz
external-csl-toolchain: extract version info from the toolchain
(From OE-Core rev: ba59a35cd2b7a0cb5903146d991f5d7f535f4f19) Signed-off-by: Christopher Larson <chris_larson@mentor.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/conf/distro/include/csl-versions.inc')
-rw-r--r--meta/conf/distro/include/csl-versions.inc105
1 files changed, 105 insertions, 0 deletions
diff --git a/meta/conf/distro/include/csl-versions.inc b/meta/conf/distro/include/csl-versions.inc
new file mode 100644
index 0000000000..22e83946a1
--- /dev/null
+++ b/meta/conf/distro/include/csl-versions.inc
@@ -0,0 +1,105 @@
1def csl_run(d, cmd, *args):
2 import bb.process
3 import subprocess
4
5 topdir = d.getVar('TOPDIR', True)
6 toolchain_path = d.getVar('EXTERNAL_TOOLCHAIN', True)
7 if not toolchain_path:
8 return 'UNKNOWN', 'UNKNOWN'
9
10 target_prefix = d.getVar('TARGET_PREFIX', True)
11 path = os.path.join(toolchain_path, 'bin', target_prefix + cmd)
12 args = [path] + list(args)
13
14 return bb.process.run(args, cwd=topdir, stderr=subprocess.PIPE)
15
16def csl_get_version(d):
17 try:
18 stdout, stderr = csl_run(d, 'gcc', '-v')
19 except bb.process.CmdError as exc:
20 bb.error('Failed to obtain CodeSourcery toolchain version: %s' % exc)
21 return 'UNKNOWN'
22 else:
23 last_line = stderr.splitlines()[-1]
24 return last_line
25
26def csl_get_main_version(d):
27 version = csl_get_version(d)
28 if version != 'UNKNOWN':
29 return version.split()[-1].rstrip(')')
30 else:
31 return version
32
33def csl_get_gcc_version(d):
34 version = csl_get_version(d)
35 if version != 'UNKNOWN':
36 return version.split()[2]
37 else:
38 return version
39
40def csl_get_libc_version(d):
41 import os,bb
42 syspath = bb.data.expand('${EXTERNAL_TOOLCHAIN}/${CSL_TARGET_SYS}', d)
43 if not syspath:
44 return 'UNKNOWN'
45
46 libpath = syspath + '/libc/lib/'
47 if not os.path.exists(libpath):
48 libpath = syspath + '/libc/sgxx-glibc/lib/'
49
50 if os.path.exists(libpath):
51 for file in os.listdir(libpath):
52 if file.find('libc-') == 0:
53 return file[5:-3]
54 return 'UNKNOWN'
55
56def csl_get_kernel_version(d):
57 import os,bb
58 syspath = bb.data.expand('${EXTERNAL_TOOLCHAIN}/${CSL_TARGET_SYS}', d)
59 if not syspath:
60 return 'UNKNOWN'
61
62 vf = syspath + '/libc/usr/include/linux/version.h'
63 if not os.path.exists(vf):
64 vf = syspath + '/libc/sgxx-glibc/usr/include/linux/version.h'
65
66 try:
67 f = open(vf, 'r')
68 except (OSError, IOError):
69 return 'UNKNOWN'
70
71 l = f.readlines();
72 f.close();
73 for s in l:
74 if s.find('LINUX_VERSION_CODE') > 0:
75 ver = int(s.split()[2])
76 maj = ver / 65536
77 ver = ver % 65536
78 min = ver / 256
79 ver = ver % 256
80 return str(maj)+'.'+str(min)+'.'+str(ver)
81 return 'UNKNOWN'
82
83def csl_get_gdb_version(d):
84 try:
85 stdout, stderr = csl_run(d, 'gdb', '-v')
86 except CmdError:
87 return 'UNKNOWN'
88 else:
89 first_line = stdout.splitlines()[0]
90 return first_line.split()[-1]
91
92python csl_version_handler () {
93 if not isinstance(e, bb.event.ConfigParsed):
94 return
95 d = e.data
96 ld = d.createCopy()
97 ld.finalize()
98
99 d.setVar('CSL_VER_MAIN', csl_get_main_version(ld))
100 d.setVar('CSL_VER_GCC', csl_get_gcc_version(ld))
101 d.setVar('CSL_VER_LIBC', csl_get_libc_version(ld))
102 d.setVar('CSL_VER_KERNEL', csl_get_kernel_version(ld))
103 d.setVar('CSL_VER_GDB', csl_get_gdb_version(ld))
104}
105addhandler csl_version_handler