Detect when gobject-introspection is missing

Instead of a compiler bug error, show a proper error message that asks
whether gobject-introspection is installed.

Fixes #58.
This commit is contained in:
James Westman 2022-05-27 11:17:48 -05:00
parent f6355fe412
commit 42aa91d4d9
3 changed files with 9 additions and 1 deletions

View file

@ -81,6 +81,8 @@ class AstNode:
validator(self) validator(self)
except CompileError as e: except CompileError as e:
yield e yield e
if e.fatal:
return
for child in self.children: for child in self.children:
yield from child._get_errors() yield from child._get_errors()

View file

@ -37,7 +37,7 @@ class CompileError(PrintableError):
category = "error" category = "error"
color = Colors.RED color = Colors.RED
def __init__(self, message, start=None, end=None, did_you_mean=None, hints=None, actions=None): def __init__(self, message, start=None, end=None, did_you_mean=None, hints=None, actions=None, fatal=False):
super().__init__(message) super().__init__(message)
self.message = message self.message = message
@ -45,6 +45,7 @@ class CompileError(PrintableError):
self.end = end self.end = end
self.hints = hints or [] self.hints = hints or []
self.actions = actions or [] self.actions = actions or []
self.fatal = fatal
if did_you_mean is not None: if did_you_mean is not None:
self._did_you_mean(*did_you_mean) self._did_you_mean(*did_you_mean)

View file

@ -39,6 +39,11 @@ class GtkDirective(AstNode):
err.hint("Expected 'using Gtk 4.0;'") err.hint("Expected 'using Gtk 4.0;'")
raise err raise err
try:
gir.get_namespace("Gtk", self.tokens["version"])
except:
raise CompileError("Could not find GTK 4 introspection files. Is gobject-introspection installed?", fatal=True)
@property @property
def gir_namespace(self): def gir_namespace(self):