From 3b55d6a2c24abec829b8d0737a5ef0f131811416 Mon Sep 17 00:00:00 2001
From: Ludovico de Nittis <ludovico.denittis@collabora.com>
Date: Wed, 17 Mar 2021 14:17:54 +0100
Subject: [PATCH] runtime: Use "/usr/share" as a fallback lib data directory

If the host system stores the shared libraries in a directory that is
not what we expect, we try as a last resort `/usr/share`, in an effort
to increase the number of OSs that we are able to cover.

For example this should help Exherbo to find the right libdrm and
drirc.d directories.

Fixes: #68

Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
---
 pressure-vessel/runtime.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/pressure-vessel/runtime.c b/pressure-vessel/runtime.c
index c3df151c7..b7cfeba60 100644
--- a/pressure-vessel/runtime.c
+++ b/pressure-vessel/runtime.c
@@ -3685,6 +3685,13 @@ pv_runtime_collect_lib_data (PvRuntime *self,
       g_autofree gchar *dir = NULL;
       g_autofree gchar *lib_multiarch = NULL;
       g_autofree gchar *dir_in_provider = NULL;
+      g_autofree gchar *dir_in_provider_fallback = NULL;
+
+      /* If we are unable to find the lib data in the provider, we try as
+       * a last resort `/usr/share`. This should help for example Exherbo
+       * that uses the unusual `/usr/${gnu_tuple}/lib` path for shared
+       * libraries. */
+      dir_in_provider_fallback = g_build_filename ("/usr", "share", dir_basename, NULL);
 
       dir = g_path_get_dirname (target);
 
@@ -3713,11 +3720,24 @@ pv_runtime_collect_lib_data (PvRuntime *self,
           g_hash_table_add (data_in_provider,
                             g_steal_pointer (&dir_in_provider));
         }
+      else if (_srt_file_test_in_sysroot (self->provider_in_current_namespace,
+                                          -1,
+                                          dir_in_provider_fallback,
+                                          G_FILE_TEST_IS_DIR))
+        {
+          g_hash_table_add (data_in_provider,
+                            g_steal_pointer (&dir_in_provider_fallback));
+        }
       else
         {
-          g_info ("We were expecting the %s directory in the provider to "
-                  "be located in \"%s/share/%s\", but instead it is "
-                  "missing", dir_basename, dir, dir_basename);
+          if (g_strcmp0 (dir_in_provider, dir_in_provider_fallback) == 0)
+            g_info ("We were expecting the %s directory in the provider to "
+                    "be located in \"%s\", but instead it is missing",
+                    dir_basename, dir_in_provider);
+          else
+            g_info ("We were expecting the %s directory in the provider to "
+                    "be located in \"%s\" or \"%s\", but instead it is missing",
+                    dir_basename, dir_in_provider, dir_in_provider_fallback);
         }
     }
 }
-- 
GitLab