-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gnome: Add support for gi-compile-repository for generate_gir #13997
Open
ewlsh
wants to merge
1
commit into
mesonbuild:master
Choose a base branch
from
ewlsh:ewlsh/gi-compile-repository
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,7 @@ class GenerateGir(TypedDict): | |
nsversion: str | ||
sources: T.List[T.Union[FileOrString, build.GeneratedTypes]] | ||
symbol_prefix: T.List[str] | ||
use_glib_to_compile_repositories: bool | ||
|
||
class GtkDoc(TypedDict): | ||
|
||
|
@@ -252,6 +253,7 @@ class GnomeModule(ExtensionModule): | |
def __init__(self, interpreter: 'Interpreter') -> None: | ||
super().__init__(interpreter) | ||
self.gir_dep: T.Optional[Dependency] = None | ||
self.girepository_dep: T.Optional[Dependency] = None | ||
self.giscanner: T.Optional[T.Union[ExternalProgram, Executable, OverrideProgram]] = None | ||
self.gicompiler: T.Optional[T.Union[ExternalProgram, Executable, OverrideProgram]] = None | ||
self.install_glib_compile_schemas = False | ||
|
@@ -307,17 +309,18 @@ def _print_gdbus_warning() -> None: | |
@staticmethod | ||
def _find_tool(state: 'ModuleState', tool: str) -> 'ToolType': | ||
tool_map = { | ||
'gio-querymodules': 'gio-2.0', | ||
'glib-compile-schemas': 'gio-2.0', | ||
'glib-compile-resources': 'gio-2.0', | ||
'gdbus-codegen': 'gio-2.0', | ||
'glib-genmarshal': 'glib-2.0', | ||
'glib-mkenums': 'glib-2.0', | ||
'g-ir-scanner': 'gobject-introspection-1.0', | ||
'g-ir-compiler': 'gobject-introspection-1.0', | ||
'gio-querymodules': ('gio-2.0', 'gio_querymodules'), | ||
'glib-compile-schemas': ('gio-2.0', 'glib_compile_schemas'), | ||
'glib-compile-resources': ('gio-2.0', 'glib_compile_resources'), | ||
'gdbus-codegen': ('gio-2.0', 'gdbus_codegen'), | ||
'glib-genmarshal': ('glib-2.0', 'glib_genmarshal'), | ||
'glib-mkenums': ('glib-2.0', 'glib_mkenums'), | ||
# TODO: Use gi_compile_repository once GLib exposes it | ||
'gi-compile-repository': ('girepository-2.0', None), | ||
'g-ir-scanner': ('gobject-introspection-1.0', 'g_ir_scanner'), | ||
'g-ir-compiler': ('gobject-introspection-1.0', 'g_ir_compiler'), | ||
} | ||
depname = tool_map[tool] | ||
varname = tool.replace('-', '_') | ||
depname, varname = tool_map[tool] | ||
return state.find_tool(tool, depname, varname) | ||
|
||
@typed_kwargs( | ||
|
@@ -763,7 +766,7 @@ def _get_dependencies_flags( | |
|
||
return cflags, internal_ldflags, external_ldflags, gi_includes, depends | ||
|
||
def _unwrap_gir_target(self, girtarget: T.Union[Executable, build.StaticLibrary, build.SharedLibrary], state: 'ModuleState' | ||
def _unwrap_gir_target(self, girtarget: T.Union[Executable, build.StaticLibrary, build.SharedLibrary], state: 'ModuleState', use_glib_to_compile_repositories: bool | ||
) -> T.Union[Executable, build.StaticLibrary, build.SharedLibrary]: | ||
if not isinstance(girtarget, (Executable, build.SharedLibrary, | ||
build.StaticLibrary)): | ||
|
@@ -772,7 +775,7 @@ def _unwrap_gir_target(self, girtarget: T.Union[Executable, build.StaticLibrary, | |
STATIC_BUILD_REQUIRED_VERSION = ">=1.58.1" | ||
if isinstance(girtarget, (build.StaticLibrary)) and \ | ||
not mesonlib.version_compare( | ||
self._get_gir_dep(state)[0].get_version(), | ||
self._get_gir_dep(state, use_glib_to_compile_repositories=use_glib_to_compile_repositories)[0].get_version(), | ||
STATIC_BUILD_REQUIRED_VERSION): | ||
raise MesonException('Static libraries can only be introspected with GObject-Introspection ' + STATIC_BUILD_REQUIRED_VERSION) | ||
|
||
|
@@ -787,12 +790,21 @@ def postconf_hook(self, b: build.Build) -> None: | |
if self.devenv is not None: | ||
b.devenv.append(self.devenv) | ||
|
||
def _get_gir_dep(self, state: 'ModuleState') -> T.Tuple[Dependency, T.Union[Executable, 'ExternalProgram', 'OverrideProgram'], | ||
def _get_gir_dep(self, state: 'ModuleState', use_glib_to_compile_repositories: bool) -> T.Tuple[Dependency, T.Union[Executable, 'ExternalProgram', 'OverrideProgram'], | ||
T.Union[Executable, 'ExternalProgram', 'OverrideProgram']]: | ||
if not self.girepository_dep and use_glib_to_compile_repositories: | ||
self.girepository_dep = state.dependency('girepository-2.0') | ||
|
||
if not self.gir_dep: | ||
self.gir_dep = state.dependency('gobject-introspection-1.0') | ||
self.giscanner = self._find_tool(state, 'g-ir-scanner') | ||
self.gicompiler = self._find_tool(state, 'g-ir-compiler') | ||
|
||
if not self.gicompiler and not use_glib_to_compile_repositories: | ||
self.gicompiler = self._find_tool(state, 'gi-compile-repository') | ||
|
||
if not self.gicompiler and use_glib_to_compile_repositories: | ||
self.gicompiler = self._find_tool(state, 'gi-compile-repository') | ||
|
||
return self.gir_dep, self.giscanner, self.gicompiler | ||
|
||
@functools.lru_cache(maxsize=None) | ||
|
@@ -1112,6 +1124,7 @@ def _get_scanner_ldflags(ldflags: T.Iterable[str]) -> T.Iterable[str]: | |
KwargInfo('install_dir_gir', (str, bool, NoneType), | ||
deprecated_values={False: ('0.61.0', 'Use install_gir to disable installation')}, | ||
validator=lambda x: 'as boolean can only be false' if x is True else None), | ||
KwargInfo('use_glib_to_compile_repositories', (bool), default=False), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not just a long name, it's an unfortunately long name... |
||
KwargInfo('install_typelib', (bool, NoneType), since='0.61.0'), | ||
KwargInfo('install_dir_typelib', (str, bool, NoneType), | ||
deprecated_values={False: ('0.61.0', 'Use install_typelib to disable installation')}, | ||
|
@@ -1127,11 +1140,13 @@ def generate_gir(self, state: 'ModuleState', args: T.Tuple[T.List[T.Union[Execut | |
# Ensure we have a C compiler even in C++ projects. | ||
state.add_language('c', MachineChoice.HOST) | ||
|
||
girtargets = [self._unwrap_gir_target(arg, state) for arg in args[0]] | ||
use_glib_to_compile_repositories = kwargs['use_glib_to_compile_repositories'] | ||
|
||
girtargets = [self._unwrap_gir_target(arg, state, use_glib_to_compile_repositories=use_glib_to_compile_repositories) for arg in args[0]] | ||
if len(girtargets) > 1 and any(isinstance(el, Executable) for el in girtargets): | ||
raise MesonException('generate_gir only accepts a single argument when one of the arguments is an executable') | ||
|
||
gir_dep, giscanner, gicompiler = self._get_gir_dep(state) | ||
gir_dep, giscanner, gicompiler = self._get_gir_dep(state, use_glib_to_compile_repositories=use_glib_to_compile_repositories) | ||
|
||
ns = kwargs['namespace'] | ||
nsversion = kwargs['nsversion'] | ||
|
6 changes: 6 additions & 0 deletions
6
test cases/frameworks/39 gnome glib compile repository/copyfile.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
import shutil | ||
|
||
shutil.copy(sys.argv[1], sys.argv[2]) |
18 changes: 18 additions & 0 deletions
18
test cases/frameworks/39 gnome glib compile repository/gir/copy.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env python3 | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# Copyright © 2021 Intel Corporation | ||
|
||
import argparse | ||
import shutil | ||
|
||
def main() -> None: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('src') | ||
parser.add_argument('dest') | ||
args = parser.parse_args() | ||
|
||
shutil.copy(args.src, args.dest) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
56 changes: 56 additions & 0 deletions
56
test cases/frameworks/39 gnome glib compile repository/gir/dep1/dep1.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include "dep1.h" | ||
|
||
struct _MesonDep1 | ||
{ | ||
GObject parent_instance; | ||
}; | ||
|
||
G_DEFINE_TYPE (MesonDep1, meson_dep1, G_TYPE_OBJECT) | ||
|
||
/** | ||
* meson_dep1_new: | ||
* | ||
* Allocates a new #MesonDep1. | ||
* | ||
* Returns: (transfer full): a #MesonDep1. | ||
*/ | ||
MesonDep1 * | ||
meson_dep1_new (void) | ||
{ | ||
return g_object_new (MESON_TYPE_DEP1, NULL); | ||
} | ||
|
||
static void | ||
meson_dep1_finalize (GObject *object) | ||
{ | ||
G_OBJECT_CLASS (meson_dep1_parent_class)->finalize (object); | ||
} | ||
|
||
static void | ||
meson_dep1_class_init (MesonDep1Class *klass) | ||
{ | ||
GObjectClass *object_class = G_OBJECT_CLASS (klass); | ||
|
||
object_class->finalize = meson_dep1_finalize; | ||
} | ||
|
||
static void | ||
meson_dep1_init (MesonDep1 *self) | ||
{ | ||
} | ||
|
||
/** | ||
* meson_dep1_just_return_it: | ||
* @dep: a #MesonDep2. | ||
* | ||
* Returns the #MesonDep2 that is passed in | ||
* | ||
* Returns: (transfer none): a #MesonDep2 | ||
*/ | ||
MesonDep2* | ||
meson_dep1_just_return_it (MesonDep1 *self, MesonDep2 *dep) | ||
{ | ||
g_return_val_if_fail (MESON_IS_DEP1 (self), NULL); | ||
|
||
return dep; | ||
} |
23 changes: 23 additions & 0 deletions
23
test cases/frameworks/39 gnome glib compile repository/gir/dep1/dep1.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef MESON_DEP1_H | ||
#define MESON_DEP1_H | ||
|
||
#if !defined (MESON_TEST_1) | ||
#error "MESON_TEST_1 not defined." | ||
#endif | ||
|
||
#include <glib-object.h> | ||
#include "dep2/dep2.h" | ||
|
||
G_BEGIN_DECLS | ||
|
||
#define MESON_TYPE_DEP1 (meson_dep1_get_type()) | ||
|
||
G_DECLARE_FINAL_TYPE (MesonDep1, meson_dep1, MESON, DEP1, GObject) | ||
|
||
MesonDep1 *meson_dep1_new (void); | ||
MesonDep2 *meson_dep1_just_return_it (MesonDep1 *self, | ||
MesonDep2 *dep); | ||
|
||
G_END_DECLS | ||
|
||
#endif /* MESON_DEP1_H */ |
124 changes: 124 additions & 0 deletions
124
test cases/frameworks/39 gnome glib compile repository/gir/dep1/dep2/dep2.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#include "dep2.h" | ||
|
||
struct _MesonDep2 | ||
{ | ||
GObject parent_instance; | ||
|
||
gchar *msg; | ||
}; | ||
|
||
G_DEFINE_TYPE (MesonDep2, meson_dep2, G_TYPE_OBJECT) | ||
|
||
enum { | ||
PROP_0, | ||
PROP_MSG, | ||
LAST_PROP | ||
}; | ||
|
||
static GParamSpec *gParamSpecs [LAST_PROP]; | ||
|
||
/** | ||
* meson_dep2_new: | ||
* @msg: The message to set. | ||
* | ||
* Allocates a new #MesonDep2. | ||
* | ||
* Returns: (transfer full): a #MesonDep2. | ||
*/ | ||
MesonDep2 * | ||
meson_dep2_new (const gchar *msg) | ||
{ | ||
g_return_val_if_fail (msg != NULL, NULL); | ||
|
||
return g_object_new (MESON_TYPE_DEP2, | ||
"message", msg, | ||
NULL); | ||
} | ||
|
||
static void | ||
meson_dep2_finalize (GObject *object) | ||
{ | ||
MesonDep2 *self = (MesonDep2 *)object; | ||
|
||
g_clear_pointer (&self->msg, g_free); | ||
|
||
G_OBJECT_CLASS (meson_dep2_parent_class)->finalize (object); | ||
} | ||
|
||
static void | ||
meson_dep2_get_property (GObject *object, | ||
guint prop_id, | ||
GValue *value, | ||
GParamSpec *pspec) | ||
{ | ||
MesonDep2 *self = MESON_DEP2 (object); | ||
|
||
switch (prop_id) | ||
{ | ||
case PROP_MSG: | ||
g_value_set_string (value, self->msg); | ||
break; | ||
default: | ||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | ||
} | ||
} | ||
|
||
static void | ||
meson_dep2_set_property (GObject *object, | ||
guint prop_id, | ||
const GValue *value, | ||
GParamSpec *pspec) | ||
{ | ||
MesonDep2 *self = MESON_DEP2 (object); | ||
|
||
switch (prop_id) | ||
{ | ||
case PROP_MSG: | ||
self->msg = g_value_dup_string (value); | ||
break; | ||
default: | ||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | ||
} | ||
} | ||
|
||
static void | ||
meson_dep2_class_init (MesonDep2Class *klass) | ||
{ | ||
GObjectClass *object_class = G_OBJECT_CLASS (klass); | ||
|
||
object_class->finalize = meson_dep2_finalize; | ||
object_class->get_property = meson_dep2_get_property; | ||
object_class->set_property = meson_dep2_set_property; | ||
|
||
gParamSpecs [PROP_MSG] = | ||
g_param_spec_string ("message", | ||
"Message", | ||
"The message to print.", | ||
NULL, | ||
(G_PARAM_READWRITE | | ||
G_PARAM_CONSTRUCT_ONLY | | ||
G_PARAM_STATIC_STRINGS)); | ||
|
||
g_object_class_install_properties (object_class, LAST_PROP, gParamSpecs); | ||
} | ||
|
||
static void | ||
meson_dep2_init (MesonDep2 *self) | ||
{ | ||
} | ||
|
||
/** | ||
* meson_dep2_return_message: | ||
* @self: a #MesonDep2. | ||
* | ||
* Returns the message. | ||
* | ||
* Returns: (transfer none): a const gchar* | ||
*/ | ||
const gchar* | ||
meson_dep2_return_message (MesonDep2 *self) | ||
{ | ||
g_return_val_if_fail (MESON_IS_DEP2 (self), NULL); | ||
|
||
return (const gchar*) self->msg; | ||
} |
21 changes: 21 additions & 0 deletions
21
test cases/frameworks/39 gnome glib compile repository/gir/dep1/dep2/dep2.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef MESON_DEP2_H | ||
#define MESON_DEP2_H | ||
|
||
#if !defined (MESON_TEST_1) | ||
#error "MESON_TEST_1 not defined." | ||
#endif | ||
|
||
#include <glib-object.h> | ||
|
||
G_BEGIN_DECLS | ||
|
||
#define MESON_TYPE_DEP2 (meson_dep2_get_type()) | ||
|
||
G_DECLARE_FINAL_TYPE (MesonDep2, meson_dep2, MESON, DEP2, GObject) | ||
|
||
MesonDep2 *meson_dep2_new (const gchar *msg); | ||
const gchar *meson_dep2_return_message (MesonDep2 *self); | ||
|
||
G_END_DECLS | ||
|
||
#endif /* MESON_DEP2_H */ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code as-written does not allow looking up tools which are not in pkg-config, this adapts the code to allow finding tools via binary lookup only