diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-12-20 20:35:25 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-12-21 13:43:20 +0100 |
commit | 681bd2c524ed71ac04045c90884ba8d55eee7b66 (patch) | |
tree | f50b21fb487cead9833a04a307f0e4d7b54d7a8d | |
parent | b9da6a098b08d4eafec239fc05e0fd2073115504 (diff) | |
download | systemd-681bd2c524ed71ac04045c90884ba8d55eee7b66.tar.gz |
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.
-rw-r--r-- | meson.build | 5 | ||||
-rw-r--r-- | src/analyze/analyze.c | 3 | ||||
-rw-r--r-- | src/basic/build.h | 2 | ||||
-rw-r--r-- | src/basic/meson.build | 5 | ||||
-rw-r--r-- | src/basic/util.c | 2 | ||||
-rw-r--r-- | src/basic/version.h.in | 1 | ||||
-rw-r--r-- | src/boot/efi/boot.c | 8 | ||||
-rw-r--r-- | src/boot/efi/meson.build | 4 | ||||
-rw-r--r-- | src/boot/efi/stub.c | 4 | ||||
-rw-r--r-- | src/core/dbus-manager.c | 2 | ||||
-rw-r--r-- | src/core/main.c | 4 | ||||
-rw-r--r-- | src/import/curl-util.c | 3 | ||||
-rw-r--r-- | src/journal-remote/journal-upload.c | 3 | ||||
-rw-r--r-- | src/test/test-libudev.c | 3 | ||||
-rw-r--r-- | src/test/test-udev.c | 3 | ||||
-rw-r--r-- | src/udev/scsi_id/scsi_id.c | 3 | ||||
-rw-r--r-- | src/udev/udevadm.h | 4 | ||||
-rw-r--r-- | src/udev/udevd.c | 5 | ||||
-rwxr-xr-x | tools/meson-vcs-tag.sh | 9 |
19 files changed, 51 insertions, 22 deletions
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) { "<!-- 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" diff --git a/src/basic/build.h b/src/basic/build.h index 2c46550300..7a59059080 100644 --- a/src/basic/build.h +++ b/src/basic/build.h @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ #pragma once +#include "version.h" + #if HAVE_PAM #define _PAM_FEATURE_ "+PAM" #else diff --git a/src/basic/meson.build b/src/basic/meson.build index 23b5e75bd8..95a0d45450 100644 --- a/src/basic/meson.build +++ b/src/basic/meson.build @@ -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 diff --git a/src/basic/util.c b/src/basic/util.c index 4d0c64f932..96c314e895 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -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 index 0000000000..9f82d905a7 --- /dev/null +++ b/src/basic/version.h.in @@ -0,0 +1 @@ +#define GIT_VERSION "@VCS_TAG@" diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c index 4719eeaf4b..5aae7e7c06 100644 --- a/src/boot/efi/boot.c +++ b/src/boot/efi/boot.c @@ -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); diff --git a/src/boot/efi/meson.build b/src/boot/efi/meson.build index aa897c62a1..9c0ae5ace1 100644 --- a/src/boot/efi/meson.build +++ b/src/boot/efi/meson.build @@ -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', diff --git a/src/boot/efi/stub.c b/src/boot/efi/stub.c index d11e555748..6b07879971 100644 --- a/src/boot/efi/stub.c +++ b/src/boot/efi/stub.c @@ -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); diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 8da07adfe7..88e4c6bb95 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -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())); diff --git a/src/core/main.c b/src/core/main.c index 0c2313fc19..bb86280c2d 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -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)); } diff --git a/src/import/curl-util.c b/src/import/curl-util.c index 05b17c3c78..360628fe44 100644 --- a/src/import/curl-util.c +++ b/src/import/curl-util.c @@ -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; diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c index 8d459235bf..ef3556f825 100644 --- a/src/journal-remote/journal-upload.c +++ b/src/journal-remote/journal-upload.c @@ -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://")) { diff --git a/src/test/test-libudev.c b/src/test/test-libudev.c index 10bf365035..53c9e5f745 100644 --- a/src/test/test-libudev.c +++ b/src/test/test-libudev.c @@ -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': diff --git a/src/test/test-udev.c b/src/test/test-udev.c index 7a4622b875..ab31f5a2f1 100644 --- a/src/test/test-udev.c +++ b/src/test/test-udev.c @@ -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]; diff --git a/src/udev/scsi_id/scsi_id.c b/src/udev/scsi_id/scsi_id.c index e94f2946f9..2698cdd82f 100644 --- a/src/udev/scsi_id/scsi_id.c +++ b/src/udev/scsi_id/scsi_id.c @@ -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': diff --git a/src/udev/udevadm.h b/src/udev/udevadm.h index 98f9019a48..af0faff443 100644 --- a/src/udev/udevadm.h +++ b/src/udev/udevadm.h @@ -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; } diff --git a/src/udev/udevd.c b/src/udev/udevd.c index fb8724ea87..ed5c3eb5dd 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -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 index 0000000000..9b024c8c28 --- /dev/null +++ b/tools/meson-vcs-tag.sh @@ -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" |