From 55a2bb55361ae3f1b46c542167069e85e66b1e74 Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Tue, 19 Jan 2021 14:13:03 +0100 Subject: [PATCH] Generate a hwdb instead of udev rules We only use the rules/hwdb to enable auto-suspend. So, instead of shipping our own rules, we can just use the existing autosuspend rules and ship a hwdb that sets the appropriate flag. Closes: #336 --- ...nt-list-udev-rules.c => fprint-list-udev-hwdb.c} | 13 ++++++++----- libfprint/meson.build | 10 +++++----- meson.build | 6 +++--- meson_options.txt | 4 ++-- tests/meson.build | 4 ++-- 5 files changed, 20 insertions(+), 17 deletions(-) rename libfprint/{fprint-list-udev-rules.c => fprint-list-udev-hwdb.c} (93%) diff --git a/libfprint/fprint-list-udev-rules.c b/libfprint/fprint-list-udev-hwdb.c similarity index 93% rename from libfprint/fprint-list-udev-rules.c rename to libfprint/fprint-list-udev-hwdb.c index e574cac..1553db4 100644 --- a/libfprint/fprint-list-udev-rules.c +++ b/libfprint/fprint-list-udev-hwdb.c @@ -147,17 +147,20 @@ print_driver (const FpDeviceClass *cls) g_hash_table_insert (printed, key, (void *) cls->id); if (num_printed == 0) - g_print ("# %s\n", cls->full_name); + { + if (cls != &whitelist) + g_print ("\n# Supported by libfprint driver %s\n", cls->id); + else + g_print ("\n# Known unsupported devices\n"); + } - g_print ("SUBSYSTEM==\"usb\", ATTRS{idVendor}==\"%04x\", ATTRS{idProduct}==\"%04x\", ATTRS{dev}==\"*\", TEST==\"power/control\", ATTR{power/control}=\"auto\"\n", + g_print ("usb:v%04Xp%04X*\n", entry->vid, entry->pid); - g_print ("SUBSYSTEM==\"usb\", ATTRS{idVendor}==\"%04x\", ATTRS{idProduct}==\"%04x\", ENV{LIBFPRINT_DRIVER}=\"%s\"\n", - entry->vid, entry->pid, cls->full_name); num_printed++; } if (num_printed > 0) - g_print ("\n"); + g_print (" ID_AUTOSUSPEND=1\n"); } int diff --git a/libfprint/meson.build b/libfprint/meson.build index 4d1d30c..e385ce8 100644 --- a/libfprint/meson.build +++ b/libfprint/meson.build @@ -295,19 +295,19 @@ libfprint_private_dep = declare_dependency( ] ) -udev_rules = executable('fprint-list-udev-rules', - 'fprint-list-udev-rules.c', +udev_hwdb = executable('fprint-list-udev-hwdb', + 'fprint-list-udev-hwdb.c', dependencies: libfprint_private_dep, link_with: libfprint_drivers, install: false) if get_option('udev_rules') custom_target('udev-rules', - output: '60-@0@-autosuspend.rules'.format(versioned_libname), + output: '60-autosuspend-@0@.hwdb'.format(versioned_libname), capture: true, - command: [ udev_rules ], + command: [ udev_hwdb ], install: true, - install_dir: udev_rules_dir) + install_dir: udev_hwdb_dir) endif supported_devices = executable('fprint-list-supported-devices', diff --git a/meson.build b/meson.build index 139c571..0d4822d 100644 --- a/meson.build +++ b/meson.build @@ -175,11 +175,11 @@ drivers_type_func += '}' root_inc = include_directories('.') if get_option('udev_rules') - udev_rules_dir = get_option('udev_rules_dir') + udev_hwdb_dir = get_option('udev_hwdb_dir') - if udev_rules_dir == 'auto' + if udev_hwdb_dir == 'auto' udev_dep = dependency('udev') - udev_rules_dir = udev_dep.get_pkgconfig_variable('udevdir') + '/rules.d' + udev_hwdb_dir = udev_dep.get_pkgconfig_variable('udevdir') + '/hwdb.d' endif endif diff --git a/meson_options.txt b/meson_options.txt index 746efdc..414695f 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -10,8 +10,8 @@ option('udev_rules', description: 'Whether to create a udev rules file', type: 'boolean', value: true) -option('udev_rules_dir', - description: 'Installation path for udev rules', +option('udev_hwdb_dir', + description: 'Installation path for udev hwdb', type: 'string', value: 'auto') option('gtk-examples', diff --git a/tests/meson.build b/tests/meson.build index f9603b8..537a00a 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -169,8 +169,8 @@ foreach test_name: unit_tests endforeach # Run udev rule generator with fatal warnings -test('udev-rules', - udev_rules, +test('udev-hwdb', + udev_hwdb, env: envs) gdb = find_program('gdb', required: false)