aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreter.py
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2017-01-14 14:41:18 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2017-01-24 00:20:51 +0530
commit7d6f628ed4c3c3dca32bef01b2581f2e9bcde189 (patch)
tree995cb632db1f11e94209bfc18205f7c8e81f52f2 /mesonbuild/interpreter.py
parent905ff356118d3317aa1922bbfee3dd4c3cb71a6f (diff)
downloadmeson-7d6f628ed4c3c3dca32bef01b2581f2e9bcde189.zip
meson-7d6f628ed4c3c3dca32bef01b2581f2e9bcde189.tar.gz
meson-7d6f628ed4c3c3dca32bef01b2581f2e9bcde189.tar.bz2
Support file perms for install_data and install_subdir
With the 'install_mode' kwarg, you can now specify the file and directory permissions and the owner and the group to be used while installing. You can pass either: * A single string specifying just the permissions * A list of strings with: - The first argument a string of permissions - The second argument a string specifying the owner or an int specifying the uid - The third argument a string specifying the group or an int specifying the gid Specifying `false` as any of the arguments skips setting that one. The format of the permissions kwarg is the same as the symbolic notation used by ls -l with the first character that specifies 'd', '-', 'c', etc for the file type omitted since that is always obvious from the context. Includes unit tests for the same. Sadly these only run on Linux right now, but we want them to run on all platforms. We do set the mode in the integration tests for all platforms but we don't check if they were actually set correctly.
Diffstat (limited to 'mesonbuild/interpreter.py')
-rw-r--r--mesonbuild/interpreter.py36
1 files changed, 30 insertions, 6 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index b5cd0b6..cb5b617 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -22,7 +22,7 @@ from . import optinterpreter
from . import compilers
from .wrap import wrap
from . import mesonlib
-from .mesonlib import Popen_safe
+from .mesonlib import FileMode, Popen_safe
from .dependencies import InternalDependency, Dependency
from .interpreterbase import InterpreterBase
from .interpreterbase import check_stringlist, noPosargs, noKwargs, stringArgs
@@ -453,11 +453,12 @@ class DataHolder(InterpreterObject):
return self.held_object.install_dir
class InstallDir(InterpreterObject):
- def __init__(self, source_subdir, installable_subdir, install_dir):
+ def __init__(self, src_subdir, inst_subdir, install_dir, install_mode):
InterpreterObject.__init__(self)
- self.source_subdir = source_subdir
- self.installable_subdir = installable_subdir
+ self.source_subdir = src_subdir
+ self.installable_subdir = inst_subdir
self.install_dir = install_dir
+ self.install_mode = install_mode
class Man(InterpreterObject):
@@ -2141,6 +2142,25 @@ requirements use the version keyword argument instead.''')
self.evaluate_codeblock(codeblock)
self.subdir = prev_subdir
+ def _get_kwarg_install_mode(self, kwargs):
+ if 'install_mode' not in kwargs:
+ return None
+ install_mode = []
+ mode = mesonlib.stringintlistify(kwargs.get('install_mode', []))
+ for m in mode:
+ # We skip any arguments that are set to `false`
+ if m is False:
+ m = None
+ install_mode.append(m)
+ if len(install_mode) > 3:
+ raise InvalidArguments('Keyword argument install_mode takes at '
+ 'most 3 arguments.')
+ if len(install_mode) > 0 and install_mode[0] is not None and \
+ not isinstance(install_mode[0], str):
+ raise InvalidArguments('Keyword argument install_mode requires the '
+ 'permissions arg to be a string or false')
+ return FileMode(*install_mode)
+
def func_install_data(self, node, args, kwargs):
kwsource = mesonlib.stringlistify(kwargs.get('sources', []))
raw_sources = args + kwsource
@@ -2153,7 +2173,10 @@ requirements use the version keyword argument instead.''')
source_strings.append(s)
sources += self.source_strings_to_files(source_strings)
install_dir = kwargs.get('install_dir', None)
- data = DataHolder(build.Data(sources, install_dir))
+ if not isinstance(install_dir, (str, type(None))):
+ raise InvalidArguments('Keyword argument install_dir not a string.')
+ install_mode = self._get_kwarg_install_mode(kwargs)
+ data = DataHolder(build.Data(sources, install_dir, install_mode))
self.build.data.append(data.held_object)
return data
@@ -2166,7 +2189,8 @@ requirements use the version keyword argument instead.''')
install_dir = kwargs['install_dir']
if not isinstance(install_dir, str):
raise InvalidArguments('Keyword argument install_dir not a string.')
- idir = InstallDir(self.subdir, args[0], install_dir)
+ install_mode = self._get_kwarg_install_mode(kwargs)
+ idir = InstallDir(self.subdir, args[0], install_dir, install_mode)
self.build.install_dirs.append(idir)
return idir