From 681bd2c524ed71ac04045c90884ba8d55eee7b66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 20 Dec 2018 20:35:25 +0100 Subject: [PATCH] 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. --- meson.build | 5 ++++- src/analyze/analyze.c | 3 ++- src/basic/build.h | 2 ++ src/basic/meson.build | 5 +++++ src/basic/util.c | 2 +- src/basic/version.h.in | 1 + src/boot/efi/boot.c | 8 ++++---- src/boot/efi/meson.build | 4 ++-- src/boot/efi/stub.c | 4 ++-- src/core/dbus-manager.c | 2 +- src/core/main.c | 4 ++-- src/import/curl-util.c | 3 ++- src/journal-remote/journal-upload.c | 3 ++- src/test/test-libudev.c | 3 ++- src/test/test-udev.c | 3 ++- src/udev/scsi_id/scsi_id.c | 3 ++- src/udev/udevadm.h | 4 +++- src/udev/udevd.c | 5 +++-- tools/meson-vcs-tag.sh | 9 +++++++++ 19 files changed, 51 insertions(+), 22 deletions(-) create mode 100644 src/basic/version.h.in create mode 100755 tools/meson-vcs-tag.sh diff --git a/meson.build b/meson.build index 7816ba9949..100265570d 100644 --- a/meson.build +++ b/meson.build @@ -21,7 +21,6 @@ libudev_version = '1.6.11' # set. Ugh, ugh, ugh! conf = configuration_data() conf.set('PROJECT_VERSION', meson.project_version()) -conf.set_quoted('PACKAGE_VERSION', meson.project_version()) substs = configuration_data() substs.set('PROJECT_URL', 'https://www.freedesktop.org/wiki/Software/systemd') @@ -584,6 +583,10 @@ endif ##################################################################### +vcs_tagger = [meson.source_root() + '/tools/meson-vcs-tag.sh', + '@0@/.git'.format(meson.source_root()), + meson.project_version()] + sed = find_program('sed') awk = find_program('awk') m4 = find_program('m4') diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index 1f69b9fda1..3915b66739 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -14,6 +14,7 @@ #include "alloc-util.h" #include "analyze-security.h" #include "analyze-verify.h" +#include "build.h" #include "bus-error.h" #include "bus-unit-util.h" #include "bus-util.h" @@ -696,7 +697,7 @@ static int analyze_plot(int argc, char *argv[], void *userdata) { "\n" "\n" "\n\n" - "\n\n", PACKAGE_VERSION); + "\n\n", GIT_VERSION); /* style sheet */ svg("\n