File: extra-substvars.py

package info (click to toggle)
gobject-introspection 1.84.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 72,336 kB
  • sloc: ansic: 562,269; python: 23,692; xml: 16,240; yacc: 1,711; perl: 1,624; sh: 1,139; lex: 510; cpp: 487; makefile: 182; javascript: 15; lisp: 1
file content (57 lines) | stat: -rwxr-xr-x 1,604 bytes parent folder | download
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
#!/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. "local: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('local:libffiN=' + libffiN)

    for suffix in ('ARCH_OS', 'GNU_TYPE', 'MULTIARCH'):
        var = 'DEB_HOST_' + suffix
        substvar = var.replace('_', '-')
        print(f'local:{substvar}={os.environ[var]}')

    for suffix in ('GNU_TYPE',):
        var = 'DEB_HOST_' + suffix
        substvar = var.replace('_', '-') + '-DASHES'
        value = os.environ[var].replace('_', '-')
        print(f'local:{substvar}={value}')