Skip to content

Commit

Permalink
configure_file: Support 'rename'
Browse files Browse the repository at this point in the history
This allows generated configuration files to be renamed during
installation, just as with install_data.

The rename parameter must either be an empty list, indicating that
renaming is disabled, or a single string.

Signed-off-by: Keith Packard <[email protected]>
  • Loading branch information
keith-packard committed Dec 7, 2024
1 parent fc55a87 commit 1f2d77c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
9 changes: 9 additions & 0 deletions docs/yaml/functions/configure_file.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
8 changes: 7 additions & 1 deletion mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -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]:
Expand Down
1 change: 1 addition & 0 deletions mesonbuild/interpreter/kwargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 7 additions & 0 deletions test cases/common/14 configure file/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion test cases/common/14 configure file/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
]
}

0 comments on commit 1f2d77c

Please sign in to comment.