diff options
10 files changed, 499 insertions, 76 deletions
diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index d8c8f10..4f72d2f 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -103,22 +103,33 @@ class GnomeModule: depends.append(lib) return link_command - def get_include_args(self, state, include_dirs): + def get_include_args(self, state, include_dirs, prefix='-I'): if not include_dirs: return [] + build_to_src = os.path.relpath(state.environment.get_source_dir(), + state.environment.get_build_dir()) dirs_str = [] for incdirs in include_dirs: if hasattr(incdirs, "held_object"): dirs = incdirs.held_object else: dirs = incdirs - for incdir in dirs.get_incdirs(): - if os.path.isabs(incdir): - dirs_str += ['-I%s' % os.path.join(incdir)] - else: - dirs_str += ['-I%s' % os.path.join(state.environment.get_source_dir(), - dirs.curdir, incdir)] + + if isinstance(dirs, str): + dirs_str += ['%s%s' % (prefix, dirs)] + continue + + # Should be build.IncludeDirs object. + basedir = dirs.get_curdir() + for d in dirs.get_incdirs(): + expdir = os.path.join(basedir, d) + srctreedir = os.path.join(build_to_src, expdir) + dirs_str += ['%s%s' % (prefix, expdir), + '%s%s' % (prefix, srctreedir)] + for d in dirs.get_extra_build_dirs(): + dirs_str += ['%s%s' % (prefix, d)] + return dirs_str def generate_gir(self, state, args, kwargs): @@ -143,6 +154,7 @@ class GnomeModule: libsources = kwargs.pop('sources') girfile = '%s-%s.gir' % (ns, nsversion) depends = [girtarget] + gir_inc_dirs = [] scan_command = ['g-ir-scanner', '@INPUT@'] scan_command += pkgargs @@ -151,7 +163,7 @@ class GnomeModule: extra_args = mesonlib.stringlistify(kwargs.pop('extra_args', [])) scan_command += extra_args - scan_command += self.get_include_args(state, girtarget.include_dirs) + scan_command += self.get_include_args(state, girtarget.get_include_dirs()) if 'link_with' in kwargs: link_with = kwargs.pop('link_with') @@ -162,12 +174,25 @@ class GnomeModule: if 'includes' in kwargs: includes = kwargs.pop('includes') - if isinstance(includes, str): - scan_command += ['--include=%s' % includes] - elif isinstance(includes, list): - scan_command += ['--include=%s' % inc for inc in includes] - else: - raise MesonException('Gir includes must be str or list') + if not isinstance(includes, list): + includes = [includes] + for inc in includes: + if hasattr(inc, 'held_object'): + inc = inc.held_object + if isinstance(inc, str): + scan_command += ['--include=%s' % (inc, )] + elif isinstance(inc, GirTarget): + gir_inc_dirs += [ + os.path.join(state.environment.get_build_dir(), + inc.get_subdir()), + ] + scan_command += [ + "--include=%s" % (inc.get_basename()[:-4], ), + ] + depends += [inc] + else: + raise MesonException( + 'Gir includes must be str, GirTarget, or list of them') if state.global_args.get('c'): scan_command += ['--cflags-begin'] scan_command += state.global_args['c'] @@ -191,54 +216,69 @@ class GnomeModule: else: raise MesonException('Gir export packages must be str or list') - deps = None - if 'dependencies' in kwargs: - deps = kwargs.pop('dependencies') - if not isinstance (deps, list): - deps = [deps] - for dep in deps: - if isinstance(dep.held_object, dependencies.InternalDependency): - scan_command += self.get_include_args(state, dep.held_object.include_directories) - for lib in dep.held_object.libraries: - scan_command += self.get_link_args(state, lib.held_object, depends) - for source in dep.held_object.sources: - if isinstance(source.held_object, GirTarget): - scan_command += ["--add-include-path=%s" % - os.path.join(state.environment.get_build_dir(), - source.held_object.get_subdir())] - elif isinstance(dep.held_object, dependencies.PkgConfigDependency): - for lib in dep.held_object.libs: - if os.path.isabs(lib) and dep.held_object.is_libtool: - scan_command += ["-L%s" % os.path.dirname(lib)] - libname = os.path.basename(lib) - if libname.startswith("lib"): - libname = libname[3:] - libname = libname.split(".so")[0] - lib = "-l%s" % libname - # Hack to avoid passing some compiler options in - if lib.startswith("-W"): - continue - scan_command += [lib] - - girdir = dep.held_object.get_variable ("girdir") + deps = kwargs.pop('dependencies', []) + if not isinstance(deps, list): + deps = [deps] + deps = (girtarget.get_all_link_deps() + girtarget.get_external_deps() + + deps) + for dep in deps: + if hasattr(dep, 'held_object'): + dep = dep.held_object + if isinstance(dep, dependencies.InternalDependency): + scan_command += self.get_include_args( + state, + dep.include_directories) + for lib in dep.libraries: + scan_command += self.get_link_args(state, lib.held_object, + depends) + for source in dep.sources: + if isinstance(source.held_object, GirTarget): + scan_command += [ + "--add-include-path=%s" % ( + os.path.join(state.environment.get_build_dir(), + source.held_object.get_subdir()), + ) + ] + # This should be any dependency other than an internal one. + elif isinstance(dep, dependencies.Dependency): + scan_command += dep.get_compile_args() + for lib in dep.get_link_args(): + if (os.path.isabs(lib) and + # For PkgConfigDependency only: + getattr(dep, 'is_libtool', False)): + scan_command += ["-L%s" % os.path.dirname(lib)] + libname = os.path.basename(lib) + if libname.startswith("lib"): + libname = libname[3:] + libname = libname.split(".so")[0] + lib = "-l%s" % libname + # Hack to avoid passing some compiler options in + if lib.startswith("-W"): + continue + scan_command += [lib] + + if isinstance(dep, dependencies.PkgConfigDependency): + girdir = dep.get_variable("girdir") if girdir: - scan_command += ["--add-include-path=%s" % girdir] - else: - mlog.log('dependency %s not handled to build gir files' % dep) - continue - - inc_dirs = None - if kwargs.get('include_directories'): - inc_dirs = kwargs.pop('include_directories') - - if not isinstance(inc_dirs, list): - inc_dirs = [inc_dirs] + scan_command += ["--add-include-path=%s" % (girdir, )] + elif isinstance(dep, (build.StaticLibrary, build.SharedLibrary)): + for incd in dep.get_include_dirs(): + scan_command += incd.get_incdirs() + else: + mlog.log('dependency %s not handled to build gir files' % dep) + continue + + inc_dirs = kwargs.pop('include_directories', []) + if not isinstance(inc_dirs, list): + inc_dirs = [inc_dirs] + for incd in inc_dirs: + if not isinstance(incd.held_object, (str, build.IncludeDirs)): + raise MesonException( + 'Gir include dirs should be include_directories().') + scan_command += self.get_include_args(state, inc_dirs) + scan_command += self.get_include_args(state, gir_inc_dirs + inc_dirs, + prefix='--add-include-path=') - for ind in inc_dirs: - if isinstance(ind.held_object, build.IncludeDirs): - scan_command += ['--add-include-path=%s' % inc for inc in ind.held_object.get_incdirs()] - else: - raise MesonException('Gir include dirs should be include_directories()') if isinstance(girtarget, build.Executable): scan_command += ['--program', girtarget] elif isinstance(girtarget, build.SharedLibrary): @@ -257,22 +297,24 @@ class GnomeModule: typelib_output = '%s-%s.typelib' % (ns, nsversion) typelib_cmd = ['g-ir-compiler', scan_target, '--output', '@OUTPUT@'] - if inc_dirs: - for incd in inc_dirs: - typelib_cmd += ['--includedir=%s' % inc for inc in - incd.held_object.get_incdirs()] - if deps: - for dep in deps: - if isinstance(dep.held_object, dependencies.InternalDependency): - for source in dep.held_object.sources: - if isinstance(source.held_object, GirTarget): - typelib_cmd += ["--includedir=%s" % - os.path.join(state.environment.get_build_dir(), - source.held_object.get_subdir())] - elif isinstance(dep.held_object, dependencies.PkgConfigDependency): - girdir = dep.held_object.get_variable ("girdir") - if girdir: - typelib_cmd += ["--includedir=%s" % girdir] + typelib_cmd += self.get_include_args(state, gir_inc_dirs, + prefix='--includedir=') + for dep in deps: + if hasattr(dep, 'held_object'): + dep = dep.held_object + if isinstance(dep, dependencies.InternalDependency): + for source in dep.sources: + if isinstance(source.held_object, GirTarget): + typelib_cmd += [ + "--includedir=%s" % ( + os.path.join(state.environment.get_build_dir(), + source.held_object.get_subdir()), + ) + ] + elif isinstance(dep, dependencies.PkgConfigDependency): + girdir = dep.get_variable("girdir") + if girdir: + typelib_cmd += ["--includedir=%s" % (girdir, )] kwargs['output'] = typelib_output kwargs['command'] = typelib_cmd diff --git a/test cases/frameworks/12 multiple gir/gir/meson-subsample.c b/test cases/frameworks/12 multiple gir/gir/meson-subsample.c new file mode 100644 index 0000000..2d58a10 --- /dev/null +++ b/test cases/frameworks/12 multiple gir/gir/meson-subsample.c @@ -0,0 +1,124 @@ +#include "meson-subsample.h" + +struct _MesonSubSample +{ + MesonSample parent_instance; + + gchar *msg; +}; + +G_DEFINE_TYPE (MesonSubSample, meson_sub_sample, MESON_TYPE_SAMPLE) + +enum { + PROP_0, + PROP_MSG, + LAST_PROP +}; + +static GParamSpec *gParamSpecs [LAST_PROP]; + +/** + * meson_sub_sample_new: + * @msg: The message to set. + * + * Allocates a new #MesonSubSample. + * + * Returns: (transfer full): a #MesonSubSample. + */ +MesonSubSample * +meson_sub_sample_new (const gchar *msg) +{ + g_return_val_if_fail (msg != NULL, NULL); + + return g_object_new (MESON_TYPE_SUB_SAMPLE, + "message", msg, + NULL); +} + +static void +meson_sub_sample_finalize (GObject *object) +{ + MesonSubSample *self = (MesonSubSample *)object; + + g_clear_pointer (&self->msg, g_free); + + G_OBJECT_CLASS (meson_sub_sample_parent_class)->finalize (object); +} + +static void +meson_sub_sample_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MesonSubSample *self = MESON_SUB_SAMPLE (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_sub_sample_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MesonSubSample *self = MESON_SUB_SAMPLE (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_sub_sample_class_init (MesonSubSampleClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = meson_sub_sample_finalize; + object_class->get_property = meson_sub_sample_get_property; + object_class->set_property = meson_sub_sample_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_sub_sample_init (MesonSubSample *self) +{ +} + +/** + * meson_sub_sample_print_message: + * @self: a #MesonSubSample. + * + * Prints the message. + * + * Returns: Nothing. + */ +void +meson_sub_sample_print_message (MesonSubSample *self) +{ + g_return_if_fail (MESON_IS_SUB_SAMPLE (self)); + + g_print ("Message: %s\n", self->msg); +} diff --git a/test cases/frameworks/12 multiple gir/gir/meson-subsample.h b/test cases/frameworks/12 multiple gir/gir/meson-subsample.h new file mode 100644 index 0000000..9d34a08 --- /dev/null +++ b/test cases/frameworks/12 multiple gir/gir/meson-subsample.h @@ -0,0 +1,17 @@ +#ifndef MESON_SUB_SAMPLE_H +#define MESON_SUB_SAMPLE_H + +#include <glib-object.h> +#include <meson-sample.h> + +G_BEGIN_DECLS + +#define MESON_TYPE_SUB_SAMPLE (meson_sub_sample_get_type()) + +G_DECLARE_FINAL_TYPE (MesonSubSample, meson_sub_sample, MESON, SUB_SAMPLE, MesonSample) + +MesonSubSample *meson_sub_sample_new (const gchar *msg); + +G_END_DECLS + +#endif /* MESON_SUB_SAMPLE_H */ diff --git a/test cases/frameworks/12 multiple gir/gir/meson.build b/test cases/frameworks/12 multiple gir/gir/meson.build new file mode 100644 index 0000000..6001a09 --- /dev/null +++ b/test cases/frameworks/12 multiple gir/gir/meson.build @@ -0,0 +1,30 @@ +libsources = ['meson-subsample.c', 'meson-subsample.h'] + +girsubproject = shared_library( + 'girsubproject', + sources : libsources, + dependencies : [gobj, girlib_dep], + install : true +) + +girexe = executable( + 'girprog', + sources : 'prog.c', + dependencies : [gobj, girlib_dep], + link_with : girsubproject +) + +gnome.generate_gir( + girsubproject, + sources : libsources, + nsversion : '1.0', + namespace : 'MesonSub', + symbol_prefix : 'meson_sub_', + identifier_prefix : 'MesonSub', + includes : ['GObject-2.0', meson_gir], + install : true +) + +message('TEST: ' + girsubproject.outdir()) + +test('gobject introspection/subproject/c', girexe) diff --git a/test cases/frameworks/12 multiple gir/gir/prog.c b/test cases/frameworks/12 multiple gir/gir/prog.c new file mode 100644 index 0000000..f25c9d8 --- /dev/null +++ b/test cases/frameworks/12 multiple gir/gir/prog.c @@ -0,0 +1,12 @@ +#include "meson-subsample.h" + +gint +main (gint argc, + gchar *argv[]) +{ + MesonSample * i = (MesonSample*) meson_sub_sample_new ("Hello, sub/meson/c!"); + meson_sample_print_message (i); + g_object_unref (i); + + return 0; +} diff --git a/test cases/frameworks/12 multiple gir/installed_files.txt b/test cases/frameworks/12 multiple gir/installed_files.txt new file mode 100644 index 0000000..9fb51bf --- /dev/null +++ b/test cases/frameworks/12 multiple gir/installed_files.txt @@ -0,0 +1,6 @@ +usr/lib/girepository-1.0/Meson-1.0.typelib +usr/lib/girepository-1.0/MesonSub-1.0.typelib +usr/lib/libgirlib.so +usr/lib/libgirsubproject.so +usr/share/gir-1.0/Meson-1.0.gir +usr/share/gir-1.0/MesonSub-1.0.gir diff --git a/test cases/frameworks/12 multiple gir/meson.build b/test cases/frameworks/12 multiple gir/meson.build new file mode 100644 index 0000000..794abc5 --- /dev/null +++ b/test cases/frameworks/12 multiple gir/meson.build @@ -0,0 +1,7 @@ +project('multiple-gobject-introspection', 'c') + +gnome = import('gnome') +gobj = dependency('gobject-2.0') + +subdir('mesongir') +subdir('gir') diff --git a/test cases/frameworks/12 multiple gir/mesongir/meson-sample.c b/test cases/frameworks/12 multiple gir/mesongir/meson-sample.c new file mode 100644 index 0000000..2ed9cdf --- /dev/null +++ b/test cases/frameworks/12 multiple gir/mesongir/meson-sample.c @@ -0,0 +1,126 @@ +#include "meson-sample.h" + +typedef struct _MesonSamplePrivate +{ + gchar *msg; +} MesonSamplePrivate; + + +G_DEFINE_TYPE_WITH_PRIVATE (MesonSample, meson_sample, G_TYPE_OBJECT) + +enum { + PROP_0, + PROP_MSG, + LAST_PROP +}; + +static GParamSpec *gParamSpecs [LAST_PROP]; + +/** + * meson_sample_new: + * @msg: The message to set. + * + * Allocates a new #MesonSample. + * + * Returns: (transfer full): a #MesonSample. + */ +MesonSample * +meson_sample_new (const gchar *msg) +{ + g_return_val_if_fail (msg != NULL, NULL); + + return g_object_new (MESON_TYPE_SAMPLE, + "message", msg, + NULL); +} + +static void +meson_sample_finalize (GObject *object) +{ + MesonSamplePrivate *priv = meson_sample_get_instance_private ((MesonSample *) object); + + g_clear_pointer (&priv->msg, g_free); + + G_OBJECT_CLASS (meson_sample_parent_class)->finalize (object); +} + +static void +meson_sample_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MesonSamplePrivate *priv = meson_sample_get_instance_private ((MesonSample *) object); + + switch (prop_id) + { + case PROP_MSG: + g_value_set_string (value, priv->msg); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +meson_sample_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MesonSamplePrivate *priv = meson_sample_get_instance_private ((MesonSample *) object); + + switch (prop_id) + { + case PROP_MSG: + priv->msg = g_value_dup_string (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +meson_sample_class_init (MesonSampleClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = meson_sample_finalize; + object_class->get_property = meson_sample_get_property; + object_class->set_property = meson_sample_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_sample_init (MesonSample *self) +{ +} + +/** + * meson_sample_print_message: + * @self: a #MesonSample. + * + * Prints the message. + * + */ +void +meson_sample_print_message (MesonSample *self) +{ + MesonSamplePrivate *priv; + + g_return_if_fail (MESON_IS_SAMPLE (self)); + + priv = meson_sample_get_instance_private (self); + + g_print ("Message: %s\n", priv->msg); +} diff --git a/test cases/frameworks/12 multiple gir/mesongir/meson-sample.h.in b/test cases/frameworks/12 multiple gir/mesongir/meson-sample.h.in new file mode 100644 index 0000000..d0ab29e --- /dev/null +++ b/test cases/frameworks/12 multiple gir/mesongir/meson-sample.h.in @@ -0,0 +1,22 @@ +#ifndef MESON_SAMPLE_H +#define MESON_SAMPLE_H + +#include <@HEADER@> + +G_BEGIN_DECLS + +#define MESON_TYPE_SAMPLE (meson_sample_get_type()) + +G_DECLARE_DERIVABLE_TYPE (MesonSample, meson_sample, MESON, SAMPLE, GObject) + +struct _MesonSampleClass { + GObjectClass parent_class; +}; + + +MesonSample *meson_sample_new (const gchar *msg); +void meson_sample_print_message (MesonSample *self); + +G_END_DECLS + +#endif /* MESON_SAMPLE_H */ diff --git a/test cases/frameworks/12 multiple gir/mesongir/meson.build b/test cases/frameworks/12 multiple gir/mesongir/meson.build new file mode 100644 index 0000000..4775fea --- /dev/null +++ b/test cases/frameworks/12 multiple gir/mesongir/meson.build @@ -0,0 +1,37 @@ +conf = configuration_data() +conf.set('HEADER', 'glib-object.h') + +meson_sample_header = configure_file( + input : 'meson-sample.h.in', + output : 'meson-sample.h', + configuration : conf) + +libsources = ['meson-sample.c', meson_sample_header] + +girlib = shared_library( + 'girlib', + sources : libsources, + dependencies : gobj, + install : true +) + +girtarget = gnome.generate_gir( + girlib, + sources : libsources, + nsversion : '1.0', + namespace : 'Meson', + symbol_prefix : 'meson_', + identifier_prefix : 'Meson', + includes : ['GObject-2.0'], + install : true +) +meson_gir = girtarget[0] +meson_typelib = girtarget[1] + +girlib_inc = include_directories('.') +girlib_dep = declare_dependency(link_with : girlib, + include_directories : [girlib_inc], + dependencies : [gobj], + # Everything that uses libgst needs this built to compile + sources : girtarget, +) |