Skip to content

Commit 6ff9917

Browse files
pks-tgitster
authored andcommitted
meson: populate project version via GIT-VERSION-GEN
The Git version for Meson is currently wired up manually. It can thus grow (and already 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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f6a2efd commit 6ff9917

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

meson.build

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,14 @@
170170

171171
project('git', 'c',
172172
meson_version: '>=0.61.0',
173-
version: 'v2.47.GIT',
173+
# The version is only of cosmetic nature, so if we cannot find a shell yet we
174+
# simply don't set up a version at all. This may be the case for example on
175+
# Windows systems, where we first have to bootstrap the host environment.
176+
version: find_program('sh', required: false).found() ? run_command(
177+
'GIT-VERSION-GEN', meson.current_source_dir(), '--format=@GIT_VERSION@',
178+
capture: true,
179+
check: true,
180+
).stdout().strip() : 'unknown',
174181
)
175182

176183
fs = import('fs')

0 commit comments

Comments
 (0)