[glib-networking/mcatanzaro/proxies] Add environment variable proxy resolver




commit 968dc47554c620ef2f55701f833e9cc868eaeee7
Author: Michael Catanzaro <mcatanzaro redhat com>
Date:   Fri Jul 2 15:43:01 2021 -0500

    Add environment variable proxy resolver
    
    There is no reason to use libproxy just to resolve some environment
    variables for us.
    
    This makes it possible to resolve proxies outside GNOME when built with
    libproxy support disabled, and also reduces our odds of crashing if a
    gjs app uses a libproxy that's linked to mozjs, or if a WebKit app uses
    a libproxy that's linked to JavaScriptCore.
    
    This should also help the user in #183 who was confused that libproxy
    doesn't look at environment variables when running under KDE. Of course,
    apps that use libproxy directly, rather than GProxyResolver, are still
    going to look at desktop settings first. That should probably change in
    libproxy.
    
    Fixes #162

 meson.build                                   |  19 ++-
 proxy/README.md                               |  24 ++++
 proxy/environment/environmentproxy-module.c   |  65 +++++++++
 proxy/environment/genvironmentproxyresolver.c | 191 ++++++++++++++++++++++++++
 proxy/environment/genvironmentproxyresolver.h |  35 +++++
 proxy/environment/meson.build                 |  38 +++++
 proxy/gnome/meson.build                       |   2 +-
 proxy/libproxy/meson.build                    |   2 +-
 proxy/tests/common.c                          |   4 +-
 proxy/tests/{libproxy.c => environment.c}     |  72 ++++++----
 proxy/tests/gnome.c                           |   2 +-
 proxy/tests/meson.build                       |  16 ++-
 12 files changed, 421 insertions(+), 49 deletions(-)
---
diff --git a/meson.build b/meson.build
index 38b8d650..f9953715 100644
--- a/meson.build
+++ b/meson.build
@@ -169,20 +169,19 @@ if ['darwin', 'ios'].contains(host_system)
   module_suffix = 'so'
 endif
 
-if libproxy_dep.found() or gsettings_desktop_schemas_dep.found()
-  proxy_test_programs = []
+proxy_test_programs = []
 
-  if libproxy_dep.found()
-    subdir('proxy/libproxy')
-  endif
-
-  if gsettings_desktop_schemas_dep.found()
-    subdir('proxy/gnome')
-  endif
+if libproxy_dep.found()
+subdir('proxy/libproxy')
+endif
 
-  subdir('proxy/tests')
+if gsettings_desktop_schemas_dep.found()
+subdir('proxy/gnome')
 endif
 
+subdir('proxy/environment')
+subdir('proxy/tests')
+
 subdir('tls/base')
 
 if gnutls_dep.found()
diff --git a/proxy/README.md b/proxy/README.md
new file mode 100644
index 00000000..8cf85d22
--- /dev/null
+++ b/proxy/README.md
@@ -0,0 +1,24 @@
+We currently have three proxy backends:
+
+ * environment, used if one of several proxy environment variables are set
+ * gnome, used if "GNOME" is present in `$XDG_CURRENT_DESKTOP`
+ * libproxy, used otherwise
+
+The environment backend is based on how libproxy handles proxy environment
+variables, which has some differences from how other programs (e.g. libcurl)
+might interpret these variables. In particular, the `http_proxy` or `HTTP_PROXY`
+variables are used for *all* protocols, not just HTTP. This backend allows for
+basic proxy support even if running outside GNOME and built without libproxy.
+
+The GNOME backend uses the GNOME proxy settings, currently located under
+/system/proxy in dconf. Because all /system settings are deprecated, these
+settings will probably move somewhere else in the future. See
+https://gitlab.gnome.org/GNOME/gsettings-desktop-schemas/-/issues/27.
+
+Finally, libproxy provides the best level of proxy configuration support,
+including support for environments like Windows or KDE, which have their own
+system proxy settings. But libproxy has some serious problems that are difficult
+to fix, e.g. https://github.com/libproxy/libproxy/issues/81. Accordingly, this
+backend is used only if the other two are not suitable.
+
+The GNOME and libproxy backends can both be disabled at build time, if desired.
diff --git a/proxy/environment/environmentproxy-module.c b/proxy/environment/environmentproxy-module.c
new file mode 100644
index 00000000..0361849f
--- /dev/null
+++ b/proxy/environment/environmentproxy-module.c
@@ -0,0 +1,65 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright 2021 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <glib/gi18n-lib.h>
+
+#include "genvironmentproxyresolver.h"
+
+
+void
+g_io_environmentproxy_load (GIOModule *module)
+{
+  gchar *locale_dir;
+#ifdef G_OS_WIN32
+  gchar *base_dir;
+#endif
+
+  g_environment_proxy_resolver_register (module);
+
+#ifdef G_OS_WIN32
+  base_dir = g_win32_get_package_installation_directory_of_module (NULL);
+  locale_dir = g_build_filename (base_dir, "share", "locale", NULL);
+  g_free (base_dir);
+#else
+  locale_dir = g_strdup (LOCALE_DIR);
+#endif
+
+  bindtextdomain (GETTEXT_PACKAGE, locale_dir);
+  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+  g_free (locale_dir);
+}
+
+void
+g_io_environmentproxy_unload (GIOModule *module)
+{
+}
+
+gchar **
+g_io_environmentproxy_query (void)
+{
+  gchar *eps[] = {
+    G_PROXY_RESOLVER_EXTENSION_POINT_NAME,
+    NULL
+  };
+  return g_strdupv (eps);
+}
diff --git a/proxy/environment/genvironmentproxyresolver.c b/proxy/environment/genvironmentproxyresolver.c
new file mode 100644
index 00000000..77dcbb0d
--- /dev/null
+++ b/proxy/environment/genvironmentproxyresolver.c
@@ -0,0 +1,191 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright © 2022 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "genvironmentproxyresolver.h"
+
+#include <glib.h>
+#include <glib/gi18n-lib.h>
+
+struct _GEnvironmentProxyResolver {
+  GObject parent_instance;
+
+  GProxyResolver *base_resolver;
+};
+
+static void g_environment_proxy_resolver_iface_init (GProxyResolverInterface *iface);
+
+#ifdef GENVIRONMENTPROXY_MODULE
+static void
+g_environment_proxy_resolver_class_finalize (GEnvironmentProxyResolverClass *klass)
+{
+}
+
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (GEnvironmentProxyResolver,
+                                g_environment_proxy_resolver,
+                                G_TYPE_OBJECT, 0,
+                                G_IMPLEMENT_INTERFACE_DYNAMIC (G_TYPE_PROXY_RESOLVER,
+                                                               g_environment_proxy_resolver_iface_init))
+#else
+G_DEFINE_TYPE_EXTENDED (GEnvironmentProxyResolver,
+                        g_environment_proxy_resolver,
+                        G_TYPE_OBJECT, 0,
+                        G_IMPLEMENT_INTERFACE (G_TYPE_PROXY_RESOLVER,
+                                               g_environment_proxy_resolver_iface_init))
+#endif
+
+static gboolean
+is_running_libproxy_test (void)
+{
+  const char *gio_proxy_test_name;
+  gio_proxy_test_name = g_getenv ("GIO_PROXY_TEST_NAME");
+  if (gio_proxy_test_name && strcmp (gio_proxy_test_name, "libproxy") == 0)
+    return TRUE;
+  return FALSE;
+}
+
+static gboolean
+g_environment_proxy_resolver_is_supported (GProxyResolver *object)
+{
+  if (is_running_libproxy_test ())
+    return FALSE;
+
+  return (g_getenv ("ftp_proxy") || g_getenv ("FTP_PROXY") ||
+          g_getenv ("https_proxy") || g_getenv ("HTTPS_PROXY") ||
+          g_getenv ("http_proxy") || g_getenv ("HTTP_PROXY") ||
+          g_getenv ("no_proxy") || g_getenv ("NO_PROXY"));
+}
+
+static GProxyResolver *
+get_base_resolver (GProxyResolver *resolver)
+{
+  return G_PROXY_RESOLVER (G_ENVIRONMENT_PROXY_RESOLVER (resolver)->base_resolver);
+}
+
+static gchar **
+g_environment_proxy_resolver_lookup (GProxyResolver  *resolver,
+                                     const gchar     *uri,
+                                     GCancellable    *cancellable,
+                                     GError         **error)
+{
+  return g_proxy_resolver_lookup (get_base_resolver (resolver), uri, cancellable, error);
+}
+
+static void
+g_environment_proxy_resolver_lookup_async (GProxyResolver      *resolver,
+                                           const gchar         *uri,
+                                           GCancellable        *cancellable,
+                                           GAsyncReadyCallback  callback,
+                                           gpointer             user_data)
+{
+  g_proxy_resolver_lookup_async (get_base_resolver (resolver), uri, cancellable, callback, user_data);
+}
+
+static gchar **
+g_environment_proxy_resolver_lookup_finish (GProxyResolver     *resolver,
+                                            GAsyncResult       *result,
+                                            GError            **error)
+{
+  return g_proxy_resolver_lookup_finish (resolver, result, error);
+}
+
+static void
+g_environment_proxy_resolver_finalize (GObject *object)
+{
+  GEnvironmentProxyResolver *resolver = G_ENVIRONMENT_PROXY_RESOLVER (object);
+  
+  g_object_unref (resolver->base_resolver);
+
+  G_OBJECT_CLASS (g_environment_proxy_resolver_parent_class)->finalize (object);
+}
+
+static void
+g_environment_proxy_resolver_init (GEnvironmentProxyResolver *resolver)
+{
+  char **ignore_hosts = NULL;
+  const char *default_proxy = NULL;
+
+  if (g_getenv ("no_proxy"))
+    ignore_hosts = g_strsplit (g_getenv ("no_proxy"), ",", -1);
+  else if (g_getenv ("NO_PROXY"))
+    ignore_hosts = g_strsplit (g_getenv ("NO_PROXY"), ",", -1);
+
+  /* The http_proxy/HTTP_PROXY is used for *all* protocols (except FTP or HTTPS,
+   * if more specific environment variables are set. It is not just for HTTP.
+   * This matches the behavior of libproxy's environment variable module, or
+   * GNOME's use-same-proxy setting.
+   */
+  if (g_getenv ("http_proxy"))
+    default_proxy = g_getenv ("http_proxy");
+  else if (g_getenv ("HTTP_PROXY"))
+    default_proxy = g_getenv ("HTTP_PROXY");
+
+  resolver->base_resolver = g_simple_proxy_resolver_new (default_proxy, ignore_hosts);
+
+  if (g_getenv ("ftp_proxy"))
+    g_simple_proxy_resolver_set_uri_proxy (G_SIMPLE_PROXY_RESOLVER (resolver->base_resolver), "ftp", 
g_getenv ("ftp_proxy"));
+  else if (g_getenv ("FTP_PROXY"))
+    g_simple_proxy_resolver_set_uri_proxy (G_SIMPLE_PROXY_RESOLVER (resolver->base_resolver), "ftp", 
g_getenv ("FTP_PROXY"));
+
+  if (g_getenv ("https_proxy"))
+    g_simple_proxy_resolver_set_uri_proxy (G_SIMPLE_PROXY_RESOLVER (resolver->base_resolver), "https", 
g_getenv ("https_proxy"));
+  else if (g_getenv ("HTTPS_PROXY"))
+    g_simple_proxy_resolver_set_uri_proxy (G_SIMPLE_PROXY_RESOLVER (resolver->base_resolver), "https", 
g_getenv ("HTTPS_PROXY"));
+
+  g_strfreev (ignore_hosts);
+}
+
+static void
+g_environment_proxy_resolver_class_init (GEnvironmentProxyResolverClass *resolver_class)
+{
+  GObjectClass *object_class;
+  
+  object_class = G_OBJECT_CLASS (resolver_class);
+  object_class->finalize = g_environment_proxy_resolver_finalize;
+}
+
+static void
+g_environment_proxy_resolver_iface_init (GProxyResolverInterface *iface)
+{
+  iface->is_supported = g_environment_proxy_resolver_is_supported;
+  iface->lookup = g_environment_proxy_resolver_lookup;
+  iface->lookup_async = g_environment_proxy_resolver_lookup_async;
+  iface->lookup_finish = g_environment_proxy_resolver_lookup_finish;
+}
+
+#ifdef GENVIRONMENTPROXY_MODULE
+void
+g_environment_proxy_resolver_register (GIOModule *module)
+{
+  g_environment_proxy_resolver_register_type (G_TYPE_MODULE (module));
+  if (!module)
+    g_io_extension_point_register (G_PROXY_RESOLVER_EXTENSION_POINT_NAME);
+  g_io_extension_point_implement (G_PROXY_RESOLVER_EXTENSION_POINT_NAME,
+                                  g_environment_proxy_resolver_get_type(),
+                                  "environment",
+                                  100);
+}
+#endif
diff --git a/proxy/environment/genvironmentproxyresolver.h b/proxy/environment/genvironmentproxyresolver.h
new file mode 100644
index 00000000..faf5b6f3
--- /dev/null
+++ b/proxy/environment/genvironmentproxyresolver.h
@@ -0,0 +1,35 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright 2021 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <glib-object.h>
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+#define G_TYPE_ENVIRONMENT_PROXY_RESOLVER         (g_environment_proxy_resolver_get_type ())
+
+G_DECLARE_FINAL_TYPE (GEnvironmentProxyResolver, g_environment_proxy_resolver, G, 
ENVIRONMENT_PROXY_RESOLVER, GObject)
+
+void g_environment_proxy_resolver_register (GIOModule *module);
+
+G_END_DECLS
diff --git a/proxy/environment/meson.build b/proxy/environment/meson.build
new file mode 100644
index 00000000..9f8a4133
--- /dev/null
+++ b/proxy/environment/meson.build
@@ -0,0 +1,38 @@
+service_conf = configuration_data()
+service_conf.set('libexecdir', libexecdir)
+
+sources = files(
+  'genvironmentproxyresolver.c',
+  'environmentproxy-module.c'
+)
+
+deps = [
+  gio_dep,
+  glib_dep,
+  gmodule_dep,
+  gobject_dep
+]
+
+module = shared_module(
+  'gioenvironmentproxy',
+  sources: sources,
+  include_directories: top_inc,
+  dependencies: deps,
+  c_args: '-DGENVIRONMENTPROXY_MODULE',
+  link_args: module_ldflags,
+  link_depends: symbol_map,
+  name_suffix: module_suffix,
+  install: true,
+  install_dir: gio_module_dir
+)
+
+if get_option('static_modules')
+  static_library('gioenvironmentproxy',
+    objects: module.extract_all_objects(),
+    install: true,
+    install_dir: gio_module_dir
+  )
+  pkg.generate(module)
+endif
+
+proxy_test_programs += [['environment', 'environment', deps]]
diff --git a/proxy/gnome/meson.build b/proxy/gnome/meson.build
index 278ca328..dd4bc5be 100644
--- a/proxy/gnome/meson.build
+++ b/proxy/gnome/meson.build
@@ -32,4 +32,4 @@ if get_option('static_modules')
   pkg.generate(module)
 endif
 
-proxy_test_programs += [['gnome', deps]]
+proxy_test_programs += [['gnome', 'gnome', deps]]
diff --git a/proxy/libproxy/meson.build b/proxy/libproxy/meson.build
index 038bfa1e..7a766b3d 100644
--- a/proxy/libproxy/meson.build
+++ b/proxy/libproxy/meson.build
@@ -70,4 +70,4 @@ executable(
   install_dir: libexecdir
 )
 
-proxy_test_programs += [['libproxy', deps]]
+proxy_test_programs += [['environment', 'libproxy', deps]]
diff --git a/proxy/tests/common.c b/proxy/tests/common.c
index cbefaceb..de009a03 100644
--- a/proxy/tests/common.c
+++ b/proxy/tests/common.c
@@ -169,14 +169,16 @@ static const struct {
 static const int n_ignore_tests = G_N_ELEMENTS (ignore_tests);
 
 static void
-test_proxy_ignore_common (gboolean is_libproxy)
+test_proxy_ignore_common (void)
 {
   GProxyResolver *resolver;
+  gboolean is_libproxy;
   GError *error = NULL;
   char **proxies;
   int i;
 
   resolver = g_proxy_resolver_get_default ();
+  is_libproxy = g_strcmp0 (getenv ("GIO_PROXY_TEST_NAME"), "libproxy") == 0;
 
   for (i = 0; i < n_ignore_tests; i++)
     {
diff --git a/proxy/tests/libproxy.c b/proxy/tests/environment.c
similarity index 58%
rename from proxy/tests/libproxy.c
rename to proxy/tests/environment.c
index e92ca81e..2d9d026c 100644
--- a/proxy/tests/libproxy.c
+++ b/proxy/tests/environment.c
@@ -2,7 +2,7 @@
 /*
  * GLibProxyResolver tests
  *
- * Copyright 2011-2013 Red Hat, Inc.
+ * Copyright © 2011-2013, 2022 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -23,24 +23,21 @@
 
 #include "common.c"
 
-static void
-reset_proxy_settings (gpointer      fixture,
-                      gconstpointer user_data)
-{
-  g_unsetenv ("http_proxy");
-  g_unsetenv ("HTTP_PROXY");
-  g_unsetenv ("https_proxy");
-  g_unsetenv ("HTTPS_PROXY");
-  g_unsetenv ("ftp_proxy");
-  g_unsetenv ("FTP_PROXY");
-  g_unsetenv ("no_proxy");
-  g_unsetenv ("NO_PROXY");
-}
+/* These tests use subprocesses in order to get a new GEnvironmentProxyResolver
+ * for each test. Using a new subprocess also adds a veneer of thread safety to
+ * our use of setenv()/unsetenv().
+ */
 
 static void
-test_proxy_uri (gpointer      fixture,
-                gconstpointer user_data)
+test_proxy_uri (void)
 {
+  if (!g_test_subprocess ())
+    {
+      g_test_trap_subprocess (NULL, 0, 0);
+      g_test_trap_assert_passed ();
+      return;
+    }
+
   g_setenv ("http_proxy", "http://proxy.example.com:8080";, TRUE);
   g_setenv ("https_proxy", "http://proxy-s.example.com:7070";, TRUE);
   g_setenv ("ftp_proxy", "ftp://proxy-f.example.com:6060";, TRUE);
@@ -49,9 +46,15 @@ test_proxy_uri (gpointer      fixture,
 }
 
 static void
-test_proxy_socks (gpointer      fixture,
-                  gconstpointer user_data)
+test_proxy_socks (void)
 {
+  if (!g_test_subprocess ())
+    {
+      g_test_trap_subprocess (NULL, 0, 0);
+      g_test_trap_assert_passed ();
+      return;
+    }
+
   g_setenv ("http_proxy", "socks://proxy.example.com:1234", TRUE);
   g_setenv ("no_proxy", "127.0.0.1", TRUE);
 
@@ -59,35 +62,44 @@ test_proxy_socks (gpointer      fixture,
 }
 
 static void
-test_proxy_ignore (gpointer      fixture,
-                   gconstpointer user_data)
+test_proxy_ignore (void)
 {
-  gchar *no_proxy = g_strjoinv (",", (gchar **)ignore_hosts);
+  gchar *no_proxy;
+
+  if (!g_test_subprocess ())
+    {
+      g_test_trap_subprocess (NULL, 0, 0);
+      g_test_trap_assert_passed ();
+      return;
+    }
+
+  no_proxy = g_strjoinv (",", (gchar **)ignore_hosts);
 
   g_setenv ("http_proxy", "http://localhost:8080";, TRUE);
   g_setenv ("no_proxy", no_proxy, TRUE);
   g_free (no_proxy);
 
-  test_proxy_ignore_common (TRUE);
+  test_proxy_ignore_common ();
 }
 
 int
 main (int   argc,
       char *argv[])
 {
-  g_test_init (&argc, &argv, NULL);
-
   /* Unset variables that would make libproxy try to use gconf or ksettings */
   g_unsetenv ("GNOME_DESKTOP_SESSION_ID");
   g_unsetenv ("DESKTOP_SESSION");
   g_unsetenv ("KDE_FULL_SESSION");
 
-  g_test_add_vtable ("/proxy/libproxy/uri", 0, NULL,
-                     reset_proxy_settings, test_proxy_uri, NULL);
-  g_test_add_vtable ("/proxy/libproxy/socks", 0, NULL,
-                     reset_proxy_settings, test_proxy_socks, NULL);
-  g_test_add_vtable ("/proxy/libproxy/ignore", 0, NULL,
-                     reset_proxy_settings, test_proxy_ignore, NULL);
+  /* Unset variables that libproxy would look at if it were smarter, and which
+   * it might possibly look at in the future. Just covering our bases. */
+  g_unsetenv ("XDG_CURRENT_DESKTOP");
+
+  g_test_init (&argc, &argv, NULL);
+
+  g_test_add_func ("/proxy/environment/uri", test_proxy_uri);
+  g_test_add_func ("/proxy/environment/socks", test_proxy_socks);
+  g_test_add_func ("/proxy/environment/ignore", test_proxy_ignore);
 
   return g_test_run();
 }
diff --git a/proxy/tests/gnome.c b/proxy/tests/gnome.c
index f76b0944..61f5347d 100644
--- a/proxy/tests/gnome.c
+++ b/proxy/tests/gnome.c
@@ -151,7 +151,7 @@ test_proxy_ignore (gpointer      fixture,
   g_object_unref (http);
   g_object_unref (settings);
 
-  test_proxy_ignore_common (FALSE);
+  test_proxy_ignore_common ();
 }
 
 int
diff --git a/proxy/tests/meson.build b/proxy/tests/meson.build
index 4e0079f0..56538b69 100644
--- a/proxy/tests/meson.build
+++ b/proxy/tests/meson.build
@@ -8,20 +8,25 @@ foreach program: proxy_test_programs
   test_conf.set('installed_tests_dir', installed_tests_execdir)
   test_conf.set('program', program[0])
 
+  test_name = program[0]
+  if program[0] != program[1]
+    test_name = program[0] + '-' + program[1]
+  endif
+
   if enable_installed_tests
     configure_file(
       input: test_template,
-      output: program[0] + '.test',
+      output: test_name + '.test',
       install_dir: installed_tests_metadir,
       configuration: test_conf
     )
   endif
 
   exe = executable(
-    program[0],
+    test_name,
     program[0] + '.c',
     include_directories: top_inc,
-    dependencies: program[1],
+    dependencies: program[2],
     c_args: cflags,
     install: enable_installed_tests,
     install_dir: installed_tests_execdir
@@ -30,11 +35,12 @@ foreach program: proxy_test_programs
   envs = [
     'G_TEST_SRCDIR=' + meson.current_source_dir(),
     'G_TEST_BUILDDIR=' + meson.current_build_dir(),
-    'GIO_MODULE_DIR=' + join_paths(meson.build_root(), 'proxy', program[0])
+    'GIO_MODULE_DIR=' + join_paths(meson.build_root(), 'proxy', program[1]),
+    'GIO_PROXY_TEST_NAME=' + program[1]
   ]
 
   test(
-    program[0],
+    test_name,
     exe,
     env: envs
   )


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]