typelib: Use GIRepository to find typelib path

This commit is contained in:
James Westman 2022-06-28 23:43:01 -05:00
parent cfae48a65a
commit 68610a7dba
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
2 changed files with 7 additions and 32 deletions

View file

@ -21,6 +21,10 @@ from functools import cached_property
import typing as T import typing as T
import os, sys import os, sys
import gi # type: ignore
gi.require_version("GIRepository", "2.0")
from gi.repository import GIRepository # type: ignore
from .errors import CompileError, CompilerBugError from .errors import CompileError, CompilerBugError
from . import typelib, xml_reader from . import typelib, xml_reader
@ -29,25 +33,7 @@ _xml_cache = {}
def get_namespace(namespace, version): def get_namespace(namespace, version):
from .main import LIBDIR, VERSION search_paths = GIRepository.Repository.get_search_path()
search_paths = []
if LIBDIR is not None:
search_paths.append(os.path.join(LIBDIR, "girepository-1.0"))
# This is a fragile hack to make blueprint-compiler work uninstalled on
# most systems.
if VERSION == "uninstalled":
search_paths += [
"/usr/lib/girepository-1.0",
"/usr/local/lib/girepository-1.0",
"/app/lib/girepository-1.0",
"/usr/lib64/girepository-1.0",
"/usr/local/lib64/girepository-1.0",
"/app/lib64/girepository-1.0",
]
if typelib_path := os.environ.get("GI_TYPELIB_PATH"):
search_paths.append(typelib_path)
filename = f"{namespace}-{version}.typelib" filename = f"{namespace}-{version}.typelib"
@ -76,14 +62,6 @@ def get_xml(namespace, version):
from xml.etree import ElementTree from xml.etree import ElementTree
search_paths = [] search_paths = []
# Same fragile hack as before
if VERSION == "uninstalled":
search_paths += [
"/usr/share/gir-1.0",
"/usr/local/share/gir-1.0",
"/app/share/gir-1.0",
]
if data_paths := os.environ.get("XDG_DATA_DIRS"): if data_paths := os.environ.get("XDG_DATA_DIRS"):
search_paths += [os.path.join(path, "gir-1.0") for path in data_paths.split(os.pathsep)] search_paths += [os.path.join(path, "gir-1.0") for path in data_paths.split(os.pathsep)]

View file

@ -21,17 +21,14 @@ Blueprint files can import GObject Introspection namespaces like this:
To compile a blueprint file, ``.typelib`` files for all of the imported To compile a blueprint file, ``.typelib`` files for all of the imported
namespaces must be installed. All blueprint files must import Gtk 4.0, so namespaces must be installed. All blueprint files must import Gtk 4.0, so
``Gtk-4.0.typelib`` is effectively a runtime dependency of blueprint-compiler. ``Gtk-4.0.typelib`` is effectively a runtime dependency of blueprint-compiler.
blueprint-compiler also depends on pygobject, because it uses GIRepository
to determine the search path for typelib files.
So, if a package uses blueprint-compiler, its build dependencies should include So, if a package uses blueprint-compiler, its build dependencies should include
the typelib files for any namespaces imported in its blueprint files. (Note the typelib files for any namespaces imported in its blueprint files. (Note
that many apps also have the same typelib files as runtime dependencies, that many apps also have the same typelib files as runtime dependencies,
separately from blueprint). separately from blueprint).
The search path for typelib files is defined by the
`libdir <https://mesonbuild.com/Builtin-options.html#directories>`_ that Meson
uses. Additional paths may be passed at runtime through the ``GI_TYPELIB_PATH``
environment variable.
In addition, the blueprint language server uses ``.gir`` files to provide In addition, the blueprint language server uses ``.gir`` files to provide
documentation on hover. Some distros package these files separately from the documentation on hover. Some distros package these files separately from the
main package (e.g. in a ``-devel`` package). The language server will not crash main package (e.g. in a ``-devel`` package). The language server will not crash