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