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

[PATCH v3 6/6] meson: add options to override build information

From
Patrick Steinhardt <ps@pks.im>
Date
Dec 20, 2024, 19:44 UTC
Message-ID
<20241220-b4-pks-git-version-via-environment-v3-6-1fd79b52a5fb@pks.im>
In-Reply-To
<20241220-b4-pks-git-version-via-environment-v3-0-1fd79b52a5fb@pks.im>

We inject various different kinds of build information into build artifacts, like the version string or the commit from which Git was built. Add options to let users explicitly override this information with Meson.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 Documentation/meson.build |  1 +
 meson.build               | 13 +++++++++++++
 meson_options.txt         | 10 ++++++++++
 3 files changed, 24 insertions(+)
diff --git a/Documentation/meson.build b/Documentation/meson.build
index f2426ccaa30c29bd60b850eb0a9a4ab77c66a629..fca3eab1f1360a5fdeda89c1766ab8cdb3267b89 100644
--- a/Documentation/meson.build
+++ b/Documentation/meson.build
@@ -219,6 +219,7 @@ asciidoc_conf = custom_target(
   input: meson.current_source_dir() / 'asciidoc.conf.in',
   output: 'asciidoc.conf',
   depends: [git_version_file],
+  env: version_gen_environment,
 )
 
 asciidoc_common_options = [
diff --git a/meson.build b/meson.build
index 0dccebcdf16b07650d943e53643f0e09e2975cc9..be32d60e841a3055ed2bdf6fd449a48b66d94cd0 100644
--- a/meson.build
+++ b/meson.build
@@ -201,6 +201,16 @@ if get_option('sane_tool_path') != ''
   script_environment.prepend('PATH', get_option('sane_tool_path'))
 endif
 
+# The environment used by GIT-VERSION-GEN. Note that we explicitly override
+# environment variables that might be set by the user. This is by design so
+# that we always use whatever Meson has configured instead of what is present
+# in the environment.
+version_gen_environment = script_environment
+version_gen_environment.set('GIT_BUILT_FROM_COMMIT', get_option('built_from_commit'))
+version_gen_environment.set('GIT_DATE', get_option('build_date'))
+version_gen_environment.set('GIT_USER_AGENT', get_option('user_agent'))
+version_gen_environment.set('GIT_VERSION', get_option('version'))
+
 compiler = meson.get_compiler('c')
 
 libgit_sources = [
@@ -1485,6 +1495,7 @@ git_version_file = custom_target(
   ],
   input: meson.current_source_dir() / 'GIT-VERSION-FILE.in',
   output: 'GIT-VERSION-FILE',
+  env: version_gen_environment,
   build_always_stale: true,
 )
 
@@ -1501,6 +1512,7 @@ version_def_h = custom_target(
   # Depend on GIT-VERSION-FILE so that we don't always try to rebuild this
   # target for the same commit.
   depends: [git_version_file],
+  env: version_gen_environment,
 )
 
 # Build a separate library for "version.c" so that we do not have to rebuild
@@ -1544,6 +1556,7 @@ if host_machine.system() == 'windows'
     input: meson.current_source_dir() / 'git.rc.in',
     output: 'git.rc',
     depends: [git_version_file],
+    env: version_gen_environment,
   )
 
   common_main_sources += import('windows').compile_resources(git_rc,
diff --git a/meson_options.txt b/meson_options.txt
index 32a72139bae870745d9131cc9086a4594826be91..8ead1349550807420bdb95e55298ea4f3f2ea9d0 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -16,6 +16,16 @@ option('runtime_prefix', type: 'boolean', value: false,
 option('sane_tool_path', type: 'string', value: '',
   description: 'A colon-separated list of paths to prepend to PATH if your tools in /usr/bin are broken.')
 
+# Build information compiled into Git and other parts like documentation.
+option('build_date', type: 'string', value: '',
+  description: 'Build date reported by our documentation.')
+option('built_from_commit', type: 'string', value: '',
+  description: 'Commit that Git was built from reported by git-version(1).')
+option('user_agent', type: 'string', value: '',
+  description: 'User agent reported to remote servers.')
+option('version', type: 'string', value: '',
+  description: 'Version string reported by git-version(1) and other tools.')
+
 # Features supported by Git.
 option('curl', type: 'feature', value: 'enabled',
   description: 'Build helpers used to access remotes with the HTTP transport.')
-- 
2.48.0.rc0.184.g0fc57dec57.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 43 of 44 in “GIT-VERSION-GEN: fix overriding values”
  1. 0/2 GIT-VERSION-GEN: fix overriding valuesPatrick Steinhardt, Dec 19, 2024
  2. 2/2 GIT-VERSION-GEN: fix overriding GIT_BUILT_FROM_COMMIT and GIT_DATEPatrick Steinhardt, Dec 19, 2024
  3. Kyle LippincottDec 19, 2024
  4. Junio C HamanoDec 19, 2024
  5. Jeff KingDec 20, 2024
  6. Junio C HamanoDec 20, 2024
  7. 1/2 GIT-VERSION-GEN: fix overriding version via environmentPatrick Steinhardt, Dec 19, 2024
  8. Junio C HamanoDec 19, 2024
  9. Jeff KingDec 20, 2024
  10. Patrick SteinhardtDec 20, 2024
  11. Jeff KingDec 20, 2024
  12. Patrick SteinhardtDec 20, 2024
  13. Jeff KingDec 20, 2024
  14. Patrick SteinhardtDec 20, 2024
  15. 0/5 GIT-VERSION-GEN: fix overriding valuesPatrick Steinhardt, Dec 20, 2024
  16. 1/5 GIT-VERSION-GEN: fix overriding version via environmentPatrick Steinhardt, Dec 20, 2024
  17. Jeff KingDec 20, 2024
  18. Junio C HamanoDec 20, 2024
  19. Patrick SteinhardtDec 20, 2024
  20. Patrick SteinhardtDec 20, 2024
  21. 2/5 GIT-VERSION-GEN: fix overriding GIT_BUILT_FROM_COMMIT and GIT_DATEPatrick Steinhardt, Dec 20, 2024
  22. 3/5 Makefile: drop unneeded indirection for GIT-VERSION-GEN outputsPatrick Steinhardt, Dec 20, 2024
  23. Jeff KingDec 20, 2024
  24. 4/5 Makefile: respect build info declared in "config.mak"Patrick Steinhardt, Dec 20, 2024
  25. Jeff KingDec 20, 2024
  26. Patrick SteinhardtDec 20, 2024
  27. Jeff KingDec 20, 2024
  28. Patrick SteinhardtDec 20, 2024
  29. Patrick SteinhardtDec 20, 2024
  30. Jeff KingDec 20, 2024
  31. Patrick SteinhardtDec 20, 2024
  32. Patrick SteinhardtDec 20, 2024
  33. Jeff KingDec 28, 2024
  34. 5/5 meson: add options to override build informationPatrick Steinhardt, Dec 20, 2024
  35. Jeff KingDec 20, 2024
  36. 0/6 GIT-VERSION-GEN: fix overriding valuesPatrick Steinhardt, Dec 20, 2024
  37. 1/6 Makefile: stop including "GIT-VERSION-FILE" in docsPatrick Steinhardt, Dec 20, 2024
  38. 2/6 Makefile: drop unneeded indirection for GIT-VERSION-GEN outputsPatrick Steinhardt, Dec 20, 2024
  39. 3/6 Makefile: introduce template for GIT-VERSION-GENPatrick Steinhardt, Dec 20, 2024
  40. 4/6 GIT-VERSION-GEN: fix overriding GIT_VERSIONPatrick Steinhardt, Dec 20, 2024
  41. Junio C HamanoDec 20, 2024
  42. Patrick SteinhardtDec 21, 2024
  43. 6/6 meson: add options to override build informationPatrick Steinhardt, Dec 20, 2024
  44. 5/6 GIT-VERSION-GEN: fix overriding GIT_BUILT_FROM_COMMIT and GIT_DATEPatrick Steinhardt, Dec 20, 2024

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.