From 99c269b3fe3048d6d7050c9d460cd2ff04090df8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
Date: Thu, 10 Dec 2020 20:22:54 +0100
Subject: [PATCH] meson: Do not support drivers known to fail in Big Endian
 archs

When building in big endian architectures some device tests will fail,
as per this we're pretty sure that most of the drivers are not ready
to work in big-endian architectures.
Since we're aware of this, better to just stop supporting those drivers
instead of having each distribution to handle the problem.

So, add a list of supported drivers that is filled depending the
architecture type we're building on. Keep continue building those
drivers since we want to at least test-build them, but do not expose
them as libfprint drivers, so if a device in the system uses any of them
will be ignored.

At the same time, we keep track of the problem, so that we can fix the
drivers.

Related to #236
---
 meson.build       | 20 +++++++++++++++++++-
 tests/meson.build |  3 ++-
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/meson.build b/meson.build
index cd0d83d..ec5d9a6 100644
--- a/meson.build
+++ b/meson.build
@@ -89,6 +89,7 @@ cairo_dep = dependency('cairo', required: false)
 # Drivers
 drivers = get_option('drivers').split(',')
 virtual_drivers = [ 'virtual_image' ]
+
 default_drivers = [
     'upektc_img',
     'vfs5011',
@@ -113,6 +114,13 @@ default_drivers = [
     'goodixmoc',
 ]
 
+# FIXME: All the drivers should be fixed by adjusting the byte order.
+# See https://gitlab.freedesktop.org/libfprint/libfprint/-/issues/236
+endian_independent_drivers = virtual_drivers + [
+    'aes3500',
+    'synaptics',
+]
+
 all_drivers = default_drivers + virtual_drivers
 
 if drivers == [ 'all' ]
@@ -150,6 +158,16 @@ foreach driver: drivers
     endif
 endforeach
 
+supported_drivers = []
+foreach driver: drivers
+    if build_machine.endian() == 'little' or driver in endian_independent_drivers
+        supported_drivers += driver
+    else
+        warning('Driver @0@ is not supported by big endian cpu @1@. Please, fix it!'.format(
+            driver, build_machine.cpu()))
+    endif
+endforeach
+
 # Export the drivers' types to the core code
 drivers_type_list = []
 drivers_type_func = []
@@ -162,7 +180,7 @@ drivers_type_func += '{'
 drivers_type_func += '  GArray *drivers = g_array_new (TRUE, FALSE, sizeof (GType));'
 drivers_type_func += '  GType t;'
 drivers_type_func += ''
-foreach driver: drivers
+foreach driver: supported_drivers
     drivers_type_list += 'extern GType (fpi_device_' + driver + '_get_type) (void);'
     drivers_type_func += '  t = fpi_device_' + driver + '_get_type ();'
     drivers_type_func += '  g_array_append_val (drivers, t);'
diff --git a/tests/meson.build b/tests/meson.build
index 537a00a..4ebf3b7 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -70,7 +70,8 @@ if get_option('introspection')
         driver_envs = envs
         driver_envs.set('FP_DRIVERS_WHITELIST', driver_test)
 
-        if driver_test in drivers and gusb_dep.version().version_compare('>= 0.3.0')
+        if (driver_test in supported_drivers and
+            gusb_dep.version().version_compare('>= 0.3.0'))
             test(driver_test,
                 find_program('umockdev-test.py'),
                 args: join_paths(meson.current_source_dir(), driver_test),