Return True when ``examples/`` files have been added/removed/modified.
(source_dir: Path, build_dir: Path)
| 506 | |
| 507 | |
| 508 | def detect_example_file_changes(source_dir: Path, build_dir: Path) -> bool: |
| 509 | """Return True when ``examples/`` files have been added/removed/modified.""" |
| 510 | try: |
| 511 | from ci.meson.example_metadata_cache import compute_example_files_hash |
| 512 | |
| 513 | examples_dir = source_dir / "examples" |
| 514 | example_cache_file = build_dir / "examples" / "example_metadata.cache" |
| 515 | |
| 516 | if not examples_dir.exists(): |
| 517 | return False |
| 518 | |
| 519 | skip_example_hash = False |
| 520 | if example_cache_file.exists(): |
| 521 | try: |
| 522 | cache_mtime = example_cache_file.stat().st_mtime |
| 523 | max_example_dir_mtime = get_max_dir_mtime(examples_dir) |
| 524 | if max_example_dir_mtime <= cache_mtime: |
| 525 | skip_example_hash = True |
| 526 | except OSError: |
| 527 | pass |
| 528 | |
| 529 | if skip_example_hash: |
| 530 | return False |
| 531 | |
| 532 | current_example_hash = compute_example_files_hash(examples_dir) |
| 533 | cached_example_hash = "" |
| 534 | if example_cache_file.exists(): |
| 535 | try: |
| 536 | with open(example_cache_file, "r") as f: |
| 537 | cache_data = json.load(f) |
| 538 | cached_example_hash = cache_data.get("hash", "") |
| 539 | except KeyboardInterrupt as ki: |
| 540 | handle_keyboard_interrupt(ki) |
| 541 | except Exception: |
| 542 | cached_example_hash = "" |
| 543 | |
| 544 | if current_example_hash != cached_example_hash: |
| 545 | print_warning( |
| 546 | "[MESON] ⚠️ Detected example file changes (files added/removed/modified)" |
| 547 | ) |
| 548 | if example_cache_file.exists(): |
| 549 | try: |
| 550 | example_cache_file.unlink() |
| 551 | except OSError: |
| 552 | pass |
| 553 | return True |
| 554 | return False |
| 555 | |
| 556 | except KeyboardInterrupt as ki: |
| 557 | handle_keyboard_interrupt(ki) |
| 558 | raise |
| 559 | except Exception as e: |
| 560 | _ts_print(f"[MESON] Warning: Could not check example file changes: {e}") |
| 561 | return True |
| 562 | |
| 563 | |
| 564 | def check_obsolete_zig_wrappers(source_dir: Path) -> None: |
no test coverage detected