diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2023-08-27 11:02:09 -0400 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2023-08-29 13:34:23 -0400 |
commit | 494bdbd3345d1c2d20cf2520249962bd32fc61e6 (patch) | |
tree | 9c543fe1c84c8d2b58f97f39f847ed8c53a9be63 | |
parent | 4eb9c84cf97427a11af7ec928c849e4289862202 (diff) | |
download | meson-494bdbd3345d1c2d20cf2520249962bd32fc61e6.zip meson-494bdbd3345d1c2d20cf2520249962bd32fc61e6.tar.gz meson-494bdbd3345d1c2d20cf2520249962bd32fc61e6.tar.bz2 |
gnome: Fix crash in gtkdoc and generate_gir in C++ projects
gtkdoc() and generate_gir() methods assumes there is a C compiler, but
pure C++ projects might not add it explicitly.
Fixes: #12162
-rw-r--r-- | mesonbuild/modules/__init__.py | 2 | ||||
-rw-r--r-- | mesonbuild/modules/gnome.py | 6 | ||||
-rw-r--r-- | test cases/frameworks/36 gtkdoc cpp/foo-docs.xml | 16 | ||||
-rw-r--r-- | test cases/frameworks/36 gtkdoc cpp/foo.cpp | 5 | ||||
-rw-r--r-- | test cases/frameworks/36 gtkdoc cpp/foo.h | 1 | ||||
-rw-r--r-- | test cases/frameworks/36 gtkdoc cpp/meson.build | 13 | ||||
-rw-r--r-- | test cases/frameworks/36 gtkdoc cpp/test.json | 17 | ||||
-rw-r--r-- | test cases/frameworks/37 gir cpp/foo.cpp | 5 | ||||
-rw-r--r-- | test cases/frameworks/37 gir cpp/foo.h | 1 | ||||
-rw-r--r-- | test cases/frameworks/37 gir cpp/meson.build | 16 | ||||
-rw-r--r-- | test cases/frameworks/37 gir cpp/test.json | 3 |
11 files changed, 85 insertions, 0 deletions
diff --git a/mesonbuild/modules/__init__.py b/mesonbuild/modules/__init__.py index 57c169d..eef67a1 100644 --- a/mesonbuild/modules/__init__.py +++ b/mesonbuild/modules/__init__.py @@ -167,6 +167,8 @@ class ModuleState: else: yield self._interpreter.build_incdir_object([d]) + def add_language(self, lang: str, for_machine: MachineChoice) -> None: + self._interpreter.add_languages([lang], True, for_machine) class ModuleObject(HoldableObject): """Base class for all objects returned by modules diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index 6bd0436..039e122 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -1113,6 +1113,9 @@ class GnomeModule(ExtensionModule): ) def generate_gir(self, state: 'ModuleState', args: T.Tuple[T.List[T.Union[Executable, build.SharedLibrary, build.StaticLibrary]]], kwargs: 'GenerateGir') -> ModuleReturnValue: + # 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]] 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') @@ -1430,6 +1433,9 @@ class GnomeModule(ExtensionModule): namespace = kwargs['namespace'] + # Ensure we have a C compiler even in C++ projects. + state.add_language('c', MachineChoice.HOST) + def abs_filenames(files: T.Iterable['FileOrString']) -> T.Iterator[str]: for f in files: if isinstance(f, mesonlib.File): diff --git a/test cases/frameworks/36 gtkdoc cpp/foo-docs.xml b/test cases/frameworks/36 gtkdoc cpp/foo-docs.xml new file mode 100644 index 0000000..85c673c --- /dev/null +++ b/test cases/frameworks/36 gtkdoc cpp/foo-docs.xml @@ -0,0 +1,16 @@ +<?xml version="1.0"?> +<!DOCTYPE book PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'"> +<!ENTITY version SYSTEM "version.xml"> +]> +<book id="index" xmlns:xi="http://www.w3.org/2003/XInclude"> + <bookinfo> + <title>Foo Reference Manual</title> + </bookinfo> + + <chapter id="foo"> + <title>GLib Core Application Support</title> + <xi:include href="xml/foo.xml" /> + </chapter> +</book> diff --git a/test cases/frameworks/36 gtkdoc cpp/foo.cpp b/test cases/frameworks/36 gtkdoc cpp/foo.cpp new file mode 100644 index 0000000..15fa269 --- /dev/null +++ b/test cases/frameworks/36 gtkdoc cpp/foo.cpp @@ -0,0 +1,5 @@ +#include "foo.h" + +int foo_do_something(void) { + return 42; +} diff --git a/test cases/frameworks/36 gtkdoc cpp/foo.h b/test cases/frameworks/36 gtkdoc cpp/foo.h new file mode 100644 index 0000000..cac03d3 --- /dev/null +++ b/test cases/frameworks/36 gtkdoc cpp/foo.h @@ -0,0 +1 @@ +int foo_do_something(void); diff --git a/test cases/frameworks/36 gtkdoc cpp/meson.build b/test cases/frameworks/36 gtkdoc cpp/meson.build new file mode 100644 index 0000000..747eae5 --- /dev/null +++ b/test cases/frameworks/36 gtkdoc cpp/meson.build @@ -0,0 +1,13 @@ +project('gnome module without C', 'cpp') + +gtkdoc = find_program('gtkdoc-scan', required: false) +if not gtkdoc.found() + error('MESON_SKIP_TEST gtkdoc not found.') +endif + +gnome = import('gnome') + +lib = library('foo++', 'foo.cpp') +gnome.gtkdoc('foo', + src_dir: '.', + main_xml : 'foo-docs.xml',) diff --git a/test cases/frameworks/36 gtkdoc cpp/test.json b/test cases/frameworks/36 gtkdoc cpp/test.json new file mode 100644 index 0000000..b2d9bc8 --- /dev/null +++ b/test cases/frameworks/36 gtkdoc cpp/test.json @@ -0,0 +1,17 @@ +{ + "installed": [ + {"type": "file", "file": "usr/share/gtk-doc/html/foo/up-insensitive.png"}, + {"type": "file", "file": "usr/share/gtk-doc/html/foo/home.png"}, + {"type": "file", "file": "usr/share/gtk-doc/html/foo/foo.html"}, + {"type": "file", "file": "usr/share/gtk-doc/html/foo/foo-foo.html"}, + {"type": "file", "file": "usr/share/gtk-doc/html/foo/style.css"}, + {"type": "file", "file": "usr/share/gtk-doc/html/foo/index.html"}, + {"type": "file", "file": "usr/share/gtk-doc/html/foo/foo.devhelp2"}, + {"type": "file", "file": "usr/share/gtk-doc/html/foo/left.png"}, + {"type": "file", "file": "usr/share/gtk-doc/html/foo/left-insensitive.png"}, + {"type": "file", "file": "usr/share/gtk-doc/html/foo/right-insensitive.png"}, + {"type": "file", "file": "usr/share/gtk-doc/html/foo/up.png"}, + {"type": "file", "file": "usr/share/gtk-doc/html/foo/right.png"} + ], + "skip_on_jobname": ["azure", "msys2"] +} diff --git a/test cases/frameworks/37 gir cpp/foo.cpp b/test cases/frameworks/37 gir cpp/foo.cpp new file mode 100644 index 0000000..15fa269 --- /dev/null +++ b/test cases/frameworks/37 gir cpp/foo.cpp @@ -0,0 +1,5 @@ +#include "foo.h" + +int foo_do_something(void) { + return 42; +} diff --git a/test cases/frameworks/37 gir cpp/foo.h b/test cases/frameworks/37 gir cpp/foo.h new file mode 100644 index 0000000..cac03d3 --- /dev/null +++ b/test cases/frameworks/37 gir cpp/foo.h @@ -0,0 +1 @@ +int foo_do_something(void); diff --git a/test cases/frameworks/37 gir cpp/meson.build b/test cases/frameworks/37 gir cpp/meson.build new file mode 100644 index 0000000..c8bf428 --- /dev/null +++ b/test cases/frameworks/37 gir cpp/meson.build @@ -0,0 +1,16 @@ +project('gnome module without C', 'cpp') + +gi = dependency('gobject-introspection-1.0', required: false) +if not gi.found() + error('MESON_SKIP_TEST gobject-introspection not found.') +endif + +gnome = import('gnome') + +lib = library('foo++', 'foo.cpp') +gnome.generate_gir( + lib, + sources: ['foo.cpp', 'foo.h'], + namespace: 'foo', + nsversion: meson.project_version(), +) diff --git a/test cases/frameworks/37 gir cpp/test.json b/test cases/frameworks/37 gir cpp/test.json new file mode 100644 index 0000000..a9d74fb --- /dev/null +++ b/test cases/frameworks/37 gir cpp/test.json @@ -0,0 +1,3 @@ +{ + "skip_on_jobname": ["azure", "macos", "msys2"] +} |