aboutsummaryrefslogtreecommitdiff
path: root/meta-linaro-toolchain/conf/distro/include/external-arm-toolchain-versions.inc
diff options
context:
space:
mode:
Diffstat (limited to 'meta-linaro-toolchain/conf/distro/include/external-arm-toolchain-versions.inc')
-rw-r--r--meta-linaro-toolchain/conf/distro/include/external-arm-toolchain-versions.inc128
1 files changed, 128 insertions, 0 deletions
diff --git a/meta-linaro-toolchain/conf/distro/include/external-arm-toolchain-versions.inc b/meta-linaro-toolchain/conf/distro/include/external-arm-toolchain-versions.inc
new file mode 100644
index 00000000..7064d6b3
--- /dev/null
+++ b/meta-linaro-toolchain/conf/distro/include/external-arm-toolchain-versions.inc
@@ -0,0 +1,128 @@
+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]
+ 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/lib64/' + bb.data.expand('${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/lib64/'
+
+ if os.path.exists(libpath):
+ for file in os.listdir(libpath):
+ if file.find('libc-') == 0:
+ return file[5:-3]
+
+ libpath = syspath + '/libc/usr/lib64/' + bb.data.expand('${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/lib64/'
+
+ 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