mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Add input directory argument to batch-compile
This allows it to maintain the directory structure of the input files.
This commit is contained in:
parent
0e33ce190d
commit
5c0fd46ebe
2 changed files with 15 additions and 3 deletions
|
@ -35,7 +35,7 @@ gtk-blueprint-tool works as a meson subproject.
|
||||||
# LIST YOUR BLUEPRINT FILES HERE
|
# LIST YOUR BLUEPRINT FILES HERE
|
||||||
),
|
),
|
||||||
output: '.',
|
output: '.',
|
||||||
command: [find_program('gtk-blueprint-tool'), 'batch-compile', '@OUTPUT@', '@INPUT@'],
|
command: [find_program('gtk-blueprint-tool'), 'batch-compile', '@OUTPUT@', '@CURRENT_SOURCE_DIR@', '@INPUT@'],
|
||||||
)
|
)
|
||||||
|
|
||||||
#. In the same ``meson.build`` file, add this argument to your ``gnome.compile_resources`` command:
|
#. In the same ``meson.build`` file, add this argument to your ``gnome.compile_resources`` command:
|
||||||
|
|
|
@ -41,6 +41,7 @@ class BlueprintApp:
|
||||||
|
|
||||||
batch_compile = self.add_subcommand("batch-compile", "Compile many blueprint files at once", self.cmd_batch_compile)
|
batch_compile = self.add_subcommand("batch-compile", "Compile many blueprint files at once", self.cmd_batch_compile)
|
||||||
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("inputs", nargs="+", metavar="filenames", default=sys.stdin, type=argparse.FileType('r'))
|
batch_compile.add_argument("inputs", nargs="+", metavar="filenames", default=sys.stdin, type=argparse.FileType('r'))
|
||||||
|
|
||||||
lsp = self.add_subcommand("lsp", "Run the language server (for internal use by IDEs)", self.cmd_lsp)
|
lsp = self.add_subcommand("lsp", "Run the language server (for internal use by IDEs)", self.cmd_lsp)
|
||||||
|
@ -87,10 +88,21 @@ class BlueprintApp:
|
||||||
data = file.read()
|
data = file.read()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if not os.path.commonpath([file.name, opts.input_dir]):
|
||||||
|
print(f"{Colors.RED}{Colors.BOLD}error: input file '{file.name}' is not in input directory '{opts.input_dir}'{Colors.CLEAR}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
xml = self._compile(data)
|
xml = self._compile(data)
|
||||||
|
|
||||||
name = os.path.splitext(os.path.basename(file.name))[0] + ".ui"
|
path = os.path.join(
|
||||||
with open(os.path.join(opts.output_dir, name), "w") as file:
|
opts.output_dir,
|
||||||
|
os.path.relpath(
|
||||||
|
os.path.splitext(file.name)[0] + ".ui",
|
||||||
|
opts.input_dir
|
||||||
|
)
|
||||||
|
)
|
||||||
|
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||||
|
with open(path, "w") as file:
|
||||||
file.write(xml)
|
file.write(xml)
|
||||||
except PrintableError as e:
|
except PrintableError as e:
|
||||||
e.pretty_print(file.name, data)
|
e.pretty_print(file.name, data)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue