mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Merge branch 'fix-72' into 'main'
port: Show error when Gtk typelib is missing Closes #72 See merge request jwestman/blueprint-compiler!54
This commit is contained in:
commit
e128b49069
4 changed files with 38 additions and 28 deletions
|
@ -80,14 +80,16 @@ class CompileError(PrintableError):
|
||||||
self.hint("Are your dependencies up to date?")
|
self.hint("Are your dependencies up to date?")
|
||||||
|
|
||||||
def pretty_print(self, filename, code, stream=sys.stdout):
|
def pretty_print(self, filename, code, stream=sys.stdout):
|
||||||
line_num, col_num = utils.idx_to_pos(self.start + 1, code)
|
stream.write(f"""{self.color}{Colors.BOLD}{self.category}: {self.message}{Colors.CLEAR}\n""")
|
||||||
line = code.splitlines(True)[line_num]
|
|
||||||
|
|
||||||
# Display 1-based line numbers
|
if code is not None and self.start is not None:
|
||||||
line_num += 1
|
line_num, col_num = utils.idx_to_pos(self.start + 1, code)
|
||||||
|
line = code.splitlines(True)[line_num]
|
||||||
|
|
||||||
stream.write(f"""{self.color}{Colors.BOLD}{self.category}: {self.message}{Colors.CLEAR}
|
# Display 1-based line numbers
|
||||||
at {filename} line {line_num} column {col_num}:
|
line_num += 1
|
||||||
|
|
||||||
|
stream.write(f"""at {filename} line {line_num} column {col_num}:
|
||||||
{Colors.FAINT}{line_num :>4} |{Colors.CLEAR}{line.rstrip()}\n {Colors.FAINT}|{" "*(col_num-1)}^{Colors.CLEAR}\n""")
|
{Colors.FAINT}{line_num :>4} |{Colors.CLEAR}{line.rstrip()}\n {Colors.FAINT}|{" "*(col_num-1)}^{Colors.CLEAR}\n""")
|
||||||
|
|
||||||
for hint in self.hints:
|
for hint in self.hints:
|
||||||
|
@ -115,6 +117,15 @@ class UnexpectedTokenError(CompileError):
|
||||||
super().__init__("Unexpected tokens", start, end)
|
super().__init__("Unexpected tokens", start, end)
|
||||||
|
|
||||||
|
|
||||||
|
class GtkTypelibMissingError(CompileError):
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super().__init__(
|
||||||
|
"Could not find GTK 4 introspection files. Is gobject-introspection installed?",
|
||||||
|
fatal=True,
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class CodeAction:
|
class CodeAction:
|
||||||
title: str
|
title: str
|
||||||
|
|
|
@ -25,7 +25,7 @@ import gi # type: ignore
|
||||||
gi.require_version("GIRepository", "2.0")
|
gi.require_version("GIRepository", "2.0")
|
||||||
from gi.repository import GIRepository # type: ignore
|
from gi.repository import GIRepository # type: ignore
|
||||||
|
|
||||||
from .errors import CompileError, CompilerBugError
|
from .errors import CompileError, CompilerBugError, GtkTypelibMissingError
|
||||||
from . import typelib, xml_reader
|
from . import typelib, xml_reader
|
||||||
|
|
||||||
_namespace_cache = {}
|
_namespace_cache = {}
|
||||||
|
@ -49,10 +49,15 @@ def get_namespace(namespace, version):
|
||||||
break
|
break
|
||||||
|
|
||||||
if filename not in _namespace_cache:
|
if filename not in _namespace_cache:
|
||||||
raise CompileError(
|
hints = ["search path: " + os.pathsep.join(search_paths)]
|
||||||
f"Namespace {namespace}-{version} could not be found",
|
|
||||||
hints=["search path: " + os.pathsep.join(search_paths)],
|
if namespace == "Gtk":
|
||||||
)
|
raise GtkTypelibMissingError(hints=hints)
|
||||||
|
else:
|
||||||
|
raise CompileError(
|
||||||
|
f"Namespace {namespace}-{version} could not be found",
|
||||||
|
hints=hints,
|
||||||
|
)
|
||||||
|
|
||||||
return _namespace_cache[filename]
|
return _namespace_cache[filename]
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ import difflib
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from . import decompiler, tokenizer, parser
|
from . import decompiler, tokenizer, parser
|
||||||
from .errors import MultipleErrors, PrintableError
|
from .errors import MultipleErrors, PrintableError, GtkTypelibMissingError
|
||||||
from .utils import Colors
|
from .utils import Colors
|
||||||
|
|
||||||
|
|
||||||
|
@ -156,11 +156,15 @@ def step2():
|
||||||
def step3():
|
def step3():
|
||||||
print(f"{Colors.BOLD}STEP 3: Convert UI files{Colors.CLEAR}")
|
print(f"{Colors.BOLD}STEP 3: Convert UI files{Colors.CLEAR}")
|
||||||
|
|
||||||
files = [
|
try:
|
||||||
(file, change_suffix(file), decompile_file(file, change_suffix(file)))
|
files = [
|
||||||
for file in listdir_recursive(".")
|
(file, change_suffix(file), decompile_file(file, change_suffix(file)))
|
||||||
if file.endswith(".ui")
|
for file in listdir_recursive(".")
|
||||||
]
|
if file.endswith(".ui")
|
||||||
|
]
|
||||||
|
except GtkTypelibMissingError as e:
|
||||||
|
e.pretty_print(None, None)
|
||||||
|
return ([], [])
|
||||||
|
|
||||||
success = 0
|
success = 0
|
||||||
for in_file, out_file, result in files:
|
for in_file, out_file, result in files:
|
||||||
|
|
|
@ -40,17 +40,7 @@ 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", version)
|
||||||
gir.get_namespace("Gtk", version)
|
|
||||||
except CompileError as e:
|
|
||||||
raise CompileError(
|
|
||||||
"Could not find GTK 4 introspection files. Is gobject-introspection installed?",
|
|
||||||
fatal=True,
|
|
||||||
# preserve the hints from the original error, because it contains
|
|
||||||
# useful debugging information
|
|
||||||
hints=e.hints,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def gir_namespace(self):
|
def gir_namespace(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue