From ca0a30fa565e510ddc96d3d5c150f90710658677 Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Fri, 23 Aug 2019 13:07:48 +0100
Subject: [PATCH] wrap: Add PRESSURE_VESSEL_RUNTIME, which can force use of a
 runtime

Allow --runtime="", to force not using a runtime, ignoring the
environment variable.

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 pressure-vessel-test-ui         |  4 ++--
 pressure-vessel-unruntime-scout |  4 ++--
 src/wrap.c                      | 11 ++++++++---
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/pressure-vessel-test-ui b/pressure-vessel-test-ui
index e3aae0e69..3b6ca1534 100755
--- a/pressure-vessel-test-ui
+++ b/pressure-vessel-test-ui
@@ -262,9 +262,9 @@ class Gui:
         id = self.runtime_combo.get_active_id()
 
         if id is None:
-            pass
+            argv.append('--runtime=')
         elif id == '/':
-            pass
+            argv.append('--runtime=')
         else:
             argv.append('--runtime')
             argv.append(os.path.join(id, 'files'))
diff --git a/pressure-vessel-unruntime-scout b/pressure-vessel-unruntime-scout
index 4ffe00792..6aed386ae 100755
--- a/pressure-vessel-unruntime-scout
+++ b/pressure-vessel-unruntime-scout
@@ -29,12 +29,12 @@
 set -e
 set -o pipefail
 set -u
-shopt -s nullglob
 
 me="$(readlink -f "$0")"
 here="${me%/*}"
 me="${me##*/}"
 
-exec "$here/pressure-vessel-unruntime" --runtime "${here}/../../scout/files" "$@"
+export PRESSURE_VESSEL_RUNTIME="${here}/../../scout/files"
+exec "$here/pressure-vessel-unruntime" "$@"
 
 # vim:set sw=4 sts=4 et:
diff --git a/src/wrap.c b/src/wrap.c
index 7fe1554e4..46347268a 100644
--- a/src/wrap.c
+++ b/src/wrap.c
@@ -1641,7 +1641,8 @@ static GOptionEntry options[] =
     "MODULE" },
   { "runtime", 0, 0, G_OPTION_ARG_FILENAME, &opt_runtime,
     "Mount the given sysroot or merged /usr in the container, and augment "
-    "it with the host system's graphics stack.",
+    "it with the host system's graphics stack. The empty string "
+    "means don't use a runtime. [Default: $PRESSURE_VESSEL_RUNTIME or '']",
     "RUNTIME" },
   { "share-home", 0, 0, G_OPTION_ARG_NONE, &opt_share_home,
     "Use the real home directory. [Default]", NULL },
@@ -1742,6 +1743,9 @@ main (int argc,
   if (!g_option_context_parse (context, &argc, &argv, error))
     goto out;
 
+  if (opt_runtime == NULL)
+    opt_runtime = g_strdup (g_getenv ("PRESSURE_VESSEL_RUNTIME"));
+
   if (opt_version)
     {
       g_print ("pressure-vessel version %s\n", VERSION);
@@ -2015,7 +2019,7 @@ main (int argc,
   if (!opt_tty)
     flatpak_bwrap_add_arg (bwrap, "--new-session");
 
-  if (opt_runtime != NULL)
+  if (opt_runtime != NULL && opt_runtime[0] != '\0')
     {
       g_debug ("Configuring runtime...");
 
@@ -2110,6 +2114,7 @@ main (int argc,
           if (g_file_test (preload, G_FILE_TEST_EXISTS))
             {
               if (opt_runtime != NULL
+                  && opt_runtime[0] != '\0'
                   && (g_str_has_prefix (preload, "/usr/")
                       || g_str_has_prefix (preload, "/lib")))
                 {
@@ -2178,7 +2183,7 @@ main (int argc,
 
   /* Put Steam Runtime environment variables back, if /usr is mounted
    * from the host. */
-  if (opt_runtime == NULL)
+  if (opt_runtime == NULL && opt_runtime[0] != '\0')
     {
       g_debug ("Making Steam Runtime available...");
 
-- 
GitLab