aboutsummaryrefslogtreecommitdiff
path: root/meta-linaro-toolchain/conf/distro/include/external-linaro-toolchain-versions.inc
blob: eb5a0f88624d5730e23f4e5c1014b707bb171b5d (plain)
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
def elt_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 elt_get_version(d):
	try:
		stdout, stderr = elt_run(d, 'gcc', '-v')
	except bb.process.CmdError as exc:
		bb.error('Failed to obtain external Linaro toolchain version: %s' % exc)
		return 'UNKNOWN'
	else:
		last_line = stderr.splitlines()[-1]
		return last_line

def elt_get_main_version(d):
	version = elt_get_version(d)
	if version != 'UNKNOWN':
		if version.split()[5] != '(crosstool-NG':
			return version.split()[7].split(')')[0]
		else:
			return version.split()[6].split('-')[3]
	else:
		return version

def elt_get_gcc_version(d):
	version = elt_get_version(d)
	if version != 'UNKNOWN':
		return version.split()[2]
	else:
		return version

def elt_get_libc_version(d):
	import os,bb
	syspath = bb.data.expand('${EXTERNAL_TOOLCHAIN}/${ELT_TARGET_SYS}', d)
	if not syspath:
		return 'UNKNOWN'

	libpath = syspath + '/libc/lib/' + bb.data.expand('${ELT_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/lib/'

	if os.path.exists(libpath):
		for file in os.listdir(libpath):
			if file.find('libc-') == 0:
				return file[5:-3]

	libpath = syspath + '/libc/usr/lib/' + bb.data.expand('${ELT_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/lib/'

	if os.path.exists(libpath):
		for file in os.listdir(libpath):
			if file.find('libc-') == 0:
				return file[5:-3]
	return 'UNKNOWN'

def elt_get_kernel_version(d):
	import os,bb
	syspath = bb.data.expand('${EXTERNAL_TOOLCHAIN}/${ELT_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 elt_get_gdb_version(d):
	try:
		stdout, stderr = elt_run(d, 'gdb', '-v')
	except bb.process.CmdError:
		return 'UNKNOWN'
	else:
		first_line = stdout.splitlines()[0]
		return first_line.split()[-1]

python external_linaro_toolchain_version_handler () {
	if not isinstance(e, bb.event.ConfigParsed):
		return
	d = e.data
	ld = d.createCopy()
	ld.finalize()

	d.setVar('ELT_VER_MAIN', elt_get_main_version(ld))
	d.setVar('ELT_VER_GCC', elt_get_gcc_version(ld))
	d.setVar('ELT_VER_LIBC', elt_get_libc_version(ld))
	d.setVar('ELT_VER_KERNEL', elt_get_kernel_version(ld))
	d.setVar('ELT_VER_GDB', elt_get_gdb_version(ld))
}
addhandler external_linaro_toolchain_version_handler