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

[PATCH 5/9] meson: wire up generation of distribution archive

From
Patrick Steinhardt <ps@pks.im>
Date
Jan 13, 2025, 08:33 UTC
Message-ID
<20250113-b4-pks-meson-additions-v1-5-97f6a93f691d@pks.im>
In-Reply-To
<20250113-b4-pks-meson-additions-v1-0-97f6a93f691d@pks.im>

Meson knows to generate distribution archives via `meson dist`. Despite generating the archive itself, this target also knows to compile and execute tests from that archive, which helps to ensure that the result is an adequate drop-in replacement for the versioned project.

While this already works as-is, one omission is that we don't propagate the commit that this is built from into the resulting archive. This can be fixed though by adding a distribution script that propagates the version into the "version" file, which GIT-VERSION-GEN knows to read if present.

Use GIT-VERSION-GEN itself to populate that file. There are two smallish gotchas:

  - The script is executed in the build directory, not in the directory
    where we generate the archive. The target directory is propagated
    via the "MESON_DIST_ROOT" environment variable, but because we don't
    use a shell to execute GIT-VERSION-GEN we cannot populate the envvar
    into its arguments. We thus adapt GIT-VERSION-GEN to handle this for
    us.
  - We use the "GIT-VERSION-FILE.in" template to generate the version,
    which contains a "GIT_VERSION=" prefix that we need to strip after
    reading the "version" file. We could avoid this extra logic if we
    used a template that only had the `@GIT_VERSION@` placeholder, but
    it would require us to add one more template file.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 GIT-VERSION-GEN |  7 ++++++-
 meson.build     | 12 ++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 95d7d41d233450774a6580c0de332e7b8f69eb4e..1f0fb4098da392511f02a34cdcc84f3889771001 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -19,6 +19,11 @@ then
 	exit 1
 fi
 
+if test -n "$OUTPUT" && test -n "$MESON_DIST_ROOT"
+then
+    OUTPUT="$MESON_DIST_ROOT/$OUTPUT"
+fi
+
 DEF_VER=$(cat "$SOURCE_DIR"/GIT-VERSION)
 
 # Protect us from reading Git version information outside of the Git directory
@@ -33,7 +38,7 @@ then
 	# then try git-describe, then default.
 	if test -f "$SOURCE_DIR"/version
 	then
-		VN=$(cat "$SOURCE_DIR"/version) || VN="$DEF_VER"
+		VN=$(cat "$SOURCE_DIR"/version) && VN=${VN#GIT_VERSION=} || VN="$DEF_VER"
 	elif {
 			test -d "$SOURCE_DIR/.git" ||
 			test -d "${GIT_DIR:-.git}" ||
diff --git a/meson.build b/meson.build
index 0b559215e4f105ac87bd580d755f88c32b7b36ca..771bdded484a0c0e8638e7c6555e3f4e09e64025 100644
--- a/meson.build
+++ b/meson.build
@@ -1940,6 +1940,18 @@ devenv.set('GIT_BUILD_DIR', meson.current_build_dir())
 devenv.prepend('PATH', meson.current_build_dir() / 'bin-wrappers')
 meson.add_devenv(devenv)
 
+# Generate the 'version' file in the distribution tarball. This is used via
+# `meson dist -C <builddir>` to populate the source archive with the Git
+# version that the archive is being generated from. GIT-VERSION-GEN knows to
+# pick up this file.
+meson.add_dist_script(
+  shell,
+  meson.current_source_dir() / 'GIT-VERSION-GEN',
+  meson.current_source_dir(),
+  meson.current_source_dir() / 'GIT-VERSION-FILE.in',
+  'version',
+)
+
 summary({
   'curl': curl.found(),
   'expat': expat.found(),
-- 
2.48.0.257.gd3603152ad.dirty
Previous: Patrick SteinhardtNext: Junio C Hamano
Message 12 of 35 in “meson: a couple of additions”
  1. 0/9 meson: a couple of additionsPatrick Steinhardt, Jan 13, 2025
  2. 1/9 GIT-VERSION-GEN: simplify computing the dirty markerPatrick Steinhardt, Jan 13, 2025
  3. 2/9 GIT-VERSION-GEN: move default version into a separate filePatrick Steinhardt, Jan 13, 2025
  4. Junio C HamanoJan 13, 2025
  5. Eli SchwartzJan 13, 2025
  6. Patrick SteinhardtJan 14, 2025
  7. 3/9 meson: fix dependencies for generated headersPatrick Steinhardt, Jan 13, 2025
  8. 4/9 meson: wire up development environmentsPatrick Steinhardt, Jan 13, 2025
  9. 6/9 meson: wire up fuzzersPatrick Steinhardt, Jan 13, 2025
  10. Junio C HamanoJan 13, 2025
  11. Patrick SteinhardtJan 14, 2025
  12. 5/9 meson: wire up generation of distribution archivePatrick Steinhardt, Jan 13, 2025
  13. Junio C HamanoJan 13, 2025
  14. Patrick SteinhardtJan 14, 2025
  15. 7/9 meson: make the CSPRNG backend configurablePatrick Steinhardt, Jan 13, 2025
  16. Patrick SteinhardtJan 13, 2025
  17. Junio C HamanoJan 13, 2025
  18. Patrick SteinhardtJan 14, 2025
  19. Junio C HamanoJan 14, 2025
  20. 8/9 meson: fix compilation with Visual StudioPatrick Steinhardt, Jan 13, 2025
  21. M HickfordJan 13, 2025
  22. 9/9 ci: wire up Visual Studio build with MesonPatrick Steinhardt, Jan 13, 2025
  23. 00/11 meson: a couple of additionsPatrick Steinhardt, Jan 22, 2025
  24. 01/11 GIT-VERSION-GEN: simplify computing the dirty markerPatrick Steinhardt, Jan 22, 2025
  25. 02/11 GIT-VERSION-GEN: allow running without input and output filesPatrick Steinhardt, Jan 22, 2025
  26. 03/11 meson: populate project version via GIT-VERSION-GENPatrick Steinhardt, Jan 22, 2025
  27. 04/11 meson: fix dependencies for generated headersPatrick Steinhardt, Jan 22, 2025
  28. 05/11 meson: wire up development environmentsPatrick Steinhardt, Jan 22, 2025
  29. 06/11 meson: wire up generation of distribution archivePatrick Steinhardt, Jan 22, 2025
  30. 07/11 meson: wire up fuzzersPatrick Steinhardt, Jan 22, 2025
  31. 08/11 meson: make the CSPRNG backend configurablePatrick Steinhardt, Jan 22, 2025
  32. 09/11 meson: fix compilation with Visual StudioPatrick Steinhardt, Jan 22, 2025
  33. 10/11 ci: raise error when Meson generates warningsPatrick Steinhardt, Jan 22, 2025
  34. 11/11 ci: wire up Visual Studio build with MesonPatrick Steinhardt, Jan 22, 2025
  35. Junio C HamanoJan 22, 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.