Skip to content

Commit 5d5004f

Browse files
pks-tgitster
authored andcommitted
meson: wire up generation of distribution archive
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 04eb281 commit 5d5004f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

GIT-VERSION-GEN

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ then
1919
exit 1
2020
fi
2121

22+
if test -n "$OUTPUT" && test -n "$MESON_DIST_ROOT"
23+
then
24+
OUTPUT="$MESON_DIST_ROOT/$OUTPUT"
25+
fi
26+
2227
DEF_VER=$(cat "$SOURCE_DIR"/GIT-VERSION)
2328

2429
# Protect us from reading Git version information outside of the Git directory
@@ -33,7 +38,7 @@ then
3338
# then try git-describe, then default.
3439
if test -f "$SOURCE_DIR"/version
3540
then
36-
VN=$(cat "$SOURCE_DIR"/version) || VN="$DEF_VER"
41+
VN=$(cat "$SOURCE_DIR"/version) && VN=${VN#GIT_VERSION=} || VN="$DEF_VER"
3742
elif {
3843
test -d "$SOURCE_DIR/.git" ||
3944
test -d "${GIT_DIR:-.git}" ||

meson.build

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,6 +1944,18 @@ devenv.set('GIT_BUILD_DIR', meson.current_build_dir())
19441944
devenv.prepend('PATH', meson.current_build_dir() / 'bin-wrappers')
19451945
meson.add_devenv(devenv)
19461946

1947+
# Generate the 'version' file in the distribution tarball. This is used via
1948+
# `meson dist -C <builddir>` to populate the source archive with the Git
1949+
# version that the archive is being generated from. GIT-VERSION-GEN knows to
1950+
# pick up this file.
1951+
meson.add_dist_script(
1952+
shell,
1953+
meson.current_source_dir() / 'GIT-VERSION-GEN',
1954+
meson.current_source_dir(),
1955+
meson.current_source_dir() / 'GIT-VERSION-FILE.in',
1956+
'version',
1957+
)
1958+
19471959
summary({
19481960
'curl': curl.found(),
19491961
'expat': expat.found(),

0 commit comments

Comments
 (0)