aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/markdown/Reference-manual.md28
-rw-r--r--docs/markdown/snippets/install_subdir-elide_directory.md4
-rw-r--r--mesonbuild/backend/ninjabackend.py5
-rw-r--r--mesonbuild/interpreter.py13
-rw-r--r--test cases/common/66 install subdir/installed_files.txt6
-rw-r--r--test cases/common/66 install subdir/meson.build4
-rw-r--r--test cases/common/66 install subdir/nested_elided/sub/dircheck/nineth.dat1
-rw-r--r--test cases/common/66 install subdir/nested_elided/sub/eighth.dat1
-rw-r--r--test cases/common/66 install subdir/sub_elided/dircheck/fifth.dat1
-rw-r--r--test cases/common/66 install subdir/sub_elided/fourth.dat1
-rw-r--r--test cases/common/66 install subdir/subdir/meson.build2
-rw-r--r--test cases/common/66 install subdir/subdir/sub_elided/dircheck/seventh.dat1
-rw-r--r--test cases/common/66 install subdir/subdir/sub_elided/sixth.dat1
13 files changed, 62 insertions, 6 deletions
diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md
index 390371b..e5fcb67 100644
--- a/docs/markdown/Reference-manual.md
+++ b/docs/markdown/Reference-manual.md
@@ -772,7 +772,7 @@ installed with a `.gz` suffix.
### install_subdir()
``` meson
- void install_subdir(subdir_name, install_dir : ..., exclude_files : ..., exclude_directories : ...)
+ void install_subdir(subdir_name, install_dir : ..., exclude_files : ..., exclude_directories : ..., elide_directory : ...)
```
Installs the entire given subdirectory and its contents from the
@@ -786,6 +786,32 @@ The following keyword arguments are supported:
- `exclude_directories`: a list of directory names that should not be installed.
Names are interpreted as paths relative to the `subdir_name` location.
- `install_dir`: the location to place the installed subdirectory.
+- `elide_directory`: install directory contents. `elide_directory=false` by default.
+ Since 0.45.0
+
+For a given directory `foo`:
+```
+foo/
+ bar/
+ file1
+ file2
+```
+`install_subdir('foo', install_dir : 'share', elide_directory : false)` creates
+```
+share/
+ foo/
+ bar/
+ file1
+ file2
+```
+
+`install_subdir('foo', install_dir : 'share', elide_directory : true)` creates
+```
+share/
+ bar/
+ file1
+ file2
+```
### is_variable()
diff --git a/docs/markdown/snippets/install_subdir-elide_directory.md b/docs/markdown/snippets/install_subdir-elide_directory.md
new file mode 100644
index 0000000..516a286
--- /dev/null
+++ b/docs/markdown/snippets/install_subdir-elide_directory.md
@@ -0,0 +1,4 @@
+## install_subdir() supports elide_directory
+
+If elide_directory=true install_subdir() installs directory contents
+instead of directory itself, eliding name of the source directory.
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index 35e697c..ba33012 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -851,8 +851,9 @@ int dummy;
sd.source_subdir,
sd.installable_subdir).rstrip('/')
dst_dir = os.path.join(self.environment.get_prefix(),
- sd.install_dir,
- os.path.basename(src_dir))
+ sd.install_dir)
+ if not sd.elide_directory:
+ dst_dir = os.path.join(dst_dir, os.path.basename(src_dir))
d.install_subdirs.append([src_dir, dst_dir, sd.install_mode,
sd.exclude])
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 2273b71..0d9e6e8 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -507,13 +507,14 @@ class DataHolder(InterpreterObject, ObjectHolder):
return self.held_object.install_dir
class InstallDir(InterpreterObject):
- def __init__(self, src_subdir, inst_subdir, install_dir, install_mode, exclude):
+ def __init__(self, src_subdir, inst_subdir, install_dir, install_mode, exclude, elide_directory):
InterpreterObject.__init__(self)
self.source_subdir = src_subdir
self.installable_subdir = inst_subdir
self.install_dir = install_dir
self.install_mode = install_mode
self.exclude = exclude
+ self.elide_directory = elide_directory
class Man(InterpreterObject):
@@ -1390,7 +1391,7 @@ permitted_kwargs = {'add_global_arguments': {'language'},
'install_data': {'install_dir', 'install_mode', 'sources'},
'install_headers': {'install_dir', 'subdir'},
'install_man': {'install_dir'},
- 'install_subdir': {'exclude_files', 'exclude_directories', 'install_dir', 'install_mode'},
+ 'install_subdir': {'elide_directory', 'exclude_files', 'exclude_directories', 'install_dir', 'install_mode'},
'jar': jar_kwargs,
'project': {'version', 'meson_version', 'default_options', 'license', 'subproject_dir'},
'run_target': {'command', 'depends'},
@@ -2674,6 +2675,12 @@ root and issuing %s.
install_dir = kwargs['install_dir']
if not isinstance(install_dir, str):
raise InvalidArguments('Keyword argument install_dir not a string.')
+ if 'elide_directory' in kwargs:
+ if not isinstance(kwargs['elide_directory'], bool):
+ raise InterpreterException('"elide_directory" keyword must be a boolean.')
+ elide_directory = kwargs['elide_directory']
+ else:
+ elide_directory = False
if 'exclude_files' in kwargs:
exclude = extract_as_list(kwargs, 'exclude_files')
for f in exclude:
@@ -2696,7 +2703,7 @@ root and issuing %s.
exclude_directories = set()
exclude = (exclude_files, exclude_directories)
install_mode = self._get_kwarg_install_mode(kwargs)
- idir = InstallDir(self.subdir, subdir, install_dir, install_mode, exclude)
+ idir = InstallDir(self.subdir, subdir, install_dir, install_mode, exclude, elide_directory)
self.build.install_dirs.append(idir)
return idir
diff --git a/test cases/common/66 install subdir/installed_files.txt b/test cases/common/66 install subdir/installed_files.txt
index e5d2307..3f561d5 100644
--- a/test cases/common/66 install subdir/installed_files.txt
+++ b/test cases/common/66 install subdir/installed_files.txt
@@ -1,3 +1,9 @@
+usr/share/dircheck/fifth.dat
+usr/share/dircheck/seventh.dat
+usr/share/dircheck/nineth.dat
+usr/share/eighth.dat
+usr/share/fourth.dat
+usr/share/sixth.dat
usr/share/sub1/data1.dat
usr/share/sub1/second.dat
usr/share/sub1/third.dat
diff --git a/test cases/common/66 install subdir/meson.build b/test cases/common/66 install subdir/meson.build
index 18e0eaf..b65ab79 100644
--- a/test cases/common/66 install subdir/meson.build
+++ b/test cases/common/66 install subdir/meson.build
@@ -11,3 +11,7 @@ subdir('subdir')
# and read-list perms for owner and group
install_subdir('sub1', install_dir : 'share', install_mode : ['rwxr-x--t', 'root'])
install_subdir('sub/sub1', install_dir : 'share')
+
+# elide_directory
+install_subdir('sub_elided', install_dir : 'share', elide_directory : true)
+install_subdir('nested_elided/sub', install_dir : 'share', elide_directory : true)
diff --git a/test cases/common/66 install subdir/nested_elided/sub/dircheck/nineth.dat b/test cases/common/66 install subdir/nested_elided/sub/dircheck/nineth.dat
new file mode 100644
index 0000000..c4eaca7
--- /dev/null
+++ b/test cases/common/66 install subdir/nested_elided/sub/dircheck/nineth.dat
@@ -0,0 +1 @@
+Nested file under nested elided directory.
diff --git a/test cases/common/66 install subdir/nested_elided/sub/eighth.dat b/test cases/common/66 install subdir/nested_elided/sub/eighth.dat
new file mode 100644
index 0000000..fa9b7b7
--- /dev/null
+++ b/test cases/common/66 install subdir/nested_elided/sub/eighth.dat
@@ -0,0 +1 @@
+File in nested elided directory.
diff --git a/test cases/common/66 install subdir/sub_elided/dircheck/fifth.dat b/test cases/common/66 install subdir/sub_elided/dircheck/fifth.dat
new file mode 100644
index 0000000..b6ca009
--- /dev/null
+++ b/test cases/common/66 install subdir/sub_elided/dircheck/fifth.dat
@@ -0,0 +1 @@
+Data file in a subdir of elided directory.
diff --git a/test cases/common/66 install subdir/sub_elided/fourth.dat b/test cases/common/66 install subdir/sub_elided/fourth.dat
new file mode 100644
index 0000000..ca5f26a
--- /dev/null
+++ b/test cases/common/66 install subdir/sub_elided/fourth.dat
@@ -0,0 +1 @@
+Test that this file is installed directly into install_dir.
diff --git a/test cases/common/66 install subdir/subdir/meson.build b/test cases/common/66 install subdir/subdir/meson.build
index a1dadd4..270da57 100644
--- a/test cases/common/66 install subdir/subdir/meson.build
+++ b/test cases/common/66 install subdir/subdir/meson.build
@@ -1,3 +1,5 @@
install_subdir('sub1', install_dir : 'share',
# This mode will be overridden by the mode set in the outer install_subdir
install_mode : 'rwxr-x---')
+
+install_subdir('sub_elided', install_dir : 'share', elide_directory : true)
diff --git a/test cases/common/66 install subdir/subdir/sub_elided/dircheck/seventh.dat b/test cases/common/66 install subdir/subdir/sub_elided/dircheck/seventh.dat
new file mode 100644
index 0000000..ea0b8dc
--- /dev/null
+++ b/test cases/common/66 install subdir/subdir/sub_elided/dircheck/seventh.dat
@@ -0,0 +1 @@
+Nested file in a subdir.
diff --git a/test cases/common/66 install subdir/subdir/sub_elided/sixth.dat b/test cases/common/66 install subdir/subdir/sub_elided/sixth.dat
new file mode 100644
index 0000000..140f075
--- /dev/null
+++ b/test cases/common/66 install subdir/subdir/sub_elided/sixth.dat
@@ -0,0 +1 @@
+Elide test file in a subdir.