Determine if PCH needs to be rebuilt. Returns: (needs_rebuild, reason) tuple
(
emcc: str,
flags: dict[str, list[str]],
force: bool = False,
)
| 249 | |
| 250 | |
| 251 | def needs_rebuild( |
| 252 | emcc: str, |
| 253 | flags: dict[str, list[str]], |
| 254 | force: bool = False, |
| 255 | ) -> tuple[bool, str]: |
| 256 | """ |
| 257 | Determine if PCH needs to be rebuilt. |
| 258 | |
| 259 | Returns: |
| 260 | (needs_rebuild, reason) tuple |
| 261 | """ |
| 262 | if force: |
| 263 | return True, "forced rebuild (--force flag)" |
| 264 | |
| 265 | if not PCH_OUTPUT.exists(): |
| 266 | return True, "PCH output file does not exist" |
| 267 | |
| 268 | # Load metadata from previous build |
| 269 | metadata = load_metadata() |
| 270 | if not metadata: |
| 271 | return True, "no previous build metadata found" |
| 272 | |
| 273 | # Check header content hash |
| 274 | current_header_hash = compute_content_hash(PCH_HEADER) |
| 275 | if metadata.get("header_hash") != current_header_hash: |
| 276 | return True, "PCH header content changed" |
| 277 | |
| 278 | # Check flags hash |
| 279 | current_flags_hash = compute_flags_hash(flags) |
| 280 | if metadata.get("flags_hash") != current_flags_hash: |
| 281 | return True, "compilation flags changed" |
| 282 | |
| 283 | # Check compiler version |
| 284 | current_compiler_version = get_compiler_version(emcc) |
| 285 | if metadata.get("compiler_version") != current_compiler_version: |
| 286 | return True, "compiler version changed" |
| 287 | |
| 288 | # Check if any dependencies have changed (NEW: dependency tracking) |
| 289 | deps_changed, reason = check_dependencies_changed(PCH_DEPFILE, PCH_OUTPUT) |
| 290 | if deps_changed: |
| 291 | return True, reason |
| 292 | |
| 293 | return False, "PCH is up to date" |
| 294 | |
| 295 | |
| 296 | def compile_pch( |
no test coverage detected