diff --git a/blueprintcompiler/gir.py b/blueprintcompiler/gir.py index f03a37f..d795789 100644 --- a/blueprintcompiler/gir.py +++ b/blueprintcompiler/gir.py @@ -32,9 +32,15 @@ from . import typelib, xml_reader _namespace_cache: T.Dict[str, "Namespace"] = {} _xml_cache = {} +_user_search_paths = [] + + +def add_typelib_search_path(path: str): + _user_search_paths.append(path) + def get_namespace(namespace: str, version: str) -> "Namespace": - search_paths = GIRepository.Repository.get_search_path() + search_paths = [*GIRepository.Repository.get_search_path(), *_user_search_paths] filename = f"{namespace}-{version}.typelib" diff --git a/blueprintcompiler/main.py b/blueprintcompiler/main.py index 6127630..6ac7a11 100644 --- a/blueprintcompiler/main.py +++ b/blueprintcompiler/main.py @@ -22,6 +22,7 @@ import typing as T import argparse, json, os, sys from .errors import PrintableError, report_bug, MultipleErrors, CompilerBugError +from .gir import add_typelib_search_path from .lsp import LanguageServer from . import parser, tokenizer, decompiler, interactive_port from .utils import Colors @@ -41,6 +42,7 @@ class BlueprintApp: "compile", "Compile blueprint files", self.cmd_compile ) compile.add_argument("--output", dest="output", default="-") + compile.add_argument("--typelib-path", nargs="?", action="append") compile.add_argument( "input", metavar="filename", default=sys.stdin, type=argparse.FileType("r") ) @@ -52,6 +54,7 @@ class BlueprintApp: ) batch_compile.add_argument("output_dir", metavar="output-dir") batch_compile.add_argument("input_dir", metavar="input-dir") + batch_compile.add_argument("--typelib-path", nargs="?", action="append") batch_compile.add_argument( "inputs", nargs="+", @@ -91,6 +94,10 @@ class BlueprintApp: self.parser.print_help() def cmd_compile(self, opts): + if opts.typelib_path != None: + for typelib_path in opts.typelib_path: + add_typelib_search_path(typelib_path) + data = opts.input.read() try: xml, warnings = self._compile(data) @@ -108,6 +115,10 @@ class BlueprintApp: sys.exit(1) def cmd_batch_compile(self, opts): + if opts.typelib_path != None: + for typelib_path in opts.typelib_path: + add_typelib_search_path(typelib_path) + for file in opts.inputs: data = file.read()