From 5d997cad033243f86bdf7e4b104c403bdab8c898 Mon Sep 17 00:00:00 2001 From: Evan Welsh Date: Mon, 15 Jan 2024 23:21:02 -0800 Subject: [PATCH] girepository: Update gi-compile-repository and use it to compile GIRs Adapt gi-compile-repository sources to compile against the updated libgirepository that is included with GLib. This also renames "g-ir-compiler" to "gi-compile-repository" to avoid overwriting the existing binary and to simplify the binary name going forward. --- girepository/{tools => compiler}/compiler.c | 55 ++++++++++----------- girepository/compiler/meson.build | 29 +++++++++++ girepository/gifieldinfo.c | 2 +- girepository/meson.build | 2 + girepository/tests/meson.build | 3 ++ 5 files changed, 61 insertions(+), 30 deletions(-) rename girepository/{tools => compiler}/compiler.c (82%) create mode 100644 girepository/compiler/meson.build diff --git a/girepository/tools/compiler.c b/girepository/compiler/compiler.c similarity index 82% rename from girepository/tools/compiler.c rename to girepository/compiler/compiler.c index 182b00b36..27c5ac62a 100644 --- a/girepository/tools/compiler.c +++ b/girepository/compiler/compiler.c @@ -1,22 +1,25 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- - * GObject introspection: Typelib compiler +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ + +/* GObject introspection: Typelib compiler + * * + * SPDX-License-Identifier: LGPL-2.1-or-later + * Copyright (C) 2005 Matthias Clasen + * Copyright (C) 2024 GNOME Foundation * * 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. + * 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, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, see . */ #include @@ -26,16 +29,16 @@ #include #include #include +#include #ifdef G_OS_WIN32 #include #include #endif -#include "girmodule.h" -#include "girnode.h" -#include "girparser.h" -#include "gitypelib-internal.h" +#include "girmodule-private.h" +#include "girnode-private.h" +#include "girparser-private.h" gchar **includedirs = NULL; gchar **input = NULL; @@ -140,7 +143,7 @@ static GOptionEntry options[] = { "verbose", 0, 0, G_OPTION_ARG_NONE, &verbose, "show verbose messages", 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 }; int @@ -148,10 +151,8 @@ main (int argc, char ** argv) { GOptionContext *context; GError *error = NULL; - GIrParser *parser; - GIrModule *module; - gint i; - g_typelib_check_sanity (); + GIIrParser *parser; + GIIrModule *module; setlocale (LC_ALL, ""); @@ -180,8 +181,8 @@ main (int argc, char ** argv) if (show_version) { - g_printf ("g-ir-compiler %u.%u.%u\n", - GI_MAJOR_VERSION, GI_MINOR_VERSION, GI_MICRO_VERSION); + g_printf ("gi-compile-repository %u.%u.%u\n", + GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION); return 0; } @@ -195,15 +196,11 @@ main (int argc, char ** argv) g_debug ("[parsing] start, %d includes", includedirs ? g_strv_length (includedirs) : 0); - if (includedirs != NULL) - for (i = 0; includedirs[i]; i++) - g_irepository_prepend_search_path (includedirs[i]); + parser = gi_ir_parser_new (); - parser = _g_ir_parser_new (); + gi_ir_parser_set_includes (parser, (const char*const*) includedirs); - _g_ir_parser_set_includes (parser, (const char*const*) includedirs); - - module = _g_ir_parser_parse_file (parser, input[0], &error); + module = gi_ir_parser_parse_file (parser, input[0], &error); if (module == NULL) { g_fprintf (stderr, "error parsing file %s: %s\n", @@ -228,16 +225,16 @@ main (int argc, char ** argv) g_debug ("[building] module %s", module->name); - typelib = _g_ir_module_build_typelib (module); + typelib = gi_ir_module_build_typelib (module); if (typelib == NULL) g_error ("Failed to build typelib for module '%s'\n", module->name); - if (!g_typelib_validate (typelib, &error)) + if (!gi_typelib_validate (typelib, &error)) g_error ("Invalid typelib for module '%s': %s", module->name, error->message); if (!write_out_typelib (NULL, typelib)) return 1; - g_typelib_free (typelib); + gi_typelib_free (typelib); typelib = NULL; } @@ -245,7 +242,7 @@ main (int argc, char ** argv) #if 0 /* No point */ - _g_ir_parser_free (parser); + gi_ir_parser_free (parser); #endif return 0; diff --git a/girepository/compiler/meson.build b/girepository/compiler/meson.build new file mode 100644 index 000000000..7ac3d936e --- /dev/null +++ b/girepository/compiler/meson.build @@ -0,0 +1,29 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +# SPDX-FileCopyrightText: 2024 GNOME Foundation + +custom_c_args = [ + '-DG_LOG_DOMAIN="GLib-GirCompiler"', +] + +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 + +gicompilerepository = executable('gi-compile-repository', 'compiler.c', + dependencies: [ + libgirepository_dep, + libgirepository_internals_dep, + libgio_dep, + ], + install: true, + c_args: custom_c_args, +) + +# Replace the default g-ir-compiler target with the version we +# just built. +meson.override_find_program('g-ir-compiler', gicompilerepository) diff --git a/girepository/gifieldinfo.c b/girepository/gifieldinfo.c index 69c0fec20..5d362a449 100644 --- a/girepository/gifieldinfo.c +++ b/girepository/gifieldinfo.c @@ -255,7 +255,7 @@ gi_field_info_get_field (GIFieldInfo *field_info, break; case GI_TYPE_TAG_ARRAY: /* We don't check the array type and that it is fixed-size, - we trust g-ir-compiler to do the right thing */ + we trust gi-compile-repository to do the right thing */ value->v_pointer = G_STRUCT_MEMBER_P (mem, offset); result = TRUE; break; diff --git a/girepository/meson.build b/girepository/meson.build index 45a935452..3dd539376 100644 --- a/girepository/meson.build +++ b/girepository/meson.build @@ -241,3 +241,5 @@ endif if build_tests subdir('tests') endif + +subdir('compiler') diff --git a/girepository/tests/meson.build b/girepository/tests/meson.build index 01c01c936..3af29bd36 100644 --- a/girepository/tests/meson.build +++ b/girepository/tests/meson.build @@ -1,3 +1,6 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +# SPDX-FileCopyrightText: 2024 GNOME Foundation + girepository_tests = { 'cmph-bdz': { 'dependencies': [cmph_dep],