40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Copy a build-tree MFEM prefix into a Meson/meson-python destination."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
|
|
|
|
def staged_destination(destination: Path) -> Path:
|
|
destdir = os.environ.get("DESTDIR", "")
|
|
if not destdir or not destination.is_absolute():
|
|
return destination
|
|
destination_text = os.fspath(destination)
|
|
relative = destination_text[len(destination.anchor) :].lstrip("/\\")
|
|
return Path(destdir) / relative
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--source", type=Path, required=True)
|
|
parser.add_argument("--destination", type=Path, required=True)
|
|
args = parser.parse_args()
|
|
destination = staged_destination(args.destination)
|
|
destination.mkdir(parents=True, exist_ok=True)
|
|
for child in args.source.iterdir():
|
|
target = destination / child.name
|
|
if child.is_dir():
|
|
shutil.copytree(child, target, dirs_exist_ok=True, symlinks=True)
|
|
else:
|
|
shutil.copy2(child, target, follow_symlinks=False)
|
|
print(f"Installed MFEM native bundle to {destination}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|