mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Add --typelib-path command line argument
Allows adding directories to search for typelib files.
This commit is contained in:
parent
90001bd885
commit
8c3c43a34a
2 changed files with 18 additions and 1 deletions
|
@ -32,9 +32,15 @@ from . import typelib, xml_reader
|
||||||
_namespace_cache: T.Dict[str, "Namespace"] = {}
|
_namespace_cache: T.Dict[str, "Namespace"] = {}
|
||||||
_xml_cache = {}
|
_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":
|
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"
|
filename = f"{namespace}-{version}.typelib"
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ import typing as T
|
||||||
import argparse, json, os, sys
|
import argparse, json, os, sys
|
||||||
|
|
||||||
from .errors import PrintableError, report_bug, MultipleErrors, CompilerBugError
|
from .errors import PrintableError, report_bug, MultipleErrors, CompilerBugError
|
||||||
|
from .gir import add_typelib_search_path
|
||||||
from .lsp import LanguageServer
|
from .lsp import LanguageServer
|
||||||
from . import parser, tokenizer, decompiler, interactive_port
|
from . import parser, tokenizer, decompiler, interactive_port
|
||||||
from .utils import Colors
|
from .utils import Colors
|
||||||
|
@ -41,6 +42,7 @@ class BlueprintApp:
|
||||||
"compile", "Compile blueprint files", self.cmd_compile
|
"compile", "Compile blueprint files", self.cmd_compile
|
||||||
)
|
)
|
||||||
compile.add_argument("--output", dest="output", default="-")
|
compile.add_argument("--output", dest="output", default="-")
|
||||||
|
compile.add_argument("--typelib-path", nargs="?", action="append")
|
||||||
compile.add_argument(
|
compile.add_argument(
|
||||||
"input", metavar="filename", default=sys.stdin, type=argparse.FileType("r")
|
"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("output_dir", metavar="output-dir")
|
||||||
batch_compile.add_argument("input_dir", metavar="input-dir")
|
batch_compile.add_argument("input_dir", metavar="input-dir")
|
||||||
|
batch_compile.add_argument("--typelib-path", nargs="?", action="append")
|
||||||
batch_compile.add_argument(
|
batch_compile.add_argument(
|
||||||
"inputs",
|
"inputs",
|
||||||
nargs="+",
|
nargs="+",
|
||||||
|
@ -91,6 +94,10 @@ class BlueprintApp:
|
||||||
self.parser.print_help()
|
self.parser.print_help()
|
||||||
|
|
||||||
def cmd_compile(self, opts):
|
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()
|
data = opts.input.read()
|
||||||
try:
|
try:
|
||||||
xml, warnings = self._compile(data)
|
xml, warnings = self._compile(data)
|
||||||
|
@ -108,6 +115,10 @@ class BlueprintApp:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def cmd_batch_compile(self, opts):
|
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:
|
for file in opts.inputs:
|
||||||
data = file.read()
|
data = file.read()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue