diff --git a/docs/yaml/functions/configure_file.yaml b/docs/yaml/functions/configure_file.yaml index 20b96aa6e62d..069a1e3a7c8c 100644 --- a/docs/yaml/functions/configure_file.yaml +++ b/docs/yaml/functions/configure_file.yaml @@ -153,3 +153,12 @@ kwargs: description: | When specified, macro guards will be used instead of '#pragma once'. The macro guard name will be the specified name. + + rename: + type: str + since: 1.7.0 + description: | + If specified, renames the output to the provided name during + install. A nested path is allowed and is joined with + `install_dir`. The `rename` value must either be an empty list + (which disables this feature) or a single string. diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 5d2429e3873e..7efbaded9deb 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -2645,6 +2645,7 @@ def func_install_subdir(self, node: mparser.BaseNode, args: T.Tuple[str], KwargInfo('output_format', str, default='c', since='0.47.0', since_values={'json': '1.3.0'}, validator=in_set_validator({'c', 'json', 'nasm'})), KwargInfo('macro_name', (str, NoneType), default=None, since='1.3.0'), + KwargInfo('rename', (ContainerTypeInfo(list, str), NoneType), default=None, listify=True, since='1.7.0'), ) def func_configure_file(self, node: mparser.BaseNode, args: T.List[TYPE_var], kwargs: kwtypes.ConfigureFile): @@ -2703,6 +2704,11 @@ def func_configure_file(self, node: mparser.BaseNode, args: T.List[TYPE_var], (ofile_path, ofile_fname) = os.path.split(os.path.join(self.subdir, output)) ofile_abs = os.path.join(self.environment.build_dir, ofile_path, ofile_fname) + # Validate rename + rename = kwargs['rename'] + if rename and len(rename) != 1: + raise InterpreterException('rename must either be an empty list or a single string') + # Perform the appropriate action if kwargs['configuration'] is not None: conf = kwargs['configuration'] @@ -2797,7 +2803,7 @@ def func_configure_file(self, node: mparser.BaseNode, args: T.List[TYPE_var], cfile = mesonlib.File.from_built_file(ofile_path, ofile_fname) install_tag = kwargs['install_tag'] self.build.data.append(build.Data([cfile], idir, idir_name, install_mode, self.subproject, - install_tag=install_tag, data_type='configure')) + install_tag=install_tag, data_type='configure', rename=rename)) return mesonlib.File.from_built_file(self.subdir, output) def extract_incdirs(self, kwargs, key: str = 'include_directories') -> T.List[build.IncludeDirs]: diff --git a/mesonbuild/interpreter/kwargs.py b/mesonbuild/interpreter/kwargs.py index ae4866a88ad8..c1f9898504f6 100644 --- a/mesonbuild/interpreter/kwargs.py +++ b/mesonbuild/interpreter/kwargs.py @@ -299,6 +299,7 @@ class ConfigureFile(TypedDict): install_dir: T.Union[str, T.Literal[False]] install_mode: FileMode install_tag: T.Optional[str] + rename: T.List[str] encoding: str command: T.Optional[T.List[T.Union[build.Executable, ExternalProgram, Compiler, File, str]]] input: T.List[FileOrString] diff --git a/test cases/common/14 configure file/meson.build b/test cases/common/14 configure file/meson.build index 036a562b796c..d46b3770f046 100644 --- a/test cases/common/14 configure file/meson.build +++ b/test cases/common/14 configure file/meson.build @@ -30,6 +30,13 @@ configure_file(input : files('config.h.in'), output : 'config2.h', configuration : conf) +# Test if rename works +configure_file(input : files('config.h.in'), + output : 'config2.h', + install_dir : 'share/appdir', + rename : 'subdir/config2-rename.h', + configuration : conf) + # Now generate a header file with an external script. genprog = import('python3').find_python() scriptfile = '@0@/generator.py'.format(meson.current_source_dir()) diff --git a/test cases/common/14 configure file/test.json b/test cases/common/14 configure file/test.json index 5a6ccd57a8fb..4c95dfc25955 100644 --- a/test cases/common/14 configure file/test.json +++ b/test cases/common/14 configure file/test.json @@ -4,6 +4,7 @@ {"type": "file", "file": "usr/share/appdir/config2b.h"}, {"type": "file", "file": "usr/share/appdireh/config2-1.h"}, {"type": "file", "file": "usr/share/appdirok/config2-2.h"}, - {"type": "file", "file": "usr/share/configure file test/invalid-utf8-1.bin"} + {"type": "file", "file": "usr/share/configure file test/invalid-utf8-1.bin"}, + {"type": "file", "file": "usr/share/appdir/subdir/config2-rename.h"} ] }