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

* Re: [PATCH] meson: generate qemu-version.h with a custom target
  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é
  0 siblings, 2 replies; 5+ messages in thread
From: Peter Maydell @ 2026-11-05 18:34 UTC (permalink / raw)
  To: Yonggang Luo
  Cc: qemu-devel, Cleber Rosa, Paolo Bonzini, Daniel P. Berrangé,
	Pierrick Bouvier, John Snow, Marc-André Lureau,
	Philippe Mathieu-Daude

On Thu, 5 Nov 2026 at 18:15, Yonggang Luo <luoyonggang@gmail.com> wrote:
>
> 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>

If we're going back to having an external script, the other
way to fix this would be to just revert ab78ac76f44a12 and
maybe fc35f2438770, since their commit messages suggest the
main aim was to not have an external script.

thanks
-- PMM


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

* Re: [PATCH] meson: generate qemu-version.h with a custom target
  2026-11-05 18:34 ` Peter Maydell
@ 2026-11-05 18:39   ` Yonggang Luo
  2026-11-06  8:19   ` Daniel P. Berrangé
  1 sibling, 0 replies; 5+ messages in thread
From: Yonggang Luo @ 2026-11-05 18:39 UTC (permalink / raw)
  To: Peter Maydell
  Cc: qemu-devel, Cleber Rosa, Paolo Bonzini, Daniel P. Berrangé,
	Pierrick Bouvier, John Snow, Marc-André Lureau,
	Philippe Mathieu-Daude

On Fri, Nov 6, 2026 at 2:34 AM Peter Maydell <peter.maydell@linaro.org> wrote:
>
> On Thu, 5 Nov 2026 at 18:15, Yonggang Luo <luoyonggang@gmail.com> wrote:
> >
> > 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>
>
> If we're going back to having an external script, the other
> way to fix this would be to just revert ab78ac76f44a12 and
> maybe fc35f2438770, since their commit messages suggest the
> main aim was to not have an external script.

I personally think the external script(not have) is mainly about when
git presents.
That's the most used case for developers maybe. And we always need to
calling to git when .git and git present, that's the case we always need
dealt with.

And if we call git executable in an external script, it's far more
complicated to
handle. Either a complicated python script or a not-wanted bash script.

>
> thanks
> -- PMM



-- 
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo


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

* Re: [PATCH] meson: generate qemu-version.h with a custom target
  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
  1 sibling, 1 reply; 5+ messages in thread
From: Daniel P. Berrangé @ 2026-11-06  8:19 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Yonggang Luo, qemu-devel, Cleber Rosa, Paolo Bonzini,
	Pierrick Bouvier, John Snow, Marc-André Lureau,
	Philippe Mathieu-Daude

On Thu, Nov 05, 2026 at 06:34:31PM +0000, Peter Maydell wrote:
> On Thu, 5 Nov 2026 at 18:15, Yonggang Luo <luoyonggang@gmail.com> wrote:
> >
> > 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>
> 
> If we're going back to having an external script, the other
> way to fix this would be to just revert ab78ac76f44a12 and
> maybe fc35f2438770, since their commit messages suggest the
> main aim was to not have an external script.

I'm not clear what problem there was with an external script that these
were solving ? These also seem to have appeared in a pull request
without any prior posting for review, which is rather shortcutting our
normal dev process.

Personally I'd suggest we revert and then simplify the version handling
in a different way:

 * Remove the VERSION file and put the number in meson.build directly
 * Emit QEMU_PKGVERSION into build/config-host.h
 * Remove qemu/version.h and build/qemu-version.h

This avoids any need for rules to generate build/qemu-version.h
and config-host.h already has logic to regenerate itself when
meson.build changes.

With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|



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

* Re: [PATCH] meson: generate qemu-version.h with a custom target
  2026-11-06  8:19   ` Daniel P. Berrangé
@ 2026-11-06  8:42     ` Yonggang Luo
  0 siblings, 0 replies; 5+ messages in thread
From: Yonggang Luo @ 2026-11-06  8:42 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Peter Maydell, qemu-devel, Cleber Rosa, Paolo Bonzini,
	Pierrick Bouvier, John Snow, Marc-André Lureau,
	Philippe Mathieu-Daude

On Fri, Nov 6, 2026 at 4:19 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> On Thu, Nov 05, 2026 at 06:34:31PM +0000, Peter Maydell wrote:
> > On Thu, 5 Nov 2026 at 18:15, Yonggang Luo <luoyonggang@gmail.com> wrote:
> > >
> > > 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>
> >
> > If we're going back to having an external script, the other
> > way to fix this would be to just revert ab78ac76f44a12 and
> > maybe fc35f2438770, since their commit messages suggest the
> > main aim was to not have an external script.
>
> I'm not clear what problem there was with an external script that these
> were solving ? These also seem to have appeared in a pull request
> without any prior posting for review, which is rather shortcutting our
> normal dev process.
>
> Personally I'd suggest we revert and then simplify the version handling
> in a different way:
>
>  * Remove the VERSION file and put the number in meson.build directly
>  * Emit QEMU_PKGVERSION into build/config-host.h
>  * Remove qemu/version.h and build/qemu-version.h

Oh, yeah, we already have config-host.h good idea.
Seems better, so we just revert the previous commits? and goes this way?
Still have an issue, how to deal with the git version? because that's much more
dynamic. Reset to different git versions does not mean we need to re-configure.
So that when the git version changes, we have no need to reconfigure it at all.

>
> This avoids any need for rules to generate build/qemu-version.h
> and config-host.h already has logic to regenerate itself when
> meson.build changes.
>
> With regards,
> Daniel
> --
> |: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
> |: https://libvirt.org          ~~          https://entangle-photo.org :|
> |: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
>


-- 
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo


^ permalink raw reply	[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.