File: generate-plugins-header.py

package info (click to toggle)
fwupd 2.0.20-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 32,504 kB
  • sloc: ansic: 277,388; python: 11,485; xml: 9,493; sh: 1,625; makefile: 167; cpp: 19; asm: 11; javascript: 9
file content (42 lines) | stat: -rw-r--r-- 1,165 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python3
# pylint: disable=invalid-name,missing-docstring
#
# Copyright 2022 Richard Hughes <richard@hughsie.com>
#
# SPDX-License-Identifier: LGPL-2.1-or-later

import sys

if len(sys.argv) < 3:
    print("not enough arguments")
    sys.exit(1)

with open(sys.argv[1], "w") as f:
    # empty argument is no plugins
    plugin_names = []
    if sys.argv[3]:
        for fullpath in sys.argv[3].split(","):
            parts = fullpath.split("/")
            name = parts[-1]
            if name.startswith("libfu_plugin_"):
                name = name[13:]
            if name.endswith(".a"):
                name = name[:-2]
            plugin_names.append((parts[-2], name))

    # includes
    for dirname, name in plugin_names:
        f.write(
            '#include "{srcdir}/plugins/{dirname}/fu-{name}-plugin.h"\n'.format(
                srcdir=sys.argv[2], dirname=dirname, name=name.replace("_", "-")
            )
        )

    # GTypes
    gtypes = [f"fu_{name}_plugin_get_type" for _, name in plugin_names]
    f.write(
        "GType (*fu_plugin_externals[])(void) = { %s };\n"
        % ", ".join(gtypes + ["NULL"])
    )

sys.exit(0)