1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
def eat_run(d, cmd, *args):
import bb.process
import subprocess
topdir = d.getVar('TOPDIR', True)
toolchain_path = d.getVar('EXTERNAL_TOOLCHAIN', True)
if not toolchain_path:
return 'UNKNOWN', 'UNKNOWN'
target_prefix = d.getVar('TARGET_PREFIX', True)
path = os.path.join(toolchain_path, 'bin', target_prefix + cmd)
args = [path] + list(args)
return bb.process.run(args, cwd=topdir, stderr=subprocess.PIPE)
def eat_get_version(d):
try:
stdout, stderr = eat_run(d, 'gcc', '-v')
except bb.process.CmdError as exc:
bb.error('Failed to obtain external Arm toolchain version: %s' % exc)
return 'UNKNOWN'
else:
last_line = stderr.splitlines()[-1]
return last_line
# Extract the YYYY.MM version
def eat_get_main_version(d):
version = eat_get_version(d)
bb.debug(2, 'Trying for parse version info from: %s' % version)
if version != 'UNKNOWN':
if version.split()[4] == '(GNU':
# gcc version 8.2.1 20180802 (GNU Toolchain for the A-profile Architecture 8.2-2018.11 (arm-rel-8.26))
return version.split()[10].split('-')[1]
elif version.split()[3] == '(GNU':
# gcc version 8.3.0 (GNU Toolchain for the A-profile Architecture 8.3-2019.03 (arm-rel-8.36))
return version.split()[9].split('-')[1]
else:
bb.error('Failed to parse external Arm toolchain version from: %s' % version)
else:
return version
# Extract the x.y.z version from 'gcc version 4.9.1'
def eat_get_gcc_version(d):
version = eat_get_version(d)
if version != 'UNKNOWN':
return version.split()[2]
else:
return version
def eat_get_libc_version(d):
import os,bb
syspath = bb.data.expand('${EXTERNAL_TOOLCHAIN}/${EAT_TARGET_SYS}', d)
if not syspath:
return 'UNKNOWN'
libpath = syspath + '/libc/' + bb.data.expand('${EAT_LIBDIR}/${EAT_TARGET_SYS}/', d)
if os.path.exists(libpath):
for file in os.listdir(libpath):
if file.find('libc-') == 0:
return file[5:-3]
libpath = syspath + '/libc/' + bb.data.expand('${EAT_LIBDIR}/', d)
if os.path.exists(libpath):
for file in os.listdir(libpath):
if file.find('libc-') == 0:
return file[5:-3]
libpath = syspath + '/libc/usr/' + bb.data.expand('${EAT_LIBDIR}/${EAT_TARGET_SYS}/', d)
if os.path.exists(libpath):
for file in os.listdir(libpath):
if file.find('libc-') == 0:
return file[5:-3]
libpath = syspath + '/libc/usr/' + bb.data.expand('${EAT_LIBDIR}/', d)
if os.path.exists(libpath):
for file in os.listdir(libpath):
if file.find('libc-') == 0:
return file[5:-3]
return 'UNKNOWN'
def eat_get_kernel_version(d):
import os,bb
syspath = bb.data.expand('${EXTERNAL_TOOLCHAIN}/${EAT_TARGET_SYS}', d)
if not syspath:
return 'UNKNOWN'
vf = syspath + '/libc/usr/include/linux/version.h'
try:
f = open(vf, 'r')
except (OSError, IOError):
return 'UNKNOWN'
l = f.readlines();
f.close();
for s in l:
if s.find('LINUX_VERSION_CODE') > 0:
ver = int(s.split()[2])
maj = ver / 65536
ver = ver % 65536
min = ver / 256
ver = ver % 256
return str(maj)+'.'+str(min)+'.'+str(ver)
return 'UNKNOWN'
def eat_get_gdb_version(d):
try:
stdout, stderr = eat_run(d, 'gdb', '-v')
except bb.process.CmdError:
return 'UNKNOWN'
else:
first_line = stdout.splitlines()[0]
return first_line.split()[-1]
python external_arm_toolchain_version_handler () {
if not isinstance(e, bb.event.ConfigParsed):
return
d = e.data
ld = d.createCopy()
ld.finalize()
d.setVar('EAT_VER_MAIN', eat_get_main_version(ld))
d.setVar('EAT_VER_GCC', eat_get_gcc_version(ld))
d.setVar('EAT_VER_LIBC', eat_get_libc_version(ld))
d.setVar('EAT_VER_KERNEL', eat_get_kernel_version(ld))
d.setVar('EAT_VER_GDB', eat_get_gdb_version(ld))
}
addhandler external_arm_toolchain_version_handler
|