All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] meson: generate qemu-version.h with a custom target
@ 2026-11-05 18:14 Yonggang Luo
  2026-11-05 18:34 ` Peter Maydell
  0 siblings, 1 reply; 5+ messages in thread
From: Yonggang Luo @ 2026-11-05 18:14 UTC (permalink / raw)
  To: qemu-devel
  Cc: Cleber Rosa, Paolo Bonzini, Daniel P. Berrangé,
	Pierrick Bouvier, John Snow, Marc-André Lureau,
	Philippe Mathieu-Daude

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/CAFEAcA8bGODxRfRzrimhGN1v2HtcWvApRsyucemZbMUUBVkYwA@mail.gmail.com/

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 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



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-06  8:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-05 18:14 [PATCH] meson: generate qemu-version.h with a custom target Yonggang Luo
2026-11-05 18:34 ` Peter Maydell
2026-11-05 18:39   ` Yonggang Luo
2026-11-06  8:19   ` Daniel P. Berrangé
2026-11-06  8:42     ` Yonggang Luo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.