Add elide_directory keyword for install_subdir() function

If elide_directory=true install_subdir() installs directory contents
instead of directory itself, eliding name of the source directory.

Closes #2869.
pull/3010/head
Aleksey Filippov 7 years ago
parent 86ee89b400
commit 8ca3cc0c3d
  1. 28
      docs/markdown/Reference-manual.md
  2. 4
      docs/markdown/snippets/install_subdir-elide_directory.md
  3. 5
      mesonbuild/backend/ninjabackend.py
  4. 13
      mesonbuild/interpreter.py
  5. 6
      test cases/common/66 install subdir/installed_files.txt
  6. 4
      test cases/common/66 install subdir/meson.build
  7. 1
      test cases/common/66 install subdir/nested_elided/sub/dircheck/nineth.dat
  8. 1
      test cases/common/66 install subdir/nested_elided/sub/eighth.dat
  9. 1
      test cases/common/66 install subdir/sub_elided/dircheck/fifth.dat
  10. 1
      test cases/common/66 install subdir/sub_elided/fourth.dat
  11. 2
      test cases/common/66 install subdir/subdir/meson.build
  12. 1
      test cases/common/66 install subdir/subdir/sub_elided/dircheck/seventh.dat
  13. 1
      test cases/common/66 install subdir/subdir/sub_elided/sixth.dat

@ -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()

@ -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.

@ -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])

@ -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

@ -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

@ -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)

@ -0,0 +1 @@
Data file in a subdir of elided directory.

@ -0,0 +1 @@
Test that this file is installed directly into install_dir.

@ -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)

Loading…
Cancel
Save