Check if any PCH dependencies are newer than the PCH output. Args: depfile: Path to .d dependency file pch_output: Path to PCH output file Returns: (changed, reason) tuple
(depfile: Path, pch_output: Path)
| 203 | |
| 204 | |
| 205 | def check_dependencies_changed(depfile: Path, pch_output: Path) -> tuple[bool, str]: |
| 206 | """ |
| 207 | Check if any PCH dependencies are newer than the PCH output. |
| 208 | |
| 209 | Args: |
| 210 | depfile: Path to .d dependency file |
| 211 | pch_output: Path to PCH output file |
| 212 | |
| 213 | Returns: |
| 214 | (changed, reason) tuple |
| 215 | """ |
| 216 | if not depfile.exists(): |
| 217 | return False, "" # No depfile, can't check dependencies |
| 218 | |
| 219 | if not pch_output.exists(): |
| 220 | return True, "PCH output does not exist" |
| 221 | |
| 222 | # Get PCH output modification time |
| 223 | pch_mtime = pch_output.stat().st_mtime |
| 224 | depfile_mtime = depfile.stat().st_mtime |
| 225 | |
| 226 | # If depfile is older than PCH, it's stale - ignore it |
| 227 | # (This can happen after PCH is rebuilt but before depfile is regenerated) |
| 228 | if depfile_mtime < pch_mtime: |
| 229 | return False, "" # Stale depfile, rely on other checks |
| 230 | |
| 231 | # Parse dependencies |
| 232 | deps = parse_dependency_file(depfile) |
| 233 | if not deps: |
| 234 | return False, "" # Empty or unparseable depfile |
| 235 | |
| 236 | # Check each dependency |
| 237 | for dep in deps: |
| 238 | if not dep.exists(): |
| 239 | # Dependency was deleted - rebuild needed |
| 240 | # Note: This is expected during initial builds or after clean |
| 241 | return True, f"dependency missing: {dep.name}" |
| 242 | |
| 243 | dep_mtime = dep.stat().st_mtime |
| 244 | if dep_mtime > pch_mtime: |
| 245 | # Dependency is newer than PCH - rebuild needed |
| 246 | return True, f"dependency changed: {dep.name}" |
| 247 | |
| 248 | return False, "" |
| 249 | |
| 250 | |
| 251 | def needs_rebuild( |
no test coverage detected