Port to MetaContext

This ports over gnome-shell and the theme test case to MetaContext,
instead of the various functions that were available before.

The test case is changed to use the special test context, used to
construct contexts for testing. It's part of a shared libary separate
from the main libmutter one.

This enables building mutter tests during CI, as the test framework is
needed by some of gnome-shell's tests.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1840>
This commit is contained in:
Jonas Ådahl 2021-05-06 23:17:40 +02:00 committed by Marge Bot
parent 4340170e94
commit 5acab6c300
5 changed files with 49 additions and 23 deletions

View File

@ -180,7 +180,7 @@ build:
needs: ["check_commit_log"] needs: ["check_commit_log"]
before_script: before_script:
- .gitlab-ci/checkout-mutter.sh - .gitlab-ci/checkout-mutter.sh
- meson mutter mutter/build --prefix=/usr -Dtests=false - meson mutter mutter/build --prefix=/usr
- ninja -C mutter/build install - ninja -C mutter/build install
script: script:
- meson . build -Dbuildtype=debugoptimized -Dman=false --werror - meson . build -Dbuildtype=debugoptimized -Dman=false --werror

View File

@ -17,6 +17,7 @@ clutter_pc = 'mutter-clutter-' + mutter_api_version
cogl_pc = 'mutter-cogl-' + mutter_api_version cogl_pc = 'mutter-cogl-' + mutter_api_version
cogl_pango_pc = 'mutter-cogl-pango-' + mutter_api_version cogl_pango_pc = 'mutter-cogl-pango-' + mutter_api_version
libmutter_pc = 'libmutter-' + mutter_api_version libmutter_pc = 'libmutter-' + mutter_api_version
libmutter_test_pc = 'libmutter-test-' + mutter_api_version
ecal_req = '>= 3.33.1' ecal_req = '>= 3.33.1'
eds_req = '>= 3.33.1' eds_req = '>= 3.33.1'
@ -87,6 +88,7 @@ clutter_dep = dependency(clutter_pc, version: mutter_req)
cogl_dep = dependency(cogl_pc, version: mutter_req) cogl_dep = dependency(cogl_pc, version: mutter_req)
cogl_pango_dep = dependency(cogl_pango_pc, version: mutter_req) cogl_pango_dep = dependency(cogl_pango_pc, version: mutter_req)
mutter_dep = dependency(libmutter_pc, version: mutter_req) mutter_dep = dependency(libmutter_pc, version: mutter_req)
mutter_test_dep = dependency(libmutter_test_pc, version: mutter_req)
polkit_dep = dependency('polkit-agent-1', version: polkit_req) polkit_dep = dependency('polkit-agent-1', version: polkit_req)
startup_dep = dependency('libstartup-notification-1.0', version: startup_req) startup_dep = dependency('libstartup-notification-1.0', version: startup_req)
ibus_dep = dependency('ibus-1.0', version: ibus_req) ibus_dep = dependency('ibus-1.0', version: ibus_req)

View File

@ -13,7 +13,7 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <glib/gi18n-lib.h> #include <glib/gi18n-lib.h>
#include <girepository.h> #include <girepository.h>
#include <meta/main.h> #include <meta/meta-context.h>
#include <meta/meta-plugin.h> #include <meta/meta-plugin.h>
#include <meta/prefs.h> #include <meta/prefs.h>
#include <atk-bridge.h> #include <atk-bridge.h>
@ -442,33 +442,35 @@ GOptionEntry gnome_shell_options[] = {
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
GOptionContext *ctx; g_autoptr (MetaContext) context = NULL;
GError *error = NULL; GError *error = NULL;
int ecode; int ecode = EXIT_SUCCESS;
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE); textdomain (GETTEXT_PACKAGE);
context = meta_create_context (WM_NAME);
meta_context_add_option_entries (context, gnome_shell_options,
GETTEXT_PACKAGE);
meta_context_add_option_group (context, g_irepository_get_option_group ());
session_mode = (char *) g_getenv ("GNOME_SHELL_SESSION_MODE"); session_mode = (char *) g_getenv ("GNOME_SHELL_SESSION_MODE");
ctx = meta_get_option_context (); if (!meta_context_configure (context, &argc, &argv, &error))
g_option_context_add_main_entries (ctx, gnome_shell_options, GETTEXT_PACKAGE);
g_option_context_add_group (ctx, g_irepository_get_option_group ());
if (!g_option_context_parse (ctx, &argc, &argv, &error))
{ {
g_printerr ("%s: %s\n", argv[0], error->message); g_printerr ("Failed to configure: %s", error->message);
exit (1); return EXIT_FAILURE;
} }
g_option_context_free (ctx); meta_context_set_plugin_gtype (context, gnome_shell_plugin_get_type ());
meta_context_set_gnome_wm_keybindings (context, GNOME_WM_KEYBINDINGS);
meta_plugin_manager_set_plugin_type (gnome_shell_plugin_get_type ()); if (!meta_context_setup (context, &error))
{
meta_set_wm_name (WM_NAME); g_printerr ("Failed to setup: %s", error->message);
meta_set_gnome_wm_keybindings (GNOME_WM_KEYBINDINGS); return EXIT_FAILURE;
}
meta_init ();
/* FIXME: Add gjs API to set this stuff and don't depend on the /* FIXME: Add gjs API to set this stuff and don't depend on the
* environment. These propagate to child processes. * environment. These propagate to child processes.
@ -478,7 +480,7 @@ main (int argc, char **argv)
shell_init_debug (g_getenv ("SHELL_DEBUG")); shell_init_debug (g_getenv ("SHELL_DEBUG"));
shell_dbus_init (meta_get_replace_current_wm ()); shell_dbus_init (meta_context_is_replacing (context));
shell_a11y_init (); shell_a11y_init ();
shell_perf_log_init (); shell_perf_log_init ();
shell_introspection_init (); shell_introspection_init ();
@ -504,7 +506,21 @@ main (int argc, char **argv)
} }
shell_profiler_init (); shell_profiler_init ();
ecode = meta_run ();
if (!meta_context_start (context, &error))
{
g_printerr ("GNOME Shell failed to start: %s", error->message);
return EXIT_FAILURE;
}
if (!meta_context_run_main_loop (context, &error))
{
g_printerr ("GNOME Shell terminated with an error: %s", error->message);
ecode = EXIT_FAILURE;
}
meta_context_destroy (g_steal_pointer (&context));
shell_profiler_shutdown (); shell_profiler_shutdown ();
g_debug ("Doing final cleanup"); g_debug ("Doing final cleanup");

View File

@ -194,7 +194,7 @@ libst_dep = declare_dependency(link_with: libst,
test_theme = executable('test-theme', test_theme = executable('test-theme',
sources: 'test-theme.c', sources: 'test-theme.c',
c_args: st_cflags, c_args: st_cflags,
dependencies: [mutter_dep, gtk_dep, libxml_dep], dependencies: [mutter_test_dep, gtk_dep, libxml_dep],
build_rpath: mutter_typelibdir, build_rpath: mutter_typelibdir,
link_with: libst link_with: libst
) )

View File

@ -25,7 +25,7 @@
#include "st-button.h" #include "st-button.h"
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
#include <meta/main.h> #include <meta-test/meta-context-test.h>
#include <meta/meta-backend.h> #include <meta/meta-backend.h>
static ClutterActor *stage; static ClutterActor *stage;
@ -538,6 +538,8 @@ test_inline_style (void)
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
MetaContext *context;
g_autoptr (GError) error = NULL;
MetaBackend *backend; MetaBackend *backend;
StTheme *theme; StTheme *theme;
StThemeContext *theme_context; StThemeContext *theme_context;
@ -550,7 +552,13 @@ main (int argc, char **argv)
/* meta_init() cds to $HOME */ /* meta_init() cds to $HOME */
cwd = g_get_current_dir (); cwd = g_get_current_dir ();
meta_test_init (); context = meta_create_test_context (META_CONTEXT_TEST_TYPE_NESTED,
META_CONTEXT_TEST_FLAG_NONE);
if (!meta_context_configure (context, &argc, &argv, &error))
g_error ("Failed to configure: %s", error->message);
if (!meta_context_setup (context, &error))
g_error ("Failed to setup: %s", error->message);
if (chdir (cwd) < 0) if (chdir (cwd) < 0)
g_error ("chdir('%s') failed: %s", cwd, g_strerror (errno)); g_error ("chdir('%s') failed: %s", cwd, g_strerror (errno));
@ -623,7 +631,7 @@ main (int argc, char **argv)
g_object_unref (text4); g_object_unref (text4);
g_object_unref (theme); g_object_unref (theme);
clutter_actor_destroy (stage); g_object_unref (context);
return fail ? 1 : 0; return fail ? 1 : 0;
} }