From cbae2f4acc12057493d714fc85c52eb89c4b4a6a Mon Sep 17 00:00:00 2001 From: Konstantin Kharlamov Date: Tue, 9 Jan 2024 20:30:15 +0300 Subject: [PATCH] interpreter: handle multiple dirs in install_emptydir Fixes: https://github.com/mesonbuild/meson/issues/12717 --- docs/markdown/snippets/install-many-emptydirs.md | 5 +++++ docs/yaml/functions/install_emptydir.yaml | 7 ++++--- mesonbuild/interpreter/interpreter.py | 10 +++++++--- test cases/common/248 install_emptydir/meson.build | 4 ++++ test cases/common/248 install_emptydir/test.json | 6 ++++-- 5 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 docs/markdown/snippets/install-many-emptydirs.md diff --git a/docs/markdown/snippets/install-many-emptydirs.md b/docs/markdown/snippets/install-many-emptydirs.md new file mode 100644 index 000000000000..27505ae93447 --- /dev/null +++ b/docs/markdown/snippets/install-many-emptydirs.md @@ -0,0 +1,5 @@ +## [[install_emptydir]] now supports multiple dirs inside one call + +Prior to this release passing multiple paths as `dirpath` argument was resulting in only the first path to get created. The rest were ignored. That was expected behavior as [[install_emptydir]] was documented to only take a single path. But it also had an incorrect type annotation that claimed for it to take multiple paths, which led to confusion. + +Now passing more than one path in `dirpath` will create all of them. diff --git a/docs/yaml/functions/install_emptydir.yaml b/docs/yaml/functions/install_emptydir.yaml index df84f60b5d9c..278736f3c9ee 100644 --- a/docs/yaml/functions/install_emptydir.yaml +++ b/docs/yaml/functions/install_emptydir.yaml @@ -2,12 +2,13 @@ name: install_emptydir returns: void since: 0.60.0 description: | - Installs a new directory entry to the location specified by the positional - argument. If the directory exists and is not empty, the contents are left in - place. + Installs a directory (more than one allowed since 1.4.0) to the location + specified by the positional argument. If the directory exists and is not + empty, the contents are left in place. warnings: - the `install_mode` kwarg ignored integer values before 1.1.0. + - second argument and beyond when passed as dirpath were ignored before 1.4.0. varargs: name: dirpath diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index bf2a21d4bd4d..cadca6b4777b 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -2301,14 +2301,18 @@ def func_install_man(self, node: mparser.BaseNode, return m @FeatureNew('install_emptydir', '0.60.0') + @typed_pos_args('install_emptydir', varargs=str, min_varargs=1) @typed_kwargs( 'install_emptydir', INSTALL_MODE_KW, KwargInfo('install_tag', (str, NoneType), since='0.62.0') ) - def func_install_emptydir(self, node: mparser.BaseNode, args: T.Tuple[str], kwargs) -> None: - d = build.EmptyDir(args[0], kwargs['install_mode'], self.subproject, kwargs['install_tag']) - self.build.emptydir.append(d) + def func_install_emptydir(self, node: mparser.BaseNode, args: T.Tuple[T.List[str]], kwargs) -> None: + if len(args[0]) > 1: + FeatureNew.single_use('install_emptydir with more than one directory', '1.4.0', self.subproject, location=node) + self.build.emptydir += \ + [build.EmptyDir(one_dir, kwargs['install_mode'], self.subproject, kwargs['install_tag']) + for one_dir in args[0]] @FeatureNew('install_symlink', '0.61.0') @typed_pos_args('symlink_name', str) diff --git a/test cases/common/248 install_emptydir/meson.build b/test cases/common/248 install_emptydir/meson.build index a5eb046e48c1..cdeb434297c4 100644 --- a/test cases/common/248 install_emptydir/meson.build +++ b/test cases/common/248 install_emptydir/meson.build @@ -2,3 +2,7 @@ project('install_emptydir') install_emptydir(get_option('datadir')/'new_directory', install_mode: 'rwx------') install_emptydir(get_option('datadir')/'new_directory/subdir', install_mode: 'rwxr-----') +install_emptydir([get_option('datadir')/'dir1', + get_option('datadir')/'dir2', + get_option('datadir')/'dir3' + ]) diff --git a/test cases/common/248 install_emptydir/test.json b/test cases/common/248 install_emptydir/test.json index 17abe74bf18e..93522abb7940 100644 --- a/test cases/common/248 install_emptydir/test.json +++ b/test cases/common/248 install_emptydir/test.json @@ -1,7 +1,9 @@ { "installed": [ { "type": "dir", "file": "usr/share/new_directory" }, - { "type": "dir", "file": "usr/share/new_directory/subdir" } + { "type": "dir", "file": "usr/share/new_directory/subdir" }, + { "type": "dir", "file": "usr/share/dir1" }, + { "type": "dir", "file": "usr/share/dir2" }, + { "type": "dir", "file": "usr/share/dir3" } ] } -