1 /* GObject introspection: typelib inspector
3 * Copyright (C) 2011-2016 Dominique Leuenberger <dimstar@opensuse.org>
4 * Copyright © 2016 Igor Gnatenko <ignatenko@redhat.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 #include <girepository.h>
27 print_shlibs (const gchar *namespace)
31 /* Finding the shared library we depend on (if any) */
32 const gchar *shlibs = g_irepository_get_shared_library (NULL, namespace);
33 if (shlibs && shlibs[0] != '\0')
35 /* shlibs is a comma-separated list of libraries */
36 GStrv libs = g_strsplit (shlibs, ",", -1);
37 for (i = 0; libs[i]; i++)
38 g_print ("shlib: %s\n", libs[i]);
44 print_typelibs (const gchar *namespace)
48 /* Finding all the typelib-based Requires */
49 GStrv deps = g_irepository_get_dependencies (NULL, namespace);
52 for (i = 0; deps[i]; i++)
53 g_print ("typelib: %s\n", deps[i]);
62 gint status = EXIT_SUCCESS;
65 GITypelib *typelib = NULL;
67 gchar *version = NULL;
68 gboolean opt_shlibs = FALSE;
69 gboolean opt_typelibs = FALSE;
70 GStrv namespaces = NULL;
71 const gchar *namespace = NULL;
72 const GOptionEntry options[] = {
73 { "version", 0, 0, G_OPTION_ARG_STRING, &version, "Version", "VERSION" },
74 { "print-shlibs", 0, 0, G_OPTION_ARG_NONE, &opt_shlibs, "List the shared libraries the typelib requires" },
75 { "print-typelibs", 0, 0, G_OPTION_ARG_NONE, &opt_typelibs, "List other typelibs the inspected typelib requires" },
76 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &namespaces, "The typelib to inspect", "NAMESPACE" },
80 g_autoptr(GOptionContext) context = g_option_context_new ("- Inspect GI typelib");
81 g_option_context_add_main_entries (context, options, NULL);
82 if (!g_option_context_parse (context, &argc, &argv, &error))
84 status = EXIT_FAILURE;
85 g_printerr ("Failed to parse command line options: %s\n", error->message);
91 status = EXIT_FAILURE;
92 g_printerr ("Please specify at least one namespace\n");
96 if (g_strv_length (namespaces) > 1)
98 status = EXIT_FAILURE;
99 g_printerr ("Please specify only one namespace\n");
102 namespace = namespaces[0];
104 if (!opt_shlibs && !opt_typelibs)
106 status = EXIT_FAILURE;
107 g_printerr ("Please specify --print-shlibs, --print-typelibs or both.\n");
111 typelib = g_irepository_require (NULL, namespace, version, 0, &error);
114 status = EXIT_FAILURE;
115 g_printerr ("Failed to load typelib: %s\n", error->message);
120 print_shlibs (namespace);
122 print_typelibs (namespace);
126 g_error_free (error);
128 g_typelib_free (typelib);
129 g_strfreev (namespaces);