summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjell Ahlstedt <kjellahlstedt@gmail.com>2020-09-02 10:10:08 +0200
committerKjell Ahlstedt <kjellahlstedt@gmail.com>2020-09-02 10:10:08 +0200
commit775aed54a97a59a12b980cc82b9b80c698b3a181 (patch)
tree0cd88713e33042872e9f5afa3bdfdf0850957f5b
parentdbc362e4341988668d06e0d9f09482b5d5bf3bd6 (diff)
downloadmm-common-775aed54a97a59a12b980cc82b9b80c698b3a181.tar.gz
dist-build-scripts.py: Remove files from dist, if requested
The caller (a meson.build file in e.g. glibmm) can specify git-tracked files and directories that shall not be included in the tarball. They shall be removed from MESON_DIST_ROOT.
-rwxr-xr-xutil/build_scripts/dist-build-scripts.py26
1 files changed, 20 insertions, 6 deletions
diff --git a/util/build_scripts/dist-build-scripts.py b/util/build_scripts/dist-build-scripts.py
index bdcda10..31aca50 100755
--- a/util/build_scripts/dist-build-scripts.py
+++ b/util/build_scripts/dist-build-scripts.py
@@ -2,17 +2,20 @@
# External command, intended to be called with meson.add_dist_script() in meson.build
-# sys.argv[1] sys.argv[2]
-# dist-build-scripts.py <root_src_dir> <relative_script_dir>
+# argv[1] argv[2] argv[3:]
+# dist-build-scripts.py <root_src_dir> <script_dir> <no_dist>...
-# <relative_script_dir> is the directory with the build scripts, relative to <root_source_dir>.
+# <script_dir> The directory with the build scripts, relative to <root_source_dir>.
+# <no_dist> Zero or more names (relative to MESON_DIST_ROOT) of files and
+# directories that shall not be distributed.
import os
import sys
import shutil
+dist_root = os.getenv('MESON_DIST_ROOT')
src_script_dir = os.path.join(sys.argv[1], sys.argv[2])
-dist_script_dir = os.path.join(os.getenv('MESON_DIST_ROOT'), sys.argv[2])
+dist_script_dir = os.path.join(dist_root, sys.argv[2])
# Create the distribution script directory, if it does not exist.
os.makedirs(dist_script_dir, exist_ok=True)
@@ -29,15 +32,26 @@ for file in files:
shutil.copy(os.path.join(src_script_dir, file), dist_script_dir)
# Don't distribute .gitignore files.
-for dirpath, dirnames, filenames in os.walk(os.getenv('MESON_DIST_ROOT')):
+for dirpath, dirnames, filenames in os.walk(dist_root):
if '.gitignore' in filenames:
os.remove(os.path.join(dirpath, '.gitignore'))
# Remove an empty MESON_DIST_ROOT/build directory.
-dist_build_dir = os.path.join(os.getenv('MESON_DIST_ROOT'), 'build')
+dist_build_dir = os.path.join(dist_root, 'build')
if os.path.isdir(dist_build_dir):
try:
os.rmdir(dist_build_dir)
except OSError:
# Ignore the error, if not empty.
pass
+
+# Remove specified files and directories from the MESON_DIST_ROOT directory.
+for rel_path in sys.argv[3:]:
+ abs_path = os.path.join(dist_root, rel_path)
+ if os.path.isfile(abs_path):
+ os.remove(abs_path)
+ elif os.path.isdir(abs_path):
+ shutil.rmtree(abs_path, ignore_errors=True)
+ else:
+ # Ignore non-existent files and directories.
+ print('--- Info:', abs_path, 'not found, not removed.')