From ce6a705438b28efd4a29e62d58cd7a3728e77c7f Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Tue, 5 Nov 2024 15:03:11 -0500 Subject: [PATCH] vcs_tag: Add install kwargs Fixes: #4893 --- docs/markdown/snippets/vcs_tag.md | 4 ++++ docs/yaml/functions/vcs_tag.yaml | 31 +++++++++++++++++++++++++ mesonbuild/interpreter/interpreter.py | 15 ++++++++++++ test cases/common/66 vcstag/meson.build | 4 +++- test cases/common/66 vcstag/test.json | 8 +++++++ 5 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 docs/markdown/snippets/vcs_tag.md create mode 100644 test cases/common/66 vcstag/test.json diff --git a/docs/markdown/snippets/vcs_tag.md b/docs/markdown/snippets/vcs_tag.md new file mode 100644 index 000000000000..c60996a2ea31 --- /dev/null +++ b/docs/markdown/snippets/vcs_tag.md @@ -0,0 +1,4 @@ +## Install vcs_tag() output + +[[vcs_tag]] now has `install`, `install_dir`, `install_tag` and `install_mode` +keyword arguments to install the generated file. diff --git a/docs/yaml/functions/vcs_tag.yaml b/docs/yaml/functions/vcs_tag.yaml index b4aad12c60de..3a3568429edc 100644 --- a/docs/yaml/functions/vcs_tag.yaml +++ b/docs/yaml/functions/vcs_tag.yaml @@ -55,3 +55,34 @@ kwargs: type: str default: "'@VCS_TAG@'" description: String in the input file to substitute with the commit information. + + install: + type: bool + default: false + since: 1.7.0 + description: | + When true, this generated file is installed during + the install step, and `install_dir` must be set and not empty. + + install_dir: + type: str + since: 1.7.0 + description: | + The subdirectory to install the generated file to (e.g. `share/myproject`). + + install_mode: + type: list[str | int] + since: 1.7.0 + description: | + Specify the file mode in symbolic format + and optionally the owner/uid and group/gid for the installed files. + + See the `install_mode` kwarg of [[install_data]] for more information. + + install_tag: + type: str + since: 1.7.0 + description: | + A string used by the `meson install --tags` command + to install only a subset of the files. By default the file has no install + tag which means it is not being installed when `--tags` argument is specified. diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 7bb2337425c5..99530a8c89c5 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -1954,6 +1954,10 @@ def func_build_target(self, node: mparser.BaseNode, ), KwargInfo('fallback', (str, NoneType)), KwargInfo('replace_string', str, default='@VCS_TAG@'), + INSTALL_KW.evolve(since='1.7.0'), + INSTALL_DIR_KW.evolve(since='1.7.0'), + INSTALL_TAG_KW.evolve(since='1.7.0'), + INSTALL_MODE_KW.evolve(since='1.7.0'), ) def func_vcs_tag(self, node: mparser.BaseNode, args: T.List['TYPE_var'], kwargs: 'kwtypes.VcsTag') -> build.CustomTarget: if kwargs['fallback'] is None: @@ -1994,6 +1998,13 @@ def func_vcs_tag(self, node: mparser.BaseNode, args: T.List['TYPE_var'], kwargs: replace_string, regex_selector] + vcs_cmd + install = kwargs['install'] + install_mode = self._warn_kwarg_install_mode_sticky(kwargs['install_mode']) + install_dir = [] if kwargs['install_dir'] is None else [kwargs['install_dir']] + install_tag = [] if kwargs['install_tag'] is None else [kwargs['install_tag']] + if install and not install_dir: + raise InvalidArguments('vcs_tag: "install_dir" keyword argument must be set when "install" is true.') + tg = build.CustomTarget( kwargs['output'][0], self.subdir, @@ -2004,6 +2015,10 @@ def func_vcs_tag(self, node: mparser.BaseNode, args: T.List['TYPE_var'], kwargs: kwargs['output'], build_by_default=True, build_always_stale=True, + install=install, + install_dir=install_dir, + install_mode=install_mode, + install_tag=install_tag, ) self.add_target(tg.name, tg) return tg diff --git a/test cases/common/66 vcstag/meson.build b/test cases/common/66 vcstag/meson.build index 38fa590385cf..53f90d8571f9 100644 --- a/test cases/common/66 vcstag/meson.build +++ b/test cases/common/66 vcstag/meson.build @@ -32,7 +32,9 @@ tagprog = executable('tagprog', 'tagprog.c', version_src) version_src_executable = vcs_tag(input : 'vcstag.c.in', output : 'vcstag-executable.c', -command : [tagprog]) +command : [tagprog], +install: true, +install_dir: get_option('includedir')) executable('tagprog-custom', 'tagprog.c', version_src_custom) executable('tagprog-fallback', 'tagprog.c', version_src_fallback) diff --git a/test cases/common/66 vcstag/test.json b/test cases/common/66 vcstag/test.json new file mode 100644 index 000000000000..4c9e3a197215 --- /dev/null +++ b/test cases/common/66 vcstag/test.json @@ -0,0 +1,8 @@ +{ + "installed": [ + { + "type": "file", + "file": "usr/include/vcstag-executable.c" + } + ] +}