Add --typelib-path command line argument

Allows adding directories to search for typelib files.
This commit is contained in:
James Westman 2023-03-16 15:10:04 -05:00
parent 90001bd885
commit 8c3c43a34a
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
2 changed files with 18 additions and 1 deletions

View file

@ -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"

View file

@ -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()