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