From 29a822b7c888825e651d41127a6a3966e9c140e6 Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Wed, 4 Sep 2019 17:17:51 +0100
Subject: [PATCH] wrap: Fail with an error if no architectures work

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 src/wrap.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/wrap.c b/src/wrap.c
index 3c88b5564..de940f1b2 100644
--- a/src/wrap.c
+++ b/src/wrap.c
@@ -787,6 +787,7 @@ bind_runtime (FlatpakBwrap *bwrap,
   gsize i, j;
   const gchar *member;
   g_autoptr(GString) dri_path = g_string_new ("");
+  gboolean any_architecture_works = FALSE;
 
   g_return_val_if_fail (tools_dir != NULL, FALSE);
   g_return_val_if_fail (runtime != NULL, FALSE);
@@ -996,6 +997,7 @@ bind_runtime (FlatpakBwrap *bwrap,
               continue;
             }
 
+          any_architecture_works = TRUE;
           g_debug ("Container path: %s -> %s", ld_so, ld_so_in_runtime);
 
           search_path_append (dri_path, this_dri_path_in_container);
@@ -1105,6 +1107,26 @@ bind_runtime (FlatpakBwrap *bwrap,
         }
     }
 
+  if (!any_architecture_works)
+    {
+      GString *archs = g_string_new ("");
+
+      for (i = 0; i < G_N_ELEMENTS (multiarch_tuples); i++)
+        {
+          if (archs->len > 0)
+            g_string_append (archs, ", ");
+
+          g_string_append (archs, multiarch_tuples[i]);
+        }
+
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                   "None of the supported CPU architectures are common to "
+                   "the host system and the container (tried: %s)",
+                   archs->str);
+      g_string_free (archs, TRUE);
+      return FALSE;
+    }
+
   if (dri_path->len != 0)
       flatpak_bwrap_add_args (bwrap,
                               "--setenv", "LIBGL_DRIVERS_PATH", dri_path->str,
-- 
GitLab