From ad8f24f232290b778dad1152583820512ecf9f63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20=22sp1rit=22=E2=80=8B?= Date: Sat, 23 Apr 2022 00:02:13 +0200 Subject: Implement `preserve_path` for install_headers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `install_headers` function now has an optional argument `preserve_path` that allows installing multi-directory headerfile structures that live alongside sourcecode with a single command. For example, the headerfile structure headers = [ 'one.h', 'two.h', 'alpha/one.h', 'alpha/two.h', 'alpha/three.h' 'beta/one.h' ] can now be passed to `install_headers(headers, subdir: 'mylib', preserve_path: true)` and the resulting directory tree will look like {prefix} └── include    └── mylib       ├── alpha       │   ├── one.h       │   ├── two.h       │   └── three.h       ├── beta       │   └── one.h       ├── one.h       └── two.h Fixes #3371 --- mesonbuild/interpreter/interpreter.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'mesonbuild') diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 7b87843c..af83c0e54 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -2091,6 +2091,7 @@ class Interpreter(InterpreterBase, HoldableObject): @typed_kwargs( 'install_headers', KwargInfo('install_dir', (str, NoneType)), + KwargInfo('preserve_path', bool, default=False, since='0.63.0'), KwargInfo('subdir', (str, NoneType)), INSTALL_MODE_KW.evolve(since='0.47.0'), ) @@ -2104,12 +2105,25 @@ class Interpreter(InterpreterBase, HoldableObject): raise InterpreterException('install_headers: cannot specify both "install_dir" and "subdir". Use only "install_dir".') if os.path.isabs(install_subdir): mlog.deprecation('Subdir keyword must not be an absolute path. This will be a hard error in the next release.') + else: + install_subdir = '' + + dirs = collections.defaultdict(list) + ret_headers = [] + if kwargs['preserve_path']: + for file in source_files: + dirname = os.path.dirname(file.fname) + dirs[dirname].append(file) + else: + dirs[''].extend(source_files) - h = build.Headers(source_files, install_subdir, kwargs['install_dir'], - kwargs['install_mode'], self.subproject) - self.build.headers.append(h) + for childdir in dirs: + h = build.Headers(dirs[childdir], os.path.join(install_subdir, childdir), kwargs['install_dir'], + kwargs['install_mode'], self.subproject) + ret_headers.append(h) + self.build.headers.append(h) - return h + return ret_headers @typed_pos_args('install_man', varargs=(str, mesonlib.File)) @typed_kwargs( -- cgit v1.1