meson: generate version tag from git

$ build/systemctl --version
systemd 239-3555-g6178cbb5b5
+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN +PCRE2 default-hierarchy=hybrid
$ git tag v240 -m 'v240'
$ ninja -C build
ninja: Entering directory `build'
[76/76] Linking target fuzz-unit-file.
$ build/systemctl --version
systemd 240
+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN +PCRE2 default-hierarchy=hybrid

This is very useful during development, because a precise version string is
embedded in the build product and displayed during boot, so we don't have to
guess answers for questions like "did I just boot the latest version or the one
from before?".

This change creates an overhead for "noop" builds. On my laptop, 'ninja -C
build' that does nothing goes from 0.1 to 0.5 s. It would be nice to avoid
this, but I think that <1 s is still acceptable.

Fixes #7183.

PACKAGE_VERSION is renamed to GIT_VERSION, to make it obvious that this is the
more dynamically changing version string.

Why save to a file? It would be easy to generate the version tag using
run_command(), but we want to go through a file so that stuff gets rebuilt when
this file changes. If we just defined an variable in meson, ninja wouldn't know
it needs to rebuild things.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2018-12-20 20:35:25 +01:00
parent b9da6a098b
commit 681bd2c524
19 changed files with 51 additions and 22 deletions

View File

@@ -1,6 +1,8 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once
#include "version.h"
#if HAVE_PAM
#define _PAM_FEATURE_ "+PAM"
#else

View File

@@ -1,5 +1,10 @@
# SPDX-License-Identifier: LGPL-2.1+
version_h = vcs_tag(
command: vcs_tagger,
input : 'version.h.in',
output : 'version.h')
basic_sources = files('''
MurmurHash2.c
MurmurHash2.h

View File

@@ -557,7 +557,7 @@ uint64_t system_tasks_max_scale(uint64_t v, uint64_t max) {
}
int version(void) {
puts("systemd " PACKAGE_VERSION "\n"
puts("systemd " GIT_VERSION "\n"
SYSTEMD_FEATURES);
return 0;
}

1
src/basic/version.h.in Normal file
View File

@@ -0,0 +1 @@
#define GIT_VERSION "@VCS_TAG@"