Skip to content

Commit 1bc815c

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cfa01e6 commit 1bc815c

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

Documentation/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ asciidoc_conf = custom_target(
219219
input: meson.current_source_dir() / 'asciidoc.conf.in',
220220
output: 'asciidoc.conf',
221221
depends: [git_version_file],
222+
env: version_gen_environment,
222223
)
223224

224225
asciidoc_common_options = [

meson.build

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,16 @@ if get_option('sane_tool_path') != ''
201201
script_environment.prepend('PATH', get_option('sane_tool_path'))
202202
endif
203203

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+
204214
compiler = meson.get_compiler('c')
205215

206216
libgit_sources = [
@@ -1485,6 +1495,7 @@ git_version_file = custom_target(
14851495
],
14861496
input: meson.current_source_dir() / 'GIT-VERSION-FILE.in',
14871497
output: 'GIT-VERSION-FILE',
1498+
env: version_gen_environment,
14881499
build_always_stale: true,
14891500
)
14901501

@@ -1501,6 +1512,7 @@ version_def_h = custom_target(
15011512
# Depend on GIT-VERSION-FILE so that we don't always try to rebuild this
15021513
# target for the same commit.
15031514
depends: [git_version_file],
1515+
env: version_gen_environment,
15041516
)
15051517

15061518
# Build a separate library for "version.c" so that we do not have to rebuild
@@ -1544,6 +1556,7 @@ if host_machine.system() == 'windows'
15441556
input: meson.current_source_dir() / 'git.rc.in',
15451557
output: 'git.rc',
15461558
depends: [git_version_file],
1559+
env: version_gen_environment,
15471560
)
15481561

15491562
common_main_sources += import('windows').compile_resources(git_rc,

meson_options.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ option('runtime_prefix', type: 'boolean', value: false,
1616
option('sane_tool_path', type: 'string', value: '',
1717
description: 'A colon-separated list of paths to prepend to PATH if your tools in /usr/bin are broken.')
1818

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+
1929
# Features supported by Git.
2030
option('curl', type: 'feature', value: 'enabled',
2131
description: 'Build helpers used to access remotes with the HTTP transport.')

0 commit comments

Comments
 (0)