configure_file() writes qemu-version.h at setup time. That result is not a ninja edge, so a missing header is never rebuilt and compiles that include it do not order on it. Generate the header with custom_target and list it in genh. scripts/qemu-version.py reads scripts/qemu-version.h.in and substitutes -version. An empty pkgversion drops the QEMU_PKGVERSION line.
Link: https://lore.kernel.org/qemu-devel/cafeaca8bgodxrfrzrimhgn1v2htcwvaprsyucemzbmuubvk...@mail.gmail.com/ Signed-off-by: Yonggang Luo <[email protected]> --- meson.build | 14 +++++++++----- scripts/qemu-version.py | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 scripts/qemu-version.py diff --git a/meson.build b/meson.build index d7bcb581c1..78cbc91296 100644 --- a/meson.build +++ b/meson.build @@ -3574,11 +3574,15 @@ else # Unlike vcs_tag(), which always defines QEMU_PKGVERSION, leave it out if # empty. include/qemu/version.h then omits the parentheses from # QEMU_FULL_VERSION. - qemu_version_data = configuration_data() - if qemu_pkgversion != '' - qemu_version_data.set_quoted('QEMU_PKGVERSION', qemu_pkgversion) - endif - qemu_version = configure_file(output: 'qemu-version.h', configuration: qemu_version_data) + # custom_target is a genh source, so consumers order on qemu-version.h + # and ninja recreates it when the template or pkgversion changes. + qemu_version = custom_target( + 'qemu-version.h', + input: files('scripts/qemu-version.h.in'), + output: 'qemu-version.h', + capture: true, + command: [python, files('scripts/qemu-version.py'), + '-version', qemu_pkgversion, '@INPUT@']) endif genh += qemu_version diff --git a/scripts/qemu-version.py b/scripts/qemu-version.py new file mode 100644 index 0000000000..a10cc5e03c --- /dev/null +++ b/scripts/qemu-version.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-or-later + +# Usage: scripts/qemu-version.py -version PKGVERSION INPUT +# @VCS_TAG@ in INPUT is replaced with PKGVERSION. An empty PKGVERSION +# drops that line. + +import argparse +import sys + +parser = argparse.ArgumentParser() +parser.add_argument('-version', default='') +parser.add_argument('input') +args = parser.parse_args() + +version = args.version +with open(args.input, 'rb') as template_file: + template = template_file.read() +if version: + version = version.replace('\\', '\\\\').replace('"', '\\"') + template = template.replace(b'@VCS_TAG@', version.encode('utf-8')) + sys.stdout.buffer.write(template) +else: + kept = [line for line in template.splitlines(True) + if b'@VCS_TAG@' not in line] + sys.stdout.buffer.write(b''.join(kept) if kept else b'\n') -- 2.55.0.windows.3
