|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# Helper to install files that are not part of the default meson install |
| 4 | +# target. |
| 5 | +# |
| 6 | +# This includes files that should only get installed into the temporary |
| 7 | +# installation for tests and documentation. |
| 8 | + |
| 9 | +import argparse |
| 10 | +import os |
| 11 | +import shutil |
| 12 | +import sys |
| 13 | +from pathlib import PurePath |
| 14 | + |
| 15 | +parser = argparse.ArgumentParser() |
| 16 | + |
| 17 | +parser.add_argument('--destdir', type=str, |
| 18 | + default=os.environ.get('DESTDIR', None)) |
| 19 | +parser.add_argument('--prefix', type=str) |
| 20 | +parser.add_argument('--install', type=str, nargs='+', |
| 21 | + action='append', default=[]) |
| 22 | +parser.add_argument('--install-dirs', type=str, nargs='+', |
| 23 | + action='append', default=[]) |
| 24 | +parser.add_argument('--install-dir-contents', type=str, nargs='+', |
| 25 | + action='append', default=[]) |
| 26 | + |
| 27 | +args = parser.parse_args() |
| 28 | + |
| 29 | + |
| 30 | +def error_exit(msg: str): |
| 31 | + print(msg, file=sys.stderr) |
| 32 | + exit(1) |
| 33 | + |
| 34 | + |
| 35 | +def create_target_dir(prefix: str, destdir: str, targetdir: str): |
| 36 | + if not os.path.isabs(targetdir): |
| 37 | + targetdir = os.path.join(prefix, targetdir) |
| 38 | + |
| 39 | + if destdir is not None: |
| 40 | + # copy of meson's logic for joining destdir and install paths |
| 41 | + targetdir = str(PurePath(destdir, *PurePath(targetdir).parts[1:])) |
| 42 | + |
| 43 | + os.makedirs(targetdir, exist_ok=True) |
| 44 | + |
| 45 | + return targetdir |
| 46 | + |
| 47 | + |
| 48 | +def copy_files(targetdir: str, src_list: list): |
| 49 | + for src in src_list: |
| 50 | + shutil.copy2(src, targetdir) |
| 51 | + |
| 52 | + |
| 53 | +def copy_dirs(targetdir: str, src_list: list, contents: bool): |
| 54 | + for src in src_list: |
| 55 | + if not os.path.isdir(src): |
| 56 | + error_exit('{0} is not a directory'.format(src)) |
| 57 | + |
| 58 | + if contents: |
| 59 | + target = targetdir |
| 60 | + else: |
| 61 | + target = os.path.join(targetdir, os.path.split(src)[1]) |
| 62 | + shutil.copytree(src, target, dirs_exist_ok=True) |
| 63 | + |
| 64 | + |
| 65 | +for installs in args.install: |
| 66 | + targetdir = create_target_dir(args.prefix, args.destdir, installs[0]) |
| 67 | + copy_files(targetdir, installs[1:]) |
| 68 | + |
| 69 | +for installs in args.install_dirs: |
| 70 | + targetdir = create_target_dir(args.prefix, args.destdir, installs[0]) |
| 71 | + copy_dirs(targetdir, installs[1:], contents=False) |
| 72 | + |
| 73 | +for installs in args.install_dir_contents: |
| 74 | + targetdir = create_target_dir(args.prefix, args.destdir, installs[0]) |
| 75 | + copy_dirs(targetdir, installs[1:], contents=True) |
0 commit comments