2016-04-28 23:53:43 +02:00
|
|
|
/* GObject introspection: typelib inspector
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011-2016 Dominique Leuenberger <dimstar@opensuse.org>
|
|
|
|
* Copyright © 2016 Igor Gnatenko <ignatenko@redhat.com>
|
|
|
|
*
|
2024-02-08 15:01:57 +01:00
|
|
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
*
|
2016-04-28 23:53:43 +02:00
|
|
|
* 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 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, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <glib.h>
|
2024-02-26 13:43:30 +01:00
|
|
|
#include <glib/gi18n.h>
|
2016-04-28 23:53:43 +02:00
|
|
|
#include <girepository.h>
|
|
|
|
#include <stdlib.h>
|
2016-01-11 06:35:34 +01:00
|
|
|
#include <locale.h>
|
2016-04-28 23:53:43 +02:00
|
|
|
|
|
|
|
static void
|
2024-02-08 15:36:19 +01:00
|
|
|
print_shlibs (GIRepository *repository,
|
|
|
|
const gchar *namespace)
|
2016-04-28 23:53:43 +02:00
|
|
|
{
|
|
|
|
/* Finding the shared library we depend on (if any) */
|
2024-02-08 15:36:19 +01:00
|
|
|
const char * const *shlibs = gi_repository_get_shared_libraries (repository, namespace, NULL);
|
|
|
|
for (size_t i = 0; shlibs != NULL && shlibs[i] != NULL; i++)
|
|
|
|
g_print ("shlib: %s\n", shlibs[i]);
|
2016-04-28 23:53:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2024-02-08 15:36:19 +01:00
|
|
|
print_typelibs (GIRepository *repository,
|
|
|
|
const gchar *namespace)
|
2016-04-28 23:53:43 +02:00
|
|
|
{
|
|
|
|
guint i = 0;
|
|
|
|
|
|
|
|
/* Finding all the typelib-based Requires */
|
2024-02-08 15:36:19 +01:00
|
|
|
GStrv deps = gi_repository_get_dependencies (repository, namespace, NULL);
|
2016-04-28 23:53:43 +02:00
|
|
|
if (deps)
|
|
|
|
{
|
|
|
|
for (i = 0; deps[i]; i++)
|
|
|
|
g_print ("typelib: %s\n", deps[i]);
|
|
|
|
g_strfreev (deps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
main (gint argc,
|
|
|
|
gchar *argv[])
|
|
|
|
{
|
|
|
|
gint status = EXIT_SUCCESS;
|
|
|
|
|
|
|
|
GError *error = NULL;
|
2024-02-08 15:36:19 +01:00
|
|
|
GIRepository *repository = NULL;
|
2016-04-28 23:53:43 +02:00
|
|
|
GITypelib *typelib = NULL;
|
|
|
|
|
|
|
|
gchar *version = NULL;
|
|
|
|
gboolean opt_shlibs = FALSE;
|
|
|
|
gboolean opt_typelibs = FALSE;
|
|
|
|
GStrv namespaces = NULL;
|
|
|
|
const gchar *namespace = NULL;
|
|
|
|
const GOptionEntry options[] = {
|
2024-02-26 13:43:30 +01:00
|
|
|
{ "typelib-version", 0, 0, G_OPTION_ARG_STRING, &version, N_("Typelib version to inspect"), N_("VERSION") },
|
|
|
|
{ "print-shlibs", 0, 0, G_OPTION_ARG_NONE, &opt_shlibs, N_("List the shared libraries the typelib requires"), NULL },
|
|
|
|
{ "print-typelibs", 0, 0, G_OPTION_ARG_NONE, &opt_typelibs, N_("List other typelibs the inspected typelib requires"), NULL },
|
|
|
|
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &namespaces, N_("The typelib to inspect"), N_("NAMESPACE") },
|
2024-02-08 15:36:19 +01:00
|
|
|
G_OPTION_ENTRY_NULL
|
2016-04-28 23:53:43 +02:00
|
|
|
};
|
2017-05-19 05:42:28 +02:00
|
|
|
GOptionContext *context = NULL;
|
2016-04-28 23:53:43 +02:00
|
|
|
|
2016-01-11 06:35:34 +01:00
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
|
2024-02-26 13:43:30 +01:00
|
|
|
context = g_option_context_new (_("- Inspect GI typelib"));
|
2016-04-28 23:53:43 +02:00
|
|
|
g_option_context_add_main_entries (context, options, NULL);
|
|
|
|
if (!g_option_context_parse (context, &argc, &argv, &error))
|
|
|
|
{
|
2024-02-26 13:43:30 +01:00
|
|
|
char *message = g_strdup_printf (_("Failed to parse command line options: %s"), error->message);
|
2016-04-28 23:53:43 +02:00
|
|
|
status = EXIT_FAILURE;
|
2024-02-26 13:43:30 +01:00
|
|
|
g_printerr ("%s\n", message);
|
|
|
|
g_free (message);
|
2016-04-28 23:53:43 +02:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2024-02-26 13:46:53 +01:00
|
|
|
if (!namespaces || g_strv_length (namespaces) > 1)
|
2016-04-28 23:53:43 +02:00
|
|
|
{
|
|
|
|
status = EXIT_FAILURE;
|
2024-02-26 13:43:30 +01:00
|
|
|
g_printerr ("%s\n", _("Please specify exactly one namespace"));
|
2016-04-28 23:53:43 +02:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace = namespaces[0];
|
|
|
|
|
|
|
|
if (!opt_shlibs && !opt_typelibs)
|
|
|
|
{
|
|
|
|
status = EXIT_FAILURE;
|
2024-02-26 13:43:30 +01:00
|
|
|
g_printerr ("%s\n", _("Please specify --print-shlibs, --print-typelibs or both"));
|
2016-04-28 23:53:43 +02:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2024-02-08 15:36:19 +01:00
|
|
|
repository = gi_repository_new ();
|
|
|
|
typelib = gi_repository_require (repository, namespace, version, 0, &error);
|
2016-04-28 23:53:43 +02:00
|
|
|
if (!typelib)
|
|
|
|
{
|
2024-02-26 13:43:30 +01:00
|
|
|
char *message = g_strdup_printf (_("Failed to load typelib: %s"), error->message);
|
2016-04-28 23:53:43 +02:00
|
|
|
status = EXIT_FAILURE;
|
2024-02-26 13:43:30 +01:00
|
|
|
g_printerr ("%s\n", message);
|
|
|
|
g_free (message);
|
2016-04-28 23:53:43 +02:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opt_shlibs)
|
2024-02-08 15:36:19 +01:00
|
|
|
print_shlibs (repository, namespace);
|
2016-04-28 23:53:43 +02:00
|
|
|
if (opt_typelibs)
|
2024-02-08 15:36:19 +01:00
|
|
|
print_typelibs (repository, namespace);
|
2016-04-28 23:53:43 +02:00
|
|
|
|
|
|
|
out:
|
2016-08-07 09:58:57 +02:00
|
|
|
g_option_context_free (context);
|
2016-04-28 23:53:43 +02:00
|
|
|
if (error)
|
|
|
|
g_error_free (error);
|
2024-02-08 15:36:19 +01:00
|
|
|
g_clear_object (&repository);
|
2016-04-28 23:53:43 +02:00
|
|
|
g_strfreev (namespaces);
|
|
|
|
g_free (version);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|