git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 03/11] meson: populate project version via GIT-VERSION-GEN

From
Patrick Steinhardt <ps@pks.im>
Date
Jan 14, 2025, 11:56 UTC
Message-ID
<20250114-b4-pks-meson-additions-v2-3-8d7ec676cfd9@pks.im>
In-Reply-To
<20250114-b4-pks-meson-additions-v2-0-8d7ec676cfd9@pks.im>

The Git version for Meson is currently wired up manually. It can thus grow (and alread has grown) stale quite easily, as having multiple sources of truth is never a good idea. This issue is mostly of cosmetic nature as we don't use the project version anywhere, and instead use the GIT-VERSION-GEN script to propagate the correct version into our build. But it is somewhat puzzling when `meson setup` announces to build an old Git release.

There are a couple of alternatives for how to solve this:
  - We can keep the version undefined, but this makes Meson output
    "undefined" for the version, as well.
  - We can use GIT-VERSION-GEN to generate the version for us. At the
    point of configuring the project we haven't yet figured out host
    details though, and thus we didn't yet set up the shell environment.
    While not an issue for Unix-based systems, this would be an issue in
    Windows, where the shell typically gets provided via Git for Windows
    and thus requires some special setup.
  - We can pull the default version out of GIT-VERSION-GEN and move it
    into its own file. This likely requires some adjustments for scripts
    that bump the version, but allows Meson to read the version from
    that file trivially.

Pick the second option and use GIT-VERSION-GEN as it gives us the most accurate version. In order to fix the bootstrapping issue on Windows systems we simply set the version to 'unknown' in case no shell was found. As the version is only of cosmetic value this isn't really much of an issue.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 meson.build | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/meson.build b/meson.build
index 7361eb2eaad422e7a6c6ed95d275615836c21cdb..213998986e8942cee080fc5b9b675860cf429ecc 100644
--- a/meson.build
+++ b/meson.build
@@ -170,7 +170,14 @@
 
 project('git', 'c',
   meson_version: '>=0.61.0',
-  version: 'v2.47.GIT',
+  # The version is only of cosmetic nature, so if we cannot find a shell yet we
+  # simply don't set up a version at all. This may be the case for example on
+  # Windows systems, where we first have to bootstrap the host environment.
+  version: find_program('sh', required: false).found() ? run_command(
+    'GIT-VERSION-GEN', meson.current_source_dir(), '--format=@GIT_VERSION@',
+    capture: true,
+    check: true,
+  ).stdout().strip() : 'unknown',
 )
 
 fs = import('fs')
-- 
2.48.0.257.gd3603152ad.dirty
Previous: Toon ClaesNext: Toon Claes
Message 5 of 18 in “meson: a couple of additions”
  1. 00/11 meson: a couple of additionsPatrick Steinhardt, Jan 14, 2025
  2. 01/11 GIT-VERSION-GEN: simplify computing the dirty markerPatrick Steinhardt, Jan 14, 2025
  3. 02/11 GIT-VERSION-GEN: allow running without input and output filesPatrick Steinhardt, Jan 14, 2025
  4. Toon ClaesJan 21, 2025
  5. 03/11 meson: populate project version via GIT-VERSION-GENPatrick Steinhardt, Jan 14, 2025
  6. Toon ClaesJan 21, 2025
  7. 04/11 meson: fix dependencies for generated headersPatrick Steinhardt, Jan 14, 2025
  8. 05/11 meson: wire up development environmentsPatrick Steinhardt, Jan 14, 2025
  9. 06/11 meson: wire up generation of distribution archivePatrick Steinhardt, Jan 14, 2025
  10. Toon ClaesJan 21, 2025
  11. Patrick SteinhardtJan 22, 2025
  12. 07/11 meson: wire up fuzzersPatrick Steinhardt, Jan 14, 2025
  13. 08/11 meson: make the CSPRNG backend configurablePatrick Steinhardt, Jan 14, 2025
  14. 09/11 meson: fix compilation with Visual StudioPatrick Steinhardt, Jan 14, 2025
  15. 10/11 ci: raise error when Meson generates warningsPatrick Steinhardt, Jan 14, 2025
  16. Toon ClaesJan 21, 2025
  17. 11/11 ci: wire up Visual Studio build with MesonPatrick Steinhardt, Jan 14, 2025
  18. Junio C HamanoJan 14, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.