summaryrefslogtreecommitdiff
path: root/tests/copydir.py
blob: 06533f126a93827ebb29140a223662eddbd63579 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT

"""
Copy files from the source directory into the build directory.

Use to simplify running tests.
"""

import os
import shutil
import sys
from pathlib import Path

MESON_SOURCE_ROOT = Path(os.environ.get("MESON_SOURCE_ROOT", ""))
MESON_BUILD_ROOT = Path(os.environ.get("MESON_BUILD_ROOT", ""))
MESON_SUBDIR = os.environ.get("MESON_SUBDIR", "")

directory = Path(sys.argv[1])
excluded = tuple(str(directory / f) for f in sys.argv[2:])

source = MESON_SOURCE_ROOT / MESON_SUBDIR / directory
destination = MESON_BUILD_ROOT / MESON_SUBDIR / directory
destination.mkdir(parents=True, exist_ok=True)


# Callback for shutil.copytree
def ignore(directory: str, contents: list[str]) -> list[str]:
    return [f for f in contents if any(Path(directory, f).match(p) for p in excluded)]


shutil.copytree(source, destination, dirs_exist_ok=True, ignore=ignore)