Ensure meson is configured for WASM cross-compilation. Returns True if configuration succeeded.
(build_dir: Path, mode: str, force: bool = False)
| 652 | |
| 653 | |
| 654 | def ensure_meson_configured(build_dir: Path, mode: str, force: bool = False) -> bool: |
| 655 | """ |
| 656 | Ensure meson is configured for WASM cross-compilation. |
| 657 | |
| 658 | Returns True if configuration succeeded. |
| 659 | """ |
| 660 | file_list_marker = build_dir / ".src_file_list_hash" |
| 661 | |
| 662 | if build_dir.exists() and (build_dir / "build.ninja").exists() and not force: |
| 663 | # Check if source file list changed since last configure |
| 664 | current_hash = _compute_src_file_list_hash() |
| 665 | stored_hash = "" |
| 666 | if file_list_marker.exists(): |
| 667 | try: |
| 668 | stored_hash = file_list_marker.read_text(encoding="utf-8").strip() |
| 669 | except OSError: |
| 670 | pass |
| 671 | if stored_hash == current_hash: |
| 672 | # Re-render the generated cross-file so a freshly built or |
| 673 | # repaired native launcher is picked up on the NEXT meson |
| 674 | # invocation. We don't trigger a reconfigure here — the render |
| 675 | # is cheap (writes a small ini), and the next `meson setup` |
| 676 | # will see the updated paths automatically. |
| 677 | _render_wasm_cross_file(build_dir) |
| 678 | _normalize_meson_private_paths(build_dir) |
| 679 | return True # No file list changes, skip reconfigure |
| 680 | |
| 681 | # Source file list changed — need reconfigure |
| 682 | print("[WASM] Source file list changed, forcing reconfiguration...") |
| 683 | for cache_name in ["src_metadata.cache", "library_src_fingerprint"]: |
| 684 | cache_file = build_dir / cache_name |
| 685 | if cache_file.exists(): |
| 686 | try: |
| 687 | cache_file.unlink() |
| 688 | except OSError: |
| 689 | pass |
| 690 | generated_cross = _render_wasm_cross_file(build_dir) |
| 691 | cmd = [ |
| 692 | get_meson_executable(), |
| 693 | "setup", |
| 694 | "--reconfigure", |
| 695 | "--cross-file", |
| 696 | str(generated_cross), |
| 697 | str(build_dir), |
| 698 | f"-Dbuild_mode={mode}", |
| 699 | ] |
| 700 | print(f"[WASM] Reconfiguring meson (mode: {mode})...") |
| 701 | # Remove any stale meson lockfile before reconfigure (see issue #2484). |
| 702 | _cleanup_stale_meson_lockfile(build_dir) |
| 703 | result = subprocess.run(cmd, cwd=PROJECT_ROOT) |
| 704 | if result.returncode != 0: |
| 705 | print(f"[WASM] Meson reconfiguration failed (rc {result.returncode})") |
| 706 | return False |
| 707 | _normalize_meson_private_paths(build_dir) |
| 708 | try: |
| 709 | file_list_marker.write_text(current_hash, encoding="utf-8") |
| 710 | except OSError: |
| 711 | pass |
no test coverage detected