mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
Merge branch '3155-update-generate-and-inspect' into 'main'
Rename g-ir-generate and g-ir-inspect and update to girepository-2.0 See merge request GNOME/glib!3909
This commit is contained in:
commit
2ee2397622
@ -67,6 +67,7 @@ your code if integer type warnings are enabled.
|
||||
| `g_irepository_get_search_path` and `g_irepository_get_library_path` | Now return arrays rather than linked lists |
|
||||
| `g_irepository_enumerate_versions` | Now returns an array rather than a linked list |
|
||||
| `g_irepository_get_immediate_dependencies`, `g_irepository_get_dependencies` and `g_irepository_get_loaded_namespaces` | Now additionally return a length argument |
|
||||
| `g_irepository_get_shared_library` | [method@GIRepository.get_shared_libraries] |
|
||||
| `g_irepository_dump` | Takes structured `input_filename` and `output_filename` arguments rather than a single formatted string |
|
||||
| `g_function_invoker_destroy` | `gi_function_invoker_clear()` |
|
||||
| `g_struct_info_get_copy_function` | [method@GIRepository.StructInfo.get_copy_function_name] |
|
||||
@ -80,3 +81,15 @@ your code if integer type warnings are enabled.
|
||||
| `g_union_info_get_copy_function` | [method@GIRepository.UnionInfo.get_copy_function_name] |
|
||||
| `g_union_info_get_free_function` | [method@GIRepository.UnionInfo.get_free_function_name] |
|
||||
| `GIInfoType` | Use [type@GObject.Type] directly |
|
||||
|
||||
## Utility program renames from version 1.0 to 2.0
|
||||
|
||||
| girepository-1.0 | girepository-2.0 |
|
||||
|------------------|-------------------------|
|
||||
| `g-ir-compiler` | `gi-compile-repository` |
|
||||
| `g-ir-generate` | `gi-decompile-typelib` |
|
||||
| `g-ir-inspect` | `gi-inspect-typelib` |
|
||||
|
||||
In addition, the `--version` option for `g-ir-inspect` has been renamed to
|
||||
`--typelib-version` in `gi-inspect-typelib`.
|
||||
|
||||
|
@ -27,14 +27,15 @@
|
||||
#include <glib.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <gmodule.h>
|
||||
#include <girepository.h>
|
||||
|
||||
#include "girwriter.h"
|
||||
#include "girepository.h"
|
||||
#include "girwriter-private.h"
|
||||
#include "gitypelib-internal.h"
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
GIRepository *repository = NULL;
|
||||
gboolean shlib = FALSE;
|
||||
gchar *output = NULL;
|
||||
gchar **includedirs = NULL;
|
||||
@ -53,13 +54,11 @@ main (int argc, char *argv[])
|
||||
{ "all", 0, 0, G_OPTION_ARG_NONE, &show_all, "show all available information", NULL, },
|
||||
{ "version", 0, 0, G_OPTION_ARG_NONE, &show_version, "show program's version number and exit", NULL },
|
||||
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &input, NULL, NULL },
|
||||
{ NULL, }
|
||||
G_OPTION_ENTRY_NULL
|
||||
};
|
||||
|
||||
g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL);
|
||||
|
||||
g_typelib_check_sanity ();
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
|
||||
context = g_option_context_new ("");
|
||||
@ -73,8 +72,8 @@ main (int argc, char *argv[])
|
||||
|
||||
if (show_version)
|
||||
{
|
||||
g_printf ("g-ir-generate %u.%u.%u\n",
|
||||
GI_MAJOR_VERSION, GI_MINOR_VERSION, GI_MICRO_VERSION);
|
||||
g_printf ("gi-decompile-typelib %u.%u.%u\n",
|
||||
GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -85,14 +84,17 @@ main (int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
repository = gi_repository_new ();
|
||||
|
||||
if (includedirs != NULL)
|
||||
for (i = 0; includedirs[i]; i++)
|
||||
g_irepository_prepend_search_path (includedirs[i]);
|
||||
gi_repository_prepend_search_path (repository, includedirs[i]);
|
||||
|
||||
for (i = 0; input[i]; i++)
|
||||
{
|
||||
const char *namespace;
|
||||
GMappedFile *mfile;
|
||||
GMappedFile *mfile = NULL;
|
||||
GBytes *bytes = NULL;
|
||||
GITypelib *typelib;
|
||||
|
||||
error = NULL;
|
||||
@ -100,21 +102,23 @@ main (int argc, char *argv[])
|
||||
if (!mfile)
|
||||
g_error ("failed to read '%s': %s", input[i], error->message);
|
||||
|
||||
bytes = g_mapped_file_get_bytes (mfile);
|
||||
g_clear_pointer (&mfile, g_mapped_file_unref);
|
||||
|
||||
if (input[i + 1] && output)
|
||||
needs_prefix = TRUE;
|
||||
else
|
||||
needs_prefix = FALSE;
|
||||
|
||||
typelib = g_typelib_new_from_mapped_file (mfile, &error);
|
||||
typelib = gi_typelib_new_from_bytes (bytes, &error);
|
||||
if (!typelib)
|
||||
g_error ("failed to create typelib '%s': %s", input[i], error->message);
|
||||
|
||||
namespace = g_irepository_load_typelib (g_irepository_get_default (), typelib, 0,
|
||||
&error);
|
||||
namespace = gi_repository_load_typelib (repository, typelib, 0, &error);
|
||||
if (namespace == NULL)
|
||||
g_error ("failed to load typelib: %s", error->message);
|
||||
|
||||
gir_writer_write (output, namespace, needs_prefix, show_all);
|
||||
|
||||
gi_ir_writer_write (output, namespace, needs_prefix, show_all);
|
||||
|
||||
/* when writing to stdout, stop after the first module */
|
||||
if (input[i + 1] && !output)
|
||||
@ -126,5 +130,7 @@ main (int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
g_clear_object (&repository);
|
||||
|
||||
return 0;
|
||||
}
|
25
girepository/decompiler/meson.build
Normal file
25
girepository/decompiler/meson.build
Normal file
@ -0,0 +1,25 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
# SPDX-FileCopyrightText: 2024 GNOME Foundation
|
||||
|
||||
custom_c_args = [
|
||||
'-DG_LOG_DOMAIN="GLib-GirDecompiler"',
|
||||
]
|
||||
|
||||
if cc.get_id() != 'msvc'
|
||||
custom_c_args = cc.get_supported_arguments([
|
||||
'-Wno-old-style-definition',
|
||||
'-Wno-cast-align',
|
||||
'-Wno-unused-parameter',
|
||||
'-Wno-duplicated-branches',
|
||||
])
|
||||
endif
|
||||
|
||||
gidecompiletypelib = executable('gi-decompile-typelib', 'decompiler.c',
|
||||
dependencies: [
|
||||
libgirepository_dep,
|
||||
libgirepository_internals_dep,
|
||||
libgio_dep,
|
||||
],
|
||||
install: true,
|
||||
c_args: custom_c_args,
|
||||
)
|
@ -167,7 +167,7 @@ xml_free (Xml *xml)
|
||||
static void
|
||||
check_unresolved (GIBaseInfo *info)
|
||||
{
|
||||
if (gi_base_info_get_info_type (info) != GI_INFO_TYPE_UNRESOLVED)
|
||||
if (!GI_IS_UNRESOLVED_INFO (info))
|
||||
return;
|
||||
|
||||
g_critical ("Found unresolved type '%s' '%s'",
|
||||
@ -442,7 +442,7 @@ write_field_info (const char *ns,
|
||||
}
|
||||
|
||||
interface = gi_type_info_get_interface (type);
|
||||
if (interface && gi_base_info_get_info_type (interface) == GI_INFO_TYPE_CALLBACK)
|
||||
if (interface != NULL && GI_IS_CALLBACK_INFO (interface))
|
||||
write_callback_info (ns, (GICallbackInfo *)interface, file);
|
||||
else
|
||||
write_type_info (ns, type, file);
|
||||
@ -660,7 +660,7 @@ write_struct_info (const char *ns,
|
||||
type_name = gi_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info);
|
||||
type_init = gi_registered_type_info_get_type_init_function_name ((GIRegisteredTypeInfo*)info);
|
||||
|
||||
if (gi_base_info_get_info_type ((GIBaseInfo *) info) == GI_INFO_TYPE_BOXED)
|
||||
if (GI_IS_BOXED_INFO (info))
|
||||
{
|
||||
xml_start_element (file, "glib:boxed");
|
||||
xml_printf (file, " glib:name=\"%s\"", name);
|
||||
@ -847,7 +847,7 @@ write_enum_info (const char *ns,
|
||||
type_init = gi_registered_type_info_get_type_init_function_name ((GIRegisteredTypeInfo*)info);
|
||||
error_domain = gi_enum_info_get_error_domain (info);
|
||||
|
||||
if (gi_base_info_get_info_type ((GIBaseInfo *) info) == GI_INFO_TYPE_ENUM)
|
||||
if (GI_IS_ENUM_INFO (info))
|
||||
xml_start_element (file, "enumeration");
|
||||
else
|
||||
xml_start_element (file, "bitfield");
|
||||
@ -1415,45 +1415,27 @@ gi_ir_writer_write (const char *filename,
|
||||
for (j = 0; j < n_infos; j++)
|
||||
{
|
||||
GIBaseInfo *info = gi_repository_get_info (repository, cur_ns, j);
|
||||
switch (gi_base_info_get_info_type (info))
|
||||
{
|
||||
case GI_INFO_TYPE_FUNCTION:
|
||||
write_function_info (ns, (GIFunctionInfo *)info, xml);
|
||||
break;
|
||||
|
||||
case GI_INFO_TYPE_CALLBACK:
|
||||
write_callback_info (ns, (GICallbackInfo *)info, xml);
|
||||
break;
|
||||
|
||||
case GI_INFO_TYPE_STRUCT:
|
||||
case GI_INFO_TYPE_BOXED:
|
||||
write_struct_info (ns, (GIStructInfo *)info, xml);
|
||||
break;
|
||||
|
||||
case GI_INFO_TYPE_UNION:
|
||||
write_union_info (ns, (GIUnionInfo *)info, xml);
|
||||
break;
|
||||
|
||||
case GI_INFO_TYPE_ENUM:
|
||||
case GI_INFO_TYPE_FLAGS:
|
||||
write_enum_info (ns, (GIEnumInfo *)info, xml);
|
||||
break;
|
||||
|
||||
case GI_INFO_TYPE_CONSTANT:
|
||||
write_constant_info (ns, (GIConstantInfo *)info, xml);
|
||||
break;
|
||||
|
||||
case GI_INFO_TYPE_OBJECT:
|
||||
write_object_info (ns, (GIObjectInfo *)info, xml);
|
||||
break;
|
||||
|
||||
case GI_INFO_TYPE_INTERFACE:
|
||||
write_interface_info (ns, (GIInterfaceInfo *)info, xml);
|
||||
break;
|
||||
|
||||
default:
|
||||
g_error ("unknown info type %d", gi_base_info_get_info_type (info));
|
||||
}
|
||||
if (GI_IS_FUNCTION_INFO (info))
|
||||
write_function_info (ns, (GIFunctionInfo *)info, xml);
|
||||
else if (GI_IS_CALLBACK_INFO (info))
|
||||
write_callback_info (ns, (GICallbackInfo *)info, xml);
|
||||
else if (GI_IS_STRUCT_INFO (info) ||
|
||||
GI_IS_BOXED_INFO (info))
|
||||
write_struct_info (ns, (GIStructInfo *)info, xml);
|
||||
else if (GI_IS_UNION_INFO (info))
|
||||
write_union_info (ns, (GIUnionInfo *)info, xml);
|
||||
else if (GI_IS_ENUM_INFO (info) ||
|
||||
GI_IS_FLAGS_INFO (info))
|
||||
write_enum_info (ns, (GIEnumInfo *)info, xml);
|
||||
else if (GI_IS_CONSTANT_INFO (info))
|
||||
write_constant_info (ns, (GIConstantInfo *)info, xml);
|
||||
else if (GI_IS_OBJECT_INFO (info))
|
||||
write_object_info (ns, (GIObjectInfo *)info, xml);
|
||||
else if (GI_IS_INTERFACE_INFO (info))
|
||||
write_interface_info (ns, (GIInterfaceInfo *)info, xml);
|
||||
else
|
||||
g_error ("unknown info type %s", g_type_name (G_TYPE_FROM_INSTANCE (info)));
|
||||
|
||||
gi_base_info_unref (info);
|
||||
}
|
||||
|
@ -27,29 +27,23 @@
|
||||
#include <locale.h>
|
||||
|
||||
static void
|
||||
print_shlibs (const gchar *namespace)
|
||||
print_shlibs (GIRepository *repository,
|
||||
const gchar *namespace)
|
||||
{
|
||||
guint i = 0;
|
||||
|
||||
/* Finding the shared library we depend on (if any) */
|
||||
const gchar *shlibs = g_irepository_get_shared_library (NULL, namespace);
|
||||
if (shlibs && shlibs[0] != '\0')
|
||||
{
|
||||
/* shlibs is a comma-separated list of libraries */
|
||||
GStrv libs = g_strsplit (shlibs, ",", -1);
|
||||
for (i = 0; libs[i]; i++)
|
||||
g_print ("shlib: %s\n", libs[i]);
|
||||
g_strfreev (libs);
|
||||
}
|
||||
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]);
|
||||
}
|
||||
|
||||
static void
|
||||
print_typelibs (const gchar *namespace)
|
||||
print_typelibs (GIRepository *repository,
|
||||
const gchar *namespace)
|
||||
{
|
||||
guint i = 0;
|
||||
|
||||
/* Finding all the typelib-based Requires */
|
||||
GStrv deps = g_irepository_get_dependencies (NULL, namespace);
|
||||
GStrv deps = gi_repository_get_dependencies (repository, namespace, NULL);
|
||||
if (deps)
|
||||
{
|
||||
for (i = 0; deps[i]; i++)
|
||||
@ -65,6 +59,7 @@ main (gint argc,
|
||||
gint status = EXIT_SUCCESS;
|
||||
|
||||
GError *error = NULL;
|
||||
GIRepository *repository = NULL;
|
||||
GITypelib *typelib = NULL;
|
||||
|
||||
gchar *version = NULL;
|
||||
@ -73,11 +68,11 @@ main (gint argc,
|
||||
GStrv namespaces = NULL;
|
||||
const gchar *namespace = NULL;
|
||||
const GOptionEntry options[] = {
|
||||
{ "version", 0, 0, G_OPTION_ARG_STRING, &version, "Typelib version to inspect", "VERSION" },
|
||||
{ "print-shlibs", 0, 0, G_OPTION_ARG_NONE, &opt_shlibs, "List the shared libraries the typelib requires" },
|
||||
{ "print-typelibs", 0, 0, G_OPTION_ARG_NONE, &opt_typelibs, "List other typelibs the inspected typelib requires" },
|
||||
{ "typelib-version", 0, 0, G_OPTION_ARG_STRING, &version, "Typelib version to inspect", "VERSION" },
|
||||
{ "print-shlibs", 0, 0, G_OPTION_ARG_NONE, &opt_shlibs, "List the shared libraries the typelib requires", NULL },
|
||||
{ "print-typelibs", 0, 0, G_OPTION_ARG_NONE, &opt_typelibs, "List other typelibs the inspected typelib requires", NULL },
|
||||
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &namespaces, "The typelib to inspect", "NAMESPACE" },
|
||||
{ NULL },
|
||||
G_OPTION_ENTRY_NULL
|
||||
};
|
||||
GOptionContext *context = NULL;
|
||||
|
||||
@ -114,7 +109,8 @@ main (gint argc,
|
||||
goto out;
|
||||
}
|
||||
|
||||
typelib = g_irepository_require (NULL, namespace, version, 0, &error);
|
||||
repository = gi_repository_new ();
|
||||
typelib = gi_repository_require (repository, namespace, version, 0, &error);
|
||||
if (!typelib)
|
||||
{
|
||||
status = EXIT_FAILURE;
|
||||
@ -123,16 +119,15 @@ main (gint argc,
|
||||
}
|
||||
|
||||
if (opt_shlibs)
|
||||
print_shlibs (namespace);
|
||||
print_shlibs (repository, namespace);
|
||||
if (opt_typelibs)
|
||||
print_typelibs (namespace);
|
||||
print_typelibs (repository, namespace);
|
||||
|
||||
out:
|
||||
g_option_context_free (context);
|
||||
if (error)
|
||||
g_error_free (error);
|
||||
if (typelib)
|
||||
g_typelib_free (typelib);
|
||||
g_clear_object (&repository);
|
||||
g_strfreev (namespaces);
|
||||
g_free (version);
|
||||
|
24
girepository/inspector/meson.build
Normal file
24
girepository/inspector/meson.build
Normal file
@ -0,0 +1,24 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
# SPDX-FileCopyrightText: 2024 GNOME Foundation
|
||||
|
||||
custom_c_args = [
|
||||
'-DG_LOG_DOMAIN="GLib-GirInspector"',
|
||||
]
|
||||
|
||||
if cc.get_id() != 'msvc'
|
||||
custom_c_args = cc.get_supported_arguments([
|
||||
'-Wno-old-style-definition',
|
||||
'-Wno-cast-align',
|
||||
'-Wno-unused-parameter',
|
||||
'-Wno-duplicated-branches',
|
||||
])
|
||||
endif
|
||||
|
||||
giinspecttypelib = executable('gi-inspect-typelib', 'inspector.c',
|
||||
dependencies: [
|
||||
libgirepository_dep,
|
||||
libgio_dep,
|
||||
],
|
||||
install: true,
|
||||
c_args: custom_c_args,
|
||||
)
|
@ -243,3 +243,5 @@ if build_tests
|
||||
endif
|
||||
|
||||
subdir('compiler')
|
||||
subdir('decompiler')
|
||||
subdir('inspector')
|
Loading…
Reference in New Issue
Block a user