Skip to content

Commit 614c5f5

Browse files
committed
meson: make install_test_files more generic, rename to install_files
Now it supports installing directories and directory contents as well. This will be used in a subsequent patch to install documentation. Discussion: https://postgr.es/m/3fc3bb9b-f7f8-d442-35c1-ec82280c564a@enterprisedb.com
1 parent 0f0a718 commit 614c5f5

File tree

3 files changed

+78
-35
lines changed

3 files changed

+78
-35
lines changed

meson.build

+3-2
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ flex_cmd = [python, flex_wrapper,
369369
wget = find_program('wget', required: false, native: true)
370370
wget_flags = ['-O', '@OUTPUT0@', '--no-use-server-timestamps']
371371

372+
install_files = files('src/tools/install_files')
373+
372374

373375

374376
###############################################################
@@ -2845,9 +2847,8 @@ testprep_targets += test_install_libs
28452847

28462848

28472849
# command to install files used for tests, which aren't installed by default
2848-
install_test_files = files('src/tools/install_test_files')
28492850
install_test_files_args = [
2850-
install_test_files,
2851+
install_files,
28512852
'--prefix', dir_prefix,
28522853
'--install', contrib_data_dir, test_install_data,
28532854
'--install', dir_lib_pkg, test_install_libs,

src/tools/install_files

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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)

src/tools/install_test_files

-33
This file was deleted.

0 commit comments

Comments
 (0)