Skip to content

Commit

Permalink
Preventing xml node classes from forcing rebuilds when nothing changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AsherGlick committed Feb 3, 2024
1 parent 22b824c commit 8ff0e4d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
26 changes: 19 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,26 +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]]:
function = config["function"]
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

0 comments on commit 8ff0e4d

Please sign in to comment.