mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-09 12:25:48 +01:00
Rather than them being set and stored globally, make them members of `GIRepository`. This helps us move away from the concept of a global singleton `GIRepository`. This is slightly complicated by the fact that the library paths are needed within the module loading code in `GITypelib`, but at that point the `GITypelib` doesn’t have access to its parent `GIRepository` to call `gi_repository_get_library_path()`, so we have to cache them in `typelib->library_paths`. It also means that it’s no longer possible to retrieve the ‘unset’ paths from the globals, so the test for that is removed from `repository-search-paths.c`. This commit makes some API breaks, but that’s OK because libgirepository has not been in a stable release yet. Signed-off-by: Philip Withnall <pwithnall@gnome.org> Helps: #3155
68 lines
2.1 KiB
C
68 lines
2.1 KiB
C
/*
|
|
* Copyright 2023 GNOME Foundation, Inc.
|
|
* Copyright 2024 Philip Chimento <philip.chimento@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
|
*
|
|
* 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 "girepository.h"
|
|
#include "glib.h"
|
|
#include "test-common.h"
|
|
|
|
void
|
|
repository_init (int *argc,
|
|
char **argv[])
|
|
{
|
|
/* Isolate from the system typelibs and GIRs. */
|
|
g_setenv ("GI_TYPELIB_PATH", "/dev/null", TRUE);
|
|
g_setenv ("GI_GIR_PATH", "/dev/null", TRUE);
|
|
|
|
g_test_init (argc, argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
|
|
}
|
|
|
|
void
|
|
repository_setup (RepositoryFixture *fx,
|
|
const void *data)
|
|
{
|
|
GITypelib *typelib = NULL;
|
|
GError *local_error = NULL;
|
|
TypelibLoadSpec *load_spec = (TypelibLoadSpec *) data;
|
|
|
|
fx->repository = gi_repository_new ();
|
|
g_assert_nonnull (fx->repository);
|
|
|
|
fx->gobject_typelib_dir = g_test_build_filename (G_TEST_BUILT, "..", "..", "introspection", NULL);
|
|
g_test_message ("Using GI_TYPELIB_DIR = %s", fx->gobject_typelib_dir);
|
|
gi_repository_prepend_search_path (fx->repository, fx->gobject_typelib_dir);
|
|
|
|
if (load_spec)
|
|
{
|
|
typelib = gi_repository_require (fx->repository, load_spec->name, load_spec->version, 0, &local_error);
|
|
g_assert_no_error (local_error);
|
|
g_assert_nonnull (typelib);
|
|
}
|
|
}
|
|
|
|
void
|
|
repository_teardown (RepositoryFixture *fx,
|
|
const void *unused)
|
|
{
|
|
g_clear_pointer (&fx->gobject_typelib_dir, g_free);
|
|
g_clear_object (&fx->repository);
|
|
}
|