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
|
#!/usr/bin/python3
# Copyright 2021 Simon McVittie
# SPDX-License-Identifier: MIT
'''
Inspect libffi-dev:$DEB_HOST_ARCH and print the corresponding library ABI
name, e.g. "gobjectintrospection:libffiN=libffi8".
'''
import os
import subprocess
import debian.deb822
if __name__ == '__main__':
deb_host_arch = os.environ['DEB_HOST_ARCH']
result = subprocess.run(
['dpkg-query', '-s', 'libffi-dev:' + deb_host_arch],
stdout=subprocess.PIPE,
check=True,
)
stanza = result.stdout.decode('utf-8') # type: ignore
fields = debian.deb822.Packages(stanza)
libffiN = ''
for dependency in fields.relations['depends']:
for alternative in dependency:
if (
alternative['name'].startswith('libffi')
and alternative['name'][6].isdigit()
):
if libffiN != '':
raise AssertionError(
'More than one libffiN dependency in libffi-dev'
)
libffiN = alternative['name']
if not libffiN:
raise AssertionError(
'No libffiN dependency in libffi-dev'
)
print('gobjectintrospection:libffiN=' + libffiN)
|