meson: add options to override build information

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Dec 20, 2024 at 20:44 UTC 1bc815c3d0eff054c7a032130206d16839bb331a
3 files changed +24
Documentation/meson.build
+1
@@ -219,6 +219,7 @@ asciidoc_conf = custom_target(
219 input: meson.current_source_dir() / 'asciidoc.conf.in',
220 output: 'asciidoc.conf',
221 depends: [git_version_file],
222 + env: version_gen_environment,
223 )
224
225 asciidoc_common_options = [
meson.build
+13
@@ -201,6 +201,16 @@ if get_option('sane_tool_path') != ''
201 script_environment.prepend('PATH', get_option('sane_tool_path'))
202 endif
203
204 +# The environment used by GIT-VERSION-GEN. Note that we explicitly override
205 +# environment variables that might be set by the user. This is by design so
206 +# that we always use whatever Meson has configured instead of what is present
207 +# in the environment.
208 +version_gen_environment = script_environment
209 +version_gen_environment.set('GIT_BUILT_FROM_COMMIT', get_option('built_from_commit'))
210 +version_gen_environment.set('GIT_DATE', get_option('build_date'))
211 +version_gen_environment.set('GIT_USER_AGENT', get_option('user_agent'))
212 +version_gen_environment.set('GIT_VERSION', get_option('version'))
213 +
214 compiler = meson.get_compiler('c')
215
216 libgit_sources = [
@@ -1485,6 +1495,7 @@ git_version_file = custom_target(
1495 ],
1496 input: meson.current_source_dir() / 'GIT-VERSION-FILE.in',
1497 output: 'GIT-VERSION-FILE',
1498 + env: version_gen_environment,
1499 build_always_stale: true,
1500 )
1501
@@ -1501,6 +1512,7 @@ version_def_h = custom_target(
1512 # Depend on GIT-VERSION-FILE so that we don't always try to rebuild this
1513 # target for the same commit.
1514 depends: [git_version_file],
1515 + env: version_gen_environment,
1516 )
1517
1518 # Build a separate library for "version.c" so that we do not have to rebuild
@@ -1544,6 +1556,7 @@ if host_machine.system() == 'windows'
1556 input: meson.current_source_dir() / 'git.rc.in',
1557 output: 'git.rc',
1558 depends: [git_version_file],
1559 + env: version_gen_environment,
1560 )
1561
1562 common_main_sources += import('windows').compile_resources(git_rc,
meson_options.txt
+10
@@ -16,6 +16,16 @@ option('runtime_prefix', type: 'boolean', value: false,
16 option('sane_tool_path', type: 'string', value: '',
17 description: 'A colon-separated list of paths to prepend to PATH if your tools in /usr/bin are broken.')
18
19 +# Build information compiled into Git and other parts like documentation.
20 +option('build_date', type: 'string', value: '',
21 + description: 'Build date reported by our documentation.')
22 +option('built_from_commit', type: 'string', value: '',
23 + description: 'Commit that Git was built from reported by git-version(1).')
24 +option('user_agent', type: 'string', value: '',
25 + description: 'User agent reported to remote servers.')
26 +option('version', type: 'string', value: '',
27 + description: 'Version string reported by git-version(1) and other tools.')
28 +
29 # Features supported by Git.
30 option('curl', type: 'feature', value: 'enabled',
31 description: 'Build helpers used to access remotes with the HTTP transport.')