Merge pull request #11230 from keszybz/version-string-alt

Generate version string from git describe (alternative approach)
This commit is contained in:
Yu Watanabe 2019-01-03 21:33:55 +09:00 committed by GitHub
commit a92f2af28a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 115 additions and 92 deletions

View File

@ -20,12 +20,11 @@ libudev_version = '1.6.12'
# names, sometimes. Not all variables are included in every
# set. Ugh, ugh, ugh!
conf = configuration_data()
conf.set_quoted('PACKAGE_STRING', meson.project_name() + ' ' + meson.project_version())
conf.set_quoted('PACKAGE_VERSION', meson.project_version())
conf.set('PROJECT_VERSION', meson.project_version())
substs = configuration_data()
substs.set('PACKAGE_URL', 'https://www.freedesktop.org/wiki/Software/systemd')
substs.set('PACKAGE_VERSION', meson.project_version())
substs.set('PROJECT_URL', 'https://www.freedesktop.org/wiki/Software/systemd')
substs.set('PROJECT_VERSION', meson.project_version())
want_ossfuzz = get_option('oss-fuzz')
want_libfuzzer = get_option('llvm-fuzz')
@ -582,6 +581,11 @@ endif
#####################################################################
vcs_tagger = [meson.source_root() + '/tools/meson-vcs-tag.sh',
meson.source_root(),
get_option('version-tag'),
meson.project_version()]
sed = find_program('sed')
awk = find_program('awk')
m4 = find_program('m4')
@ -2892,8 +2896,9 @@ foreach tuple : fuzzers
endforeach
endif
run_target('fuzzers',
depends : fuzzer_exes,
run_target(
'fuzzers',
depends : [fuzzer_exes, version_h],
command : ['true'])
############################################################

View File

@ -1,6 +1,9 @@
# -*- mode: meson -*-
# SPDX-License-Identifier: LGPL-2.1+
option('version-tag', type : 'string',
description : 'override the git version string')
option('split-usr', type : 'combo', choices : ['auto', 'true', 'false'],
description : '''/bin, /sbin aren't symlinks into /usr''')
option('split-bin', type : 'combo', choices : ['auto', 'true', 'false'],

View 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"

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(PACKAGE_STRING "\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@"

View 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);

View 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',

View 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);

View 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()));

View File

@ -1914,7 +1914,7 @@ static void log_execution_mode(bool *ret_first_boot) {
if (arg_system) {
int v;
log_info(PACKAGE_STRING " 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(PACKAGE_STRING " 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));
}

View File

@ -173,26 +173,19 @@ systemd_shutdown_sources = files('''
'''.split())
in_files = [['macros.systemd', rpmmacrosdir],
['triggers.systemd', ''],
['system.conf', pkgsysconfdir],
['systemd.pc', pkgconfigdatadir],
['system.conf', pkgsysconfdir]]
['triggers.systemd', '']]
foreach item : in_files
file = item[0]
dir = item[1]
# If 'no', disable generation completely.
# If '', generate, but do not install.
if dir != 'no'
gen = configure_file(
input : file + '.in',
output : file,
configuration : substs)
if dir != ''
install_data(gen,
install_dir : dir)
endif
endif
configure_file(
input : file + '.in',
output : file,
configuration : substs,
install_dir : dir == 'no' ? '' : dir)
endforeach
install_data('org.freedesktop.systemd1.conf',

View File

@ -36,5 +36,5 @@ containeruidbasemax=@containeruidbasemax@
Name: systemd
Description: systemd System and Service Manager
URL: @PACKAGE_URL@
Version: @PACKAGE_VERSION@
URL: @PROJECT_URL@
Version: @PROJECT_VERSION@

View 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;

View 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_STRING,
"systemd-journal-upload " GIT_VERSION,
LOG_WARNING, );
if (arg_key || startswith(u->url, "https://")) {

View File

@ -14,7 +14,7 @@ includedir=@includedir@
Name: systemd
Description: systemd Library
URL: @PACKAGE_URL@
Version: @PACKAGE_VERSION@
URL: @PROJECT_URL@
Version: @PROJECT_VERSION@
Libs: -L${libdir} -lsystemd
Cflags: -I${includedir}

View File

@ -109,9 +109,8 @@ libsystemd_static = static_library(
libsystemd_sym = 'src/libsystemd/libsystemd.sym'
libsystemd_pc = configure_file(
configure_file(
input : 'libsystemd.pc.in',
output : 'libsystemd.pc',
configuration : substs)
install_data(libsystemd_pc,
install_dir : pkgconfiglibdir)
configuration : substs,
install_dir : pkgconfiglibdir == 'no' ? '' : pkgconfiglibdir)

View File

@ -367,7 +367,7 @@ static int trie_store(struct trie *trie, const char *filename, bool compat) {
int64_t size;
struct trie_header_f h = {
.signature = HWDB_SIG,
.tool_version = htole64(atoi(PACKAGE_VERSION)),
.tool_version = htole64(PROJECT_VERSION),
.header_size = htole64(sizeof(struct trie_header_f)),
.node_size = htole64(sizeof(struct trie_node_f)),
.child_entry_size = htole64(sizeof(struct trie_child_entry_f)),

View File

@ -14,6 +14,6 @@ includedir=@includedir@
Name: libudev
Description: Library to access udev device information
Version: @PACKAGE_VERSION@
Version: @PROJECT_VERSION@
Libs: -L${libdir} -ludev
Cflags: -I${includedir}

View File

@ -22,9 +22,8 @@ libudev_sym_path = meson.current_source_dir() + '/libudev.sym'
install_headers('libudev.h')
libudev_h_path = '@0@/libudev.h'.format(meson.current_source_dir())
libudev_pc = configure_file(
configure_file(
input : 'libudev.pc.in',
output : 'libudev.pc',
configuration : substs)
install_data(libudev_pc,
install_dir : pkgconfiglibdir)
configuration : substs,
install_dir : pkgconfiglibdir == 'no' ? '' : pkgconfiglibdir)

View 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':

View File

@ -531,7 +531,7 @@ static void test_hidden_or_backup_file(void) {
static void test_systemd_installation_has_version(const char *path) {
int r;
const unsigned versions[] = {0, 231, atoi(PACKAGE_VERSION), 999};
const unsigned versions[] = {0, 231, PROJECT_VERSION, 999};
unsigned i;
for (i = 0; i < ELEMENTSOF(versions); i++) {

View 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];

View File

@ -187,12 +187,11 @@ endforeach
install_data('udev.conf',
install_dir : join_paths(sysconfdir, 'udev'))
udev_pc = configure_file(
configure_file(
input : 'udev.pc.in',
output : 'udev.pc',
configuration : substs)
install_data(udev_pc,
install_dir : pkgconfigdatadir)
configuration : substs,
install_dir : pkgconfigdatadir == 'no' ? '' : pkgconfigdatadir)
meson.add_install_script('sh', '-c',
mkdir_p.format(join_paths(sysconfdir, 'udev/rules.d')))

View 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':

View File

@ -214,13 +214,11 @@ static struct udev_ctrl_connection *udev_ctrl_connection_free(struct udev_ctrl_c
DEFINE_TRIVIAL_REF_UNREF_FUNC(struct udev_ctrl_connection, udev_ctrl_connection, udev_ctrl_connection_free);
static int ctrl_send(struct udev_ctrl *uctrl, enum udev_ctrl_msg_type type, int intval, const char *buf, int timeout) {
struct udev_ctrl_msg_wire ctrl_msg_wire;
int err = 0;
memzero(&ctrl_msg_wire, sizeof(struct udev_ctrl_msg_wire));
strcpy(ctrl_msg_wire.version, "udev-" PACKAGE_VERSION);
ctrl_msg_wire.magic = UDEV_CTRL_MAGIC;
ctrl_msg_wire.type = type;
struct udev_ctrl_msg_wire ctrl_msg_wire = {
.version = "udev-" STRINGIFY(PROJECT_VERSION),
.magic = UDEV_CTRL_MAGIC,
.type = type,
};
if (buf)
strscpy(ctrl_msg_wire.buf, sizeof(ctrl_msg_wire.buf), buf);
@ -228,43 +226,33 @@ static int ctrl_send(struct udev_ctrl *uctrl, enum udev_ctrl_msg_type type, int
ctrl_msg_wire.intval = intval;
if (!uctrl->connected) {
if (connect(uctrl->sock, &uctrl->saddr.sa, uctrl->addrlen) < 0) {
err = -errno;
goto out;
}
if (connect(uctrl->sock, &uctrl->saddr.sa, uctrl->addrlen) < 0)
return -errno;
uctrl->connected = true;
}
if (send(uctrl->sock, &ctrl_msg_wire, sizeof(ctrl_msg_wire), 0) < 0) {
err = -errno;
goto out;
}
if (send(uctrl->sock, &ctrl_msg_wire, sizeof(ctrl_msg_wire), 0) < 0)
return -errno;
/* wait for peer message handling or disconnect */
for (;;) {
struct pollfd pfd[1];
struct pollfd pfd = {
.fd = uctrl->sock,
.events = POLLIN,
};
int r;
pfd[0].fd = uctrl->sock;
pfd[0].events = POLLIN;
r = poll(pfd, 1, timeout * MSEC_PER_SEC);
r = poll(&pfd, 1, timeout * MSEC_PER_SEC);
if (r < 0) {
if (errno == EINTR)
continue;
err = -errno;
break;
return -errno;
}
if (r > 0 && pfd[0].revents & POLLERR) {
err = -EIO;
break;
}
if (r == 0)
err = -ETIMEDOUT;
break;
return -ETIMEDOUT;
if (pfd.revents & POLLERR)
return -EIO;
return 0;
}
out:
return err;
}
int udev_ctrl_send_set_log_level(struct udev_ctrl *uctrl, int priority, int timeout) {

View File

@ -1,5 +1,5 @@
Name: udev
Description: udev
Version: @PACKAGE_VERSION@
Version: @PROJECT_VERSION@
udevdir=@udevlibexecdir@

View File

@ -3,6 +3,9 @@
#include <stdio.h>
#include "build.h"
#include "macro.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 +16,7 @@ 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);
/* Dracut relies on the version being a single integer */
puts(STRINGIFY(PROJECT_VERSION));
return 0;
}

View 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) {

18
tools/meson-vcs-tag.sh Executable file
View File

@ -0,0 +1,18 @@
#!/bin/bash
set -eu
set -o pipefail
dir="$1"
tag="$2"
fallback="$3"
if [ -n "$tag" ]; then
echo "$tag"
exit 0
fi
# Apparently git describe has a bug where it always considers the work-tree
# dirty when invoked with --git-dir (even though 'git status' is happy). Work
# around this issue by cd-ing to the source directory.
cd "$dir" && git describe --abbrev=7 --dirty=+ 2>/dev/null | sed 's/^v//' || echo "$fallback"