Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binary exporter support for structs. #420

Closed
wants to merge 10 commits into from
18 changes: 15 additions & 3 deletions src/vss_tools/exporters/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def export_node(node: VSSNode, f: BinaryIO):
@clo.overlays_opt
@clo.quantities_opt
@clo.units_opt
@clo.types_opt
@clo.types_output_opt
def cli(
vspec: Path,
output: Path,
Expand All @@ -121,22 +123,32 @@ def cli(
overlays: tuple[Path],
quantities: tuple[Path],
units: tuple[Path],
types: tuple[Path],
types_output: Path | None,
):
"""
Export to Binary.
"""

tree, _ = get_trees(
tree, datatype_tree = get_trees(
vspec=vspec,
include_dirs=include_dirs,
aborts=aborts,
strict=strict,
extended_attributes=extended_attributes,
quantities=quantities,
units=units,
types=types,
overlays=overlays,
)

log.info("Generating binary output...")
if datatype_tree:
if types_output:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if types_output is not defined?
Usually other exporters export the types then bundled into the main file.
I think either it needs to throw an error in that case for the user or defining a default types output file or ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test shows that if --types-output is not used in the make command the second if statement becomes false.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does not really answer my question because if datatype_tree is still true then but we are not doing anything with that info in that case

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ulf - I suggest you add an else statement, something like

else:
  log.warning("To generate datatype tree output you must specify wanted output file")

or

else:
  log.warning("Ignoring type tree generation as no file name specified")

... that gives a hint that they maybe have forgotten to specify output file.

with open(str(types_output), "wb") as f:
export_node(datatype_tree, f)
log.info("Binary datatype tree output generated in %s", types_output)
else:
log.warning("Ignoring type tree generation as no file name specified")
with open(str(output), "wb") as f:
export_node(tree, f)
log.info("Binary output generated in %s", output)
log.info("Binary main tree output generated in %s", output)
Loading