diff --git a/libfprint/fprint-list-udev-hwdb.c b/libfprint/fprint-list-udev-hwdb.c index 1dc0067f..55a71cd6 100644 --- a/libfprint/fprint-list-udev-hwdb.c +++ b/libfprint/fprint-list-udev-hwdb.c @@ -26,9 +26,10 @@ static const FpIdEntry allowlist_id_table[] = { /* Currently known and unsupported devices. - * You can generate this list from the wiki page using e.g.: - * gio cat https://gitlab.freedesktop.org/libfprint/wiki/-/wikis/Unsupported-Devices.md | sed -n 's!|.*\([0-9a-fA-F]\{4\}\):\([0-9a-fA-F]\{4\}\).*|.*! { .vid = 0x\1, .pid = 0x\2 },!p' + * You can regenerate this list from the wiki page with: + * meson compile -C sync-unsupported-devices */ + /* --- BEGIN GENERATED IDS --- */ { .vid = 0x0a5c, .pid = 0x5802 }, { .vid = 0x047d, .pid = 0x00f2 }, { .vid = 0x047d, .pid = 0x8054 }, @@ -166,6 +167,7 @@ static const FpIdEntry allowlist_id_table[] = { { .vid = 0x298d, .pid = 0x2033 }, { .vid = 0x2df0, .pid = 0x0003 }, { .vid = 0x3538, .pid = 0x0930 }, + /* --- END GENERATED IDS --- */ { .vid = 0 }, }; diff --git a/libfprint/meson.build b/libfprint/meson.build index 19451d2f..790f005f 100644 --- a/libfprint/meson.build +++ b/libfprint/meson.build @@ -301,8 +301,9 @@ libfprint_private_dep = declare_dependency( ] ) +udev_hwdb_list_file = files('fprint-list-udev-hwdb.c') udev_hwdb = executable('fprint-list-udev-hwdb', - 'fprint-list-udev-hwdb.c', + udev_hwdb_list_file, dependencies: libfprint_private_dep, link_with: libfprint_drivers, install: false, @@ -366,6 +367,10 @@ sync_udev_udb = custom_target('sync-udev-hwdb', alias_target('sync-udev-hwdb', sync_udev_udb) +run_target('sync-unsupported-devices', + command: [ sync_unsupported_files, udev_hwdb_list_file ] +) + supported_devices = executable('fprint-list-supported-devices', 'fprint-list-supported-devices.c', dependencies: libfprint_private_dep, diff --git a/meson.build b/meson.build index 11b096b4..3f1d2ecf 100644 --- a/meson.build +++ b/meson.build @@ -11,6 +11,8 @@ project('libfprint', [ 'c', 'cpp' ], fs = import('fs') gnome = import('gnome') +python3 = find_program('python3') + libfprint_conf = configuration_data() libfprint_conf.set_quoted('LIBFPRINT_VERSION', meson.project_version()) @@ -101,6 +103,8 @@ mathlib_dep = cc.find_library('m', required: false) sh = find_program('sh', required: true) cairo_dep = dependency('cairo', required: false) +sync_unsupported_files = files('scripts' / 'sync-unsupported-devices.py') + # introspection scanning and Gio-2.0.gir gobject_introspection = dependency('gobject-introspection-1.0', required: get_option('introspection')) diff --git a/scripts/sync-unsupported-devices.py b/scripts/sync-unsupported-devices.py new file mode 100755 index 00000000..d0b55e17 --- /dev/null +++ b/scripts/sync-unsupported-devices.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 +# +# Update the hardcoded allowlist of currently unsupported devices in +# fprint-list-udev-hwdb.c from the libfprint wiki page. + +import argparse +import re +import sys +from urllib.request import urlopen + +DEFAULT_URL = ( + "https://gitlab.freedesktop.org/libfprint/wiki/-/wikis/Unsupported-Devices.md" +) + +ID_RE = re.compile(r"\|.*([0-9a-fA-F]{4}):([0-9a-fA-F]{4}).*\|.*") + +BEGIN_MARKER = " /* --- BEGIN GENERATED IDS --- */\n" +END_MARKER = " /* --- END GENERATED IDS --- */\n" + + +def fetch(url): + try: + with urlopen(url) as response: + return response.read().decode("utf-8") + except OSError as exc: + print(f"Could not download {url}: {exc}", file=sys.stderr) + sys.exit(77) + + +def parse_entries(text): + devices = set() + for line in text.splitlines(): + match = ID_RE.match(line) + if match: + devices.add((match.group(1).lower(), match.group(2).lower())) + return [f" {{ .vid = 0x{vid}, .pid = 0x{pid} }}," for vid, pid in sorted(devices)] + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("source_file", help="Path to hwdb file") + parser.add_argument("--url", default=DEFAULT_URL, help="Wiki page URL") + args = parser.parse_args() + + entries = parse_entries(fetch(args.url)) + if not entries: + sys.exit("No device ids found on the wiki page") + + with open(args.source_file, "r", encoding="utf-8") as f: + content = f.read() + + before, begin, rest = content.partition(BEGIN_MARKER) + _, end, after = rest.partition(END_MARKER) + if not begin or not end: + sys.exit("Could not locate generated id markers in " + args.source_file) + + block = BEGIN_MARKER + "\n".join(entries) + "\n" + END_MARKER + new_content = before + block + after + + if new_content == content: + print("allowlist_id_table is already up to date") + return + + with open(args.source_file, "w", encoding="utf-8") as f: + f.write(new_content) + + print(f"Updated allowlist_id_table with {len(entries)} entries") + + +if __name__ == "__main__": + main() diff --git a/tests/meson.build b/tests/meson.build index 5f7eaab3..aad0675e 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -26,8 +26,6 @@ envs.set('FP_PRINTS_PATH', meson.project_source_root() / 'examples' / 'prints') envs.set('NO_AT_BRIDGE', '1') -python3 = find_program('python3') - installed_tests = get_option('installed-tests') installed_tests_execdir = libexecdir / 'installed-tests' / versioned_libname installed_tests_testdir = datadir / 'installed-tests' / versioned_libname