]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
meson: generate version tag from git
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 20 Dec 2018 19:35:25 +0000 (20:35 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 21 Dec 2018 12:43:20 +0000 (13:43 +0100)
$ 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.

19 files changed:
meson.build
src/analyze/analyze.c
src/basic/build.h
src/basic/meson.build
src/basic/util.c
src/basic/version.h.in [new file with mode: 0644]
src/boot/efi/boot.c
src/boot/efi/meson.build
src/boot/efi/stub.c
src/core/dbus-manager.c
src/core/main.c
src/import/curl-util.c
src/journal-remote/journal-upload.c
src/test/test-libudev.c
src/test/test-udev.c
src/udev/scsi_id/scsi_id.c
src/udev/udevadm.h
src/udev/udevd.c
tools/meson-vcs-tag.sh [new file with mode: 0755]

index 7816ba99490722ce0fed258f1cc90ad6930ecb78..100265570d53dbcf576befeb5f6cb4b0d8fa231f 100644 (file)
@@ -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')
index 1f69b9fda1b1d795b48be28ffd0539ada623fb1e..3915b66739e0ab4642c0df30e631a2bc5c91a320 100644 (file)
@@ -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) {
             "<!-- that render these files properly but much slower are ImageMagick,   -->\n"
             "<!-- gimp, inkscape, etc. To display the files on your system, just      -->\n"
             "<!-- point your browser to this file.                                    -->\n\n"
-            "<!-- This plot was generated by systemd-analyze version %-16.16s -->\n\n", PACKAGE_VERSION);
+            "<!-- This plot was generated by systemd-analyze version %-16.16s -->\n\n", GIT_VERSION);
 
         /* style sheet */
         svg("<defs>\n  <style type=\"text/css\">\n    <![CDATA[\n"
index 2c46550300c1d6a6e8a72e23a9c51bdbe0e59c89..7a59059080d384a7d87e795284139ec5692cd198 100644 (file)
@@ -1,6 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 #pragma once
 
+#include "version.h"
+
 #if HAVE_PAM
 #define _PAM_FEATURE_ "+PAM"
 #else
index 23b5e75bd8ae3e56ebb175708e49cc2b499e7217..95a0d45450df30ce2cf0f7a549f0f2b9372f8852 100644 (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
index 4d0c64f932fe21230a611208746b6a1e6e0f148b..96c314e8950b8f45e30b9fc0ca2165debe478955 100644 (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;
 }
diff --git a/src/basic/version.h.in b/src/basic/version.h.in
new file mode 100644 (file)
index 0000000..9f82d90
--- /dev/null
@@ -0,0 +1 @@
+#define GIT_VERSION "@VCS_TAG@"
index 4719eeaf4b806b2a76f1cc02802480fa8e997f95..5aae7e7c06bb6f93ac4e3409a353f3bc19aef00d 100644 (file)
@@ -17,7 +17,7 @@
 #endif
 
 /* magic string to find in the binary image */
-static const char __attribute__((used)) magic[] = "#### LoaderInfo: systemd-boot " PACKAGE_VERSION " ####";
+static const char __attribute__((used)) magic[] = "#### LoaderInfo: systemd-boot " GIT_VERSION " ####";
 
 static const EFI_GUID global_guid = EFI_GLOBAL_VARIABLE;
 
@@ -361,7 +361,7 @@ static VOID print_status(Config *config, CHAR16 *loaded_image_path) {
         uefi_call_wrapper(ST->ConOut->SetAttribute, 2, ST->ConOut, EFI_LIGHTGRAY|EFI_BACKGROUND_BLACK);
         uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut);
 
-        Print(L"systemd-boot version:   " PACKAGE_VERSION "\n");
+        Print(L"systemd-boot version:   " GIT_VERSION "\n");
         Print(L"architecture:           " EFI_MACHINE_TYPE_NAME "\n");
         Print(L"loaded image:           %s\n", loaded_image_path);
         Print(L"UEFI specification:     %d.%02d\n", ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0xffff);
@@ -804,7 +804,7 @@ static BOOLEAN menu_run(
                         break;
 
                 case KEYPRESS(0, 0, 'v'):
-                        status = PoolPrint(L"systemd-boot " PACKAGE_VERSION " (" EFI_MACHINE_TYPE_NAME "), UEFI Specification %d.%02d, Vendor %s %d.%02d",
+                        status = PoolPrint(L"systemd-boot " GIT_VERSION " (" EFI_MACHINE_TYPE_NAME "), UEFI Specification %d.%02d, Vendor %s %d.%02d",
                                            ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0xffff,
                                            ST->FirmwareVendor, ST->FirmwareRevision >> 16, ST->FirmwareRevision & 0xffff);
                         break;
@@ -2097,7 +2097,7 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
         InitializeLib(image, sys_table);
         init_usec = time_usec();
         efivar_set_time_usec(L"LoaderTimeInitUSec", init_usec);
-        efivar_set(L"LoaderInfo", L"systemd-boot " PACKAGE_VERSION, FALSE);
+        efivar_set(L"LoaderInfo", L"systemd-boot " GIT_VERSION, FALSE);
 
         infostr = PoolPrint(L"%s %d.%02d", ST->FirmwareVendor, ST->FirmwareRevision >> 16, ST->FirmwareRevision & 0xffff);
         efivar_set(L"LoaderFirmwareInfo", infostr, FALSE);
index aa897c62a13fa044879dd004671a409c8530a4c7..9c0ae5ace1da8c8eca156e8c422b08028e5e2914 100644 (file)
@@ -78,7 +78,6 @@ endif
 
 if have_gnu_efi
         efi_conf = configuration_data()
-        efi_conf.set_quoted('PACKAGE_VERSION', meson.project_version())
         efi_conf.set_quoted('EFI_MACHINE_TYPE_NAME', EFI_MACHINE_TYPE_NAME)
         efi_conf.set10('ENABLE_TPM', get_option('tpm'))
         efi_conf.set('SD_TPM_PCR', get_option('tpm-pcrindex'))
@@ -117,7 +116,8 @@ if have_gnu_efi
                         '-Wno-missing-field-initializers',
                         '-isystem', efi_incdir,
                         '-isystem', join_paths(efi_incdir, gnu_efi_path_arch),
-                        '-include', efi_config_h]
+                        '-include', efi_config_h,
+                        '-include', version_h]
         if efi_arch == 'x86_64'
                 compile_args += ['-mno-red-zone',
                                  '-mno-sse',
index d11e55574857e6214a248685d5bcffe435f29e69..6b07879971c5dbebd84b5739d1bcd1d016f36142 100644 (file)
@@ -12,7 +12,7 @@
 #include "util.h"
 
 /* magic string to find in the binary image */
-static const char __attribute__((used)) magic[] = "#### LoaderInfo: systemd-stub " PACKAGE_VERSION " ####";
+static const char __attribute__((used)) magic[] = "#### LoaderInfo: systemd-stub " GIT_VERSION " ####";
 
 static const EFI_GUID global_guid = EFI_GLOBAL_VARIABLE;
 
@@ -117,7 +117,7 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
 
         /* add StubInfo */
         if (efivar_get_raw(&global_guid, L"StubInfo", &b, &size) != EFI_SUCCESS)
-                efivar_set(L"StubInfo", L"systemd-stub " PACKAGE_VERSION, FALSE);
+                efivar_set(L"StubInfo", L"systemd-stub " GIT_VERSION, FALSE);
 
         if (szs[3] > 0)
                 graphics_splash((UINT8 *)((UINTN)loaded_image->ImageBase + addrs[3]), szs[3], NULL);
index 8da07adfe728ecfa8e4609336f8854bed886995b..88e4c6bb952099f9805936aec0e5dda4010cc364 100644 (file)
@@ -43,7 +43,7 @@ static UnitFileFlags unit_file_bools_to_flags(bool runtime, bool force) {
                (force   ? UNIT_FILE_FORCE   : 0);
 }
 
-static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_version, "s", PACKAGE_VERSION);
+static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_version, "s", GIT_VERSION);
 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_features, "s", SYSTEMD_FEATURES);
 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_architecture, "s", architecture_to_string(uname_architecture()));
 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_log_target, "s", log_target_to_string(log_get_target()));
index 0c2313fc191a2ae36a373f4037477358a0f41a0c..bb86280c2d790749d4bbd15d1663daea62db5790 100644 (file)
@@ -1914,7 +1914,7 @@ static void log_execution_mode(bool *ret_first_boot) {
         if (arg_system) {
                 int v;
 
-                log_info("systemd " PACKAGE_VERSION " running in %ssystem mode. (" SYSTEMD_FEATURES ")",
+                log_info("systemd " GIT_VERSION " running in %ssystem mode. (" SYSTEMD_FEATURES ")",
                          arg_action == ACTION_TEST ? "test " : "" );
 
                 v = detect_virtualization();
@@ -1942,7 +1942,7 @@ static void log_execution_mode(bool *ret_first_boot) {
                         _cleanup_free_ char *t;
 
                         t = uid_to_name(getuid());
-                        log_debug("systemd " PACKAGE_VERSION " running in %suser mode for user " UID_FMT "/%s. (" SYSTEMD_FEATURES ")",
+                        log_debug("systemd " GIT_VERSION " running in %suser mode for user " UID_FMT "/%s. (" SYSTEMD_FEATURES ")",
                                   arg_action == ACTION_TEST ? " test" : "", getuid(), strna(t));
                 }
 
index 05b17c3c7820b5ab974026e7cf67a7569b96fdcd..360628fe440a753fbd59f61b1ae873f5e9976bbd 100644 (file)
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 
 #include "alloc-util.h"
+#include "build.h"
 #include "curl-util.h"
 #include "fd-util.h"
 #include "locale-util.h"
@@ -283,7 +284,7 @@ int curl_glue_make(CURL **ret, const char *url, void *userdata) {
         if (curl_easy_setopt(c, CURLOPT_PRIVATE, userdata) != CURLE_OK)
                 return -EIO;
 
-        useragent = strjoina(program_invocation_short_name, "/" PACKAGE_VERSION);
+        useragent = strjoina(program_invocation_short_name, "/" GIT_VERSION);
         if (curl_easy_setopt(c, CURLOPT_USERAGENT, useragent) != CURLE_OK)
                 return -EIO;
 
index 8d459235bfd9e175eb16910f869718ad05d83c08..ef3556f8254af8468d91bac89812a90517f9de9b 100644 (file)
@@ -9,6 +9,7 @@
 #include "sd-daemon.h"
 
 #include "alloc-util.h"
+#include "build.h"
 #include "conf-parser.h"
 #include "daemon-util.h"
 #include "def.h"
@@ -236,7 +237,7 @@ int start_upload(Uploader *u,
                         easy_setopt(curl, CURLOPT_VERBOSE, 1L, LOG_WARNING, );
 
                 easy_setopt(curl, CURLOPT_USERAGENT,
-                            "systemd-journal-upload " PACKAGE_VERSION,
+                            "systemd-journal-upload " GIT_VERSION,
                             LOG_WARNING, );
 
                 if (arg_key || startswith(u->url, "https://")) {
index 10bf3650356293f42e50fa8df1feb8eabb7eae04..53c9e5f7459b7ed44149a4c0dea6109aa48ea6c8 100644 (file)
@@ -7,6 +7,7 @@
 #include <unistd.h>
 
 #include "alloc-util.h"
+#include "build.h"
 #include "fd-util.h"
 #include "libudev-list-internal.h"
 #include "libudev-util.h"
@@ -507,7 +508,7 @@ int main(int argc, char *argv[]) {
                         return EXIT_SUCCESS;
 
                 case 'V':
-                        printf("%s\n", PACKAGE_VERSION);
+                        printf("%s\n", GIT_VERSION);
                         return EXIT_SUCCESS;
 
                 case 'm':
index 7a4622b8752bc5da65b42e88c2a385e57a2eb9b8..ab31f5a2f1bbaa25c363aa97068bac51550eb70f 100644 (file)
@@ -11,6 +11,7 @@
 #include <sys/signalfd.h>
 #include <unistd.h>
 
+#include "build.h"
 #include "device-private.h"
 #include "fs-util.h"
 #include "log.h"
@@ -81,7 +82,7 @@ static int run(int argc, char *argv[]) {
                 return 0;
         }
 
-        log_debug("version %s", PACKAGE_VERSION);
+        log_debug("version %s", GIT_VERSION);
         mac_selinux_init();
 
         action = argv[1];
index e94f2946f9dfc0aabf831c4d849911b371ea556f..2698cdd82fd9d8bb36103cd1601c79ced3957474 100644 (file)
@@ -18,6 +18,7 @@
 #include <unistd.h>
 
 #include "alloc-util.h"
+#include "build.h"
 #include "fd-util.h"
 #include "libudev-util.h"
 #include "scsi_id.h"
@@ -370,7 +371,7 @@ static int set_options(int argc, char **argv,
                         break;
 
                 case 'V':
-                        printf("%s\n", PACKAGE_VERSION);
+                        printf("%s\n", GIT_VERSION);
                         exit(EXIT_SUCCESS);
 
                 case 'x':
index 98f9019a48aaa7d9c7c278ca544792a09be3ebc0..af0faff443510b413511e538cd76bf3d776fea90 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <stdio.h>
 
+#include "build.h"
+
 int info_main(int argc, char *argv[], void *userdata);
 int trigger_main(int argc, char *argv[], void *userdata);
 int settle_main(int argc, char *argv[], void *userdata);
@@ -13,6 +15,6 @@ int test_main(int argc, char *argv[], void *userdata);
 int builtin_main(int argc, char *argv[], void *userdata);
 
 static inline int print_version(void) {
-        puts(PACKAGE_VERSION);
+        puts(GIT_VERSION);
         return 0;
 }
index fb8724ea8723fbe2e9469362f6398c25fde1fe2a..ed5c3eb5dd7caa655beecd5b90b7cbb7ec7cda44 100644 (file)
@@ -31,6 +31,7 @@
 #include "sd-event.h"
 
 #include "alloc-util.h"
+#include "build.h"
 #include "cgroup-util.h"
 #include "cpu-set-util.h"
 #include "dev-setup.h"
@@ -1579,7 +1580,7 @@ static int parse_argv(int argc, char *argv[]) {
                 case 'h':
                         return help();
                 case 'V':
-                        printf("%s\n", PACKAGE_VERSION);
+                        printf("%s\n", GIT_VERSION);
                         return 0;
                 case '?':
                         return -EINVAL;
@@ -1834,7 +1835,7 @@ static int run(int argc, char *argv[]) {
         if (arg_daemonize) {
                 pid_t pid;
 
-                log_info("starting version " PACKAGE_VERSION);
+                log_info("starting version " GIT_VERSION);
 
                 /* connect /dev/null to stdin, stdout, stderr */
                 if (log_get_max_level() < LOG_DEBUG) {
diff --git a/tools/meson-vcs-tag.sh b/tools/meson-vcs-tag.sh
new file mode 100755 (executable)
index 0000000..9b024c8
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+set -eu
+set -o pipefail
+
+gitdir="$1"
+fallback="$2"
+
+git --git-dir="$gitdir" describe --abbrev=7 --dirty=+ 2>/dev/null | sed 's/^v//' || echo "$fallback"