diff options
Diffstat (limited to 'meta-linaro-toolchain/conf/distro/include/external-linaro-toolchain-versions.inc')
-rw-r--r-- | meta-linaro-toolchain/conf/distro/include/external-linaro-toolchain-versions.inc | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/meta-linaro-toolchain/conf/distro/include/external-linaro-toolchain-versions.inc b/meta-linaro-toolchain/conf/distro/include/external-linaro-toolchain-versions.inc new file mode 100644 index 0000000..6165520 --- /dev/null +++ b/meta-linaro-toolchain/conf/distro/include/external-linaro-toolchain-versions.inc | |||
@@ -0,0 +1,111 @@ | |||
1 | def elt_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 | |||
16 | def elt_get_version(d): | ||
17 | try: | ||
18 | stdout, stderr = elt_run(d, 'gcc', '-v') | ||
19 | except bb.process.CmdError as exc: | ||
20 | bb.error('Failed to obtain external Linaro toolchain version: %s' % exc) | ||
21 | return 'UNKNOWN' | ||
22 | else: | ||
23 | last_line = stderr.splitlines()[-1] | ||
24 | return last_line | ||
25 | |||
26 | def elt_get_main_version(d): | ||
27 | version = elt_get_version(d) | ||
28 | if version != 'UNKNOWN': | ||
29 | if version.split()[5] != '(crosstool-NG': | ||
30 | return version.split()[7].split(')')[0] | ||
31 | else: | ||
32 | return version.split()[6].split('-')[3] | ||
33 | else: | ||
34 | return version | ||
35 | |||
36 | def elt_get_gcc_version(d): | ||
37 | version = elt_get_version(d) | ||
38 | if version != 'UNKNOWN': | ||
39 | return version.split()[2] | ||
40 | else: | ||
41 | return version | ||
42 | |||
43 | def elt_get_libc_version(d): | ||
44 | import os,bb | ||
45 | syspath = bb.data.expand('${EXTERNAL_TOOLCHAIN}/${ELT_TARGET_SYS}', d) | ||
46 | if not syspath: | ||
47 | return 'UNKNOWN' | ||
48 | |||
49 | libpath = syspath + '/libc/lib/' + bb.data.expand('${ELT_TARGET_SYS}/', d) | ||
50 | |||
51 | if os.path.exists(libpath): | ||
52 | for file in os.listdir(libpath): | ||
53 | if file.find('libc-') == 0: | ||
54 | return file[5:-3] | ||
55 | |||
56 | libpath = syspath + '/libc/lib/' | ||
57 | |||
58 | if os.path.exists(libpath): | ||
59 | for file in os.listdir(libpath): | ||
60 | if file.find('libc-') == 0: | ||
61 | return file[5:-3] | ||
62 | return 'UNKNOWN' | ||
63 | |||
64 | def elt_get_kernel_version(d): | ||
65 | import os,bb | ||
66 | syspath = bb.data.expand('${EXTERNAL_TOOLCHAIN}/${ELT_TARGET_SYS}', d) | ||
67 | if not syspath: | ||
68 | return 'UNKNOWN' | ||
69 | |||
70 | vf = syspath + '/libc/usr/include/linux/version.h' | ||
71 | |||
72 | try: | ||
73 | f = open(vf, 'r') | ||
74 | except (OSError, IOError): | ||
75 | return 'UNKNOWN' | ||
76 | |||
77 | l = f.readlines(); | ||
78 | f.close(); | ||
79 | for s in l: | ||
80 | if s.find('LINUX_VERSION_CODE') > 0: | ||
81 | ver = int(s.split()[2]) | ||
82 | maj = ver / 65536 | ||
83 | ver = ver % 65536 | ||
84 | min = ver / 256 | ||
85 | ver = ver % 256 | ||
86 | return str(maj)+'.'+str(min)+'.'+str(ver) | ||
87 | return 'UNKNOWN' | ||
88 | |||
89 | def elt_get_gdb_version(d): | ||
90 | try: | ||
91 | stdout, stderr = elt_run(d, 'gdb', '-v') | ||
92 | except bb.process.CmdError: | ||
93 | return 'UNKNOWN' | ||
94 | else: | ||
95 | first_line = stdout.splitlines()[0] | ||
96 | return first_line.split()[-1] | ||
97 | |||
98 | python external_linaro_toolchain_version_handler () { | ||
99 | if not isinstance(e, bb.event.ConfigParsed): | ||
100 | return | ||
101 | d = e.data | ||
102 | ld = d.createCopy() | ||
103 | ld.finalize() | ||
104 | |||
105 | d.setVar('ELT_VER_MAIN', elt_get_main_version(ld)) | ||
106 | d.setVar('ELT_VER_GCC', elt_get_gcc_version(ld)) | ||
107 | d.setVar('ELT_VER_LIBC', elt_get_libc_version(ld)) | ||
108 | d.setVar('ELT_VER_KERNEL', elt_get_kernel_version(ld)) | ||
109 | d.setVar('ELT_VER_GDB', elt_get_gdb_version(ld)) | ||
110 | } | ||
111 | addhandler external_linaro_toolchain_version_handler | ||