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

Preventing xml node classes from forcing rebuilds when nothing changes #274

Merged
merged 2 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions xml_converter/generators/generate_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,11 @@ def sorted_cpp_forward_declarations(self) -> List[str]:
def write_cpp_classes(
output_directory: str,
data: Dict[str, Document],
) -> None:
) -> List[str]:
print("Writing XML Node Cpp Classes")

written_files: List[str] = []

file_loader = FileSystemLoader('cpp_templates')
env = Environment(
loader=file_loader,
Expand Down Expand Up @@ -175,25 +178,35 @@ def write_cpp_classes(
if attribute_variable.class_name == "marker_category":
attributes_of_type_marker_category.append(attribute_variable.attribute_name)

with open(os.path.join(output_directory, lowercase(cpp_class) + "_gen.hpp"), 'w') as f:
f.write(header_template.render(
hpp_filepath = os.path.join(output_directory, lowercase(cpp_class) + "_gen.hpp")
write_if_different(
path=hpp_filepath,
contents=header_template.render(
cpp_class=cpp_class,
attribute_variables=sorted(attribute_variables, key=get_attribute_variable_key),
cpp_includes=cpp_includes,
cpp_class_header=lowercase(cpp_class),
attributes_of_type_marker_category=attributes_of_type_marker_category,
))
),
)
written_files.append(hpp_filepath)

with open(os.path.join(output_directory, lowercase(cpp_class) + "_gen.cpp"), 'w') as f:
f.write(code_template.render(
cpp_filepath = os.path.join(output_directory, lowercase(cpp_class) + "_gen.cpp")
write_if_different(
path=cpp_filepath,
contents=code_template.render(
cpp_class=cpp_class,
cpp_includes=cpp_includes,
cpp_class_header=lowercase(cpp_class),
xml_class_name=cpp_classes[cpp_class],
attribute_variables=sorted(attribute_variables, key=get_attribute_variable_key),
enumerate=enumerate,
attributes_of_type_marker_category=attributes_of_type_marker_category,
))
),
)
written_files.append(cpp_filepath)

return written_files


def build_custom_function_data(config: Dict[str, Any]) -> Tuple[str, List[str]]:
Expand Down
5 changes: 3 additions & 2 deletions xml_converter/generators/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,10 @@ def main() -> None:
generator.load_input_doc(full_markdown_doc_directory)

generator.delete_generated_docs("../web_docs")
generator.delete_generated_docs("../src/")
generator.write_webdocs("../web_docs/")
write_cpp_classes("../src/", generator.data)

written_classes = write_cpp_classes("../src/", generator.data)
generator.delete_generated_docs("../src/", skip=written_classes)

written_attributes = write_attribute("../src/attribute", generator.data)
generator.delete_generated_docs("../src/attribute", skip=written_attributes)
Expand Down
Loading