diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2022-06-19 16:04:48 -0400 |
---|---|---|
committer | Eli Schwartz <eschwartz@archlinux.org> | 2022-07-08 01:58:23 -0400 |
commit | e7d87b6f58c653c3962479f59867397ffc15c32f (patch) | |
tree | 61e39ad22650fbe94d5bdb9c9b2edd263aa14dc3 /mesonbuild/interpreter/interpreter.py | |
parent | b89451847af56dc5f224a0e09605ad965d58aabe (diff) | |
download | meson-e7d87b6f58c653c3962479f59867397ffc15c32f.zip meson-e7d87b6f58c653c3962479f59867397ffc15c32f.tar.gz meson-e7d87b6f58c653c3962479f59867397ffc15c32f.tar.bz2 |
implement the new preserve_path kwarg for install_data too
Primarily interesting to me because it is then available for the python
module's install_sources method.
Based on the new feature in install_headers.
Diffstat (limited to 'mesonbuild/interpreter/interpreter.py')
-rw-r--r-- | mesonbuild/interpreter/interpreter.py | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index c2f0813..2f31815 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -79,6 +79,7 @@ from .type_checking import ( INSTALL_TAG_KW, LANGUAGE_KW, NATIVE_KW, + PRESERVE_PATH_KW, REQUIRED_KW, SOURCES_KW, VARIABLES_KW, @@ -2094,7 +2095,7 @@ class Interpreter(InterpreterBase, HoldableObject): @typed_pos_args('install_headers', varargs=(str, mesonlib.File)) @typed_kwargs( 'install_headers', - KwargInfo('preserve_path', bool, default=False, since='0.63.0'), + PRESERVE_PATH_KW, KwargInfo('subdir', (str, NoneType)), INSTALL_MODE_KW.evolve(since='0.47.0'), INSTALL_DIR_KW, @@ -2302,6 +2303,7 @@ class Interpreter(InterpreterBase, HoldableObject): INSTALL_MODE_KW.evolve(since='0.38.0'), INSTALL_TAG_KW.evolve(since='0.60.0'), INSTALL_DIR_KW, + PRESERVE_PATH_KW.evolve(since='0.64.0'), ) def func_install_data(self, node: mparser.BaseNode, args: T.Tuple[T.List['mesonlib.FileOrString']], @@ -2321,19 +2323,35 @@ class Interpreter(InterpreterBase, HoldableObject): else: install_dir_name = '{datadir}' return self.install_data_impl(sources, kwargs['install_dir'], kwargs['install_mode'], - rename, kwargs['install_tag'], install_dir_name) + rename, kwargs['install_tag'], install_dir_name, + preserve_path=kwargs['preserve_path']) def install_data_impl(self, sources: T.List[mesonlib.File], install_dir: T.Optional[str], install_mode: FileMode, rename: T.Optional[str], tag: T.Optional[str], install_dir_name: T.Optional[str] = None, - install_data_type: T.Optional[str] = None) -> build.Data: + install_data_type: T.Optional[str] = None, + preserve_path: bool = False) -> build.Data: """Just the implementation with no validation.""" - data = build.Data(sources, install_dir, install_dir_name or install_dir, install_mode, - self.subproject, rename, tag, install_data_type) - self.build.data.append(data) - return data + idir = install_dir or '' + idir_name = install_dir_name or idir + dirs = collections.defaultdict(list) + ret_data = [] + if preserve_path: + for file in sources: + dirname = os.path.dirname(file.fname) + dirs[dirname].append(file) + else: + dirs[''].extend(sources) + + for childdir, files in dirs.items(): + d = build.Data(files, os.path.join(idir, childdir), os.path.join(idir_name, childdir), + install_mode, self.subproject, rename, tag, install_data_type) + ret_data.append(d) + + self.build.data.extend(ret_data) + return ret_data @typed_pos_args('install_subdir', str) @typed_kwargs( |