3 # External command, intended to be called with meson.add_dist_script() in meson.build
5 # argv[1] argv[2] argv[3:]
6 # dist-build-scripts.py <root_src_dir> <script_dir> <no_dist>...
8 # <script_dir> The directory with the build scripts, relative to <root_source_dir>.
9 # <no_dist> Zero or more names (relative to MESON_PROJECT_DIST_ROOT)
10 # of files and directories that shall not be distributed.
16 # MESON_PROJECT_DIST_ROOT is set only if meson.version() >= 0.58.0.
17 project_dist_root = os.getenv('MESON_PROJECT_DIST_ROOT', os.getenv('MESON_DIST_ROOT'))
18 src_script_dir = os.path.join(sys.argv[1], sys.argv[2])
19 dist_script_dir = os.path.join(project_dist_root, sys.argv[2])
21 # Create the distribution script directory, if it does not exist.
22 os.makedirs(dist_script_dir, exist_ok=True)
24 # Distribute files that mm-common-get has copied to src_script_dir.
26 'check-dllexport-usage.py',
27 'dist-build-scripts.py',
33 shutil.copy(os.path.join(src_script_dir, file), dist_script_dir)
35 # Don't distribute .gitignore files.
36 for dirpath, dirnames, filenames in os.walk(project_dist_root):
37 if '.gitignore' in filenames:
38 os.remove(os.path.join(dirpath, '.gitignore'))
40 # Remove an empty MESON_PROJECT_DIST_ROOT/build directory.
41 dist_build_dir = os.path.join(project_dist_root, 'build')
42 if os.path.isdir(dist_build_dir):
44 os.rmdir(dist_build_dir)
46 # Ignore the error, if not empty.
49 # Remove specified files and directories from the MESON_PROJECT_DIST_ROOT directory.
50 for rel_path in sys.argv[3:]:
51 abs_path = os.path.join(project_dist_root, rel_path)
52 if os.path.isfile(abs_path):
54 elif os.path.isdir(abs_path):
55 shutil.rmtree(abs_path, ignore_errors=True)
57 # Ignore non-existent files and directories.
58 print('--- Info:', abs_path, 'not found, not removed.')