3 # Helper to install files that are not part of the default meson install
6 # This includes files that should only get installed into the temporary
7 # installation for tests and documentation.
13 from pathlib import PurePath
15 parser = argparse.ArgumentParser()
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=[])
27 args = parser.parse_args()
30 def error_exit(msg: str):
31 print(msg, file=sys.stderr)
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)
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:]))
43 os.makedirs(targetdir, exist_ok=True)
48 def copy_files(targetdir: str, src_list: list):
50 shutil.copy2(src, targetdir)
53 def copy_dirs(targetdir: str, src_list: list, contents: bool):
55 if not os.path.isdir(src):
56 error_exit('{0} is not a directory'.format(src))
61 target = os.path.join(targetdir, os.path.split(src)[1])
62 shutil.copytree(src, target, dirs_exist_ok=True)
65 for installs in args.install:
66 targetdir = create_target_dir(args.prefix, args.destdir, installs[0])
67 copy_files(targetdir, installs[1:])
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)
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)