Generate a single unity build file. Args: chunk_index: Index of this chunk (for naming) sources: List of source files to include in this unity file output_path: Path to write the unity file
(
chunk_index: int,
sources: list[Path],
output_path: Path,
)
| 91 | |
| 92 | |
| 93 | def generate_unity_file( |
| 94 | chunk_index: int, |
| 95 | sources: list[Path], |
| 96 | output_path: Path, |
| 97 | ) -> None: |
| 98 | """ |
| 99 | Generate a single unity build file. |
| 100 | |
| 101 | Args: |
| 102 | chunk_index: Index of this chunk (for naming) |
| 103 | sources: List of source files to include in this unity file |
| 104 | output_path: Path to write the unity file |
| 105 | """ |
| 106 | lines: list[str] = [] |
| 107 | lines.append(f"// Unity build file {chunk_index}") |
| 108 | lines.append("// Generated by ci/wasm_unity_generator.py") |
| 109 | lines.append( |
| 110 | f"// Combines {len(sources)} source files into single compilation unit" |
| 111 | ) |
| 112 | lines.append("") |
| 113 | |
| 114 | for source in sources: |
| 115 | # Use absolute paths (Emscripten em++ handles them correctly) |
| 116 | # Use angle brackets like Meson does |
| 117 | lines.append(f"#include<{source.as_posix()}>") |
| 118 | |
| 119 | lines.append("") |
| 120 | |
| 121 | content = "\n".join(lines) |
| 122 | |
| 123 | # Only write if content changed (preserve timestamps for incremental builds) |
| 124 | if output_path.exists(): |
| 125 | existing_content = output_path.read_text(encoding="utf-8") |
| 126 | if existing_content == content: |
| 127 | return # No change, skip write |
| 128 | |
| 129 | output_path.write_text(content, encoding="utf-8") |
| 130 | |
| 131 | |
| 132 | def compute_unity_metadata_hash(num_chunks: int, sources: list[Path]) -> str: |
no test coverage detected