From: Simon McVittie Date: Fri, 6 Dec 2024 17:48:04 +0000 (+0000) Subject: build: Allow version number to be followed by "-" and a suffix X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd667b95564103549ad4315d7f473b722ecd1920;p=thirdparty%2Fdbus.git build: Allow version number to be followed by "-" and a suffix Some distributions are known to have shipped dbus 1.15.x as though it was a stable release, and it isn't clear whether they knew that we use the odd/even versioning convention like GLib does. If we add a -alpha, -beta, -rc suffix to development versions starting from 1.17.0, then distros that know we use odd/even versioning will know that our development versions are not a stable-branch, and so will distros that mistakenly think we use the "semantic versioning" versioning convention popularized by . (We intentionally do not use semver, because semver would require us to ship a new minor version every time we add new API, and we do not have the resources to provide security support for an unlimited number of minor versions in parallel: we need to be able to nominate a subset of our releases as having longer-term security support, in a way that signals to distros that these are the releases they should prefer to ship.) CMake's `project()` doesn't allow this version number format[1], but we intend to use version numbers where the (major, minor, micro) tuple is enough to uniquely identify a release, so we can just tell CMake our version number without the suffix and there will be no ambiguity. Similarly, the dash is not allowed in GNU ld version scripts, so use the form of the version number without the suffix there. [1] https://gitlab.kitware.com/cmake/cmake/-/issues/16716 Helps: dbus#530 Signed-off-by: Simon McVittie --- diff --git a/CMakeLists.txt b/CMakeLists.txt index c2f288001..212a093a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ else() set(LANGUAGES C) endif() project(dbus - VERSION ${DBUS_VERSION} + VERSION ${DBUS_VERSION_NO_SUFFIX} LANGUAGES C CXX ) diff --git a/cmake/modules/MacrosMeson.cmake b/cmake/modules/MacrosMeson.cmake index d26617d2b..152672e26 100644 --- a/cmake/modules/MacrosMeson.cmake +++ b/cmake/modules/MacrosMeson.cmake @@ -32,8 +32,9 @@ endmacro() macro(meson_version prefix) set(WS "[ \t\r\n]") string(TOUPPER ${prefix} prefix_upper) - string(REGEX REPLACE ".*${WS}version:${WS}*'([0-9.]+)'.*" "\\1" ${prefix_upper}_VERSION ${_meson_build_raw}) - string(REPLACE "." ";" VERSION_LIST ${${prefix_upper}_VERSION}) + string(REGEX REPLACE ".*${WS}version:${WS}*'([0-9.]+(-[-a-zA-Z0-9.]+)?)'.*" "\\1" ${prefix_upper}_VERSION ${_meson_build_raw}) + string(REGEX REPLACE "-.*" "" ${prefix_upper}_VERSION_NO_SUFFIX ${${prefix_upper}_VERSION}) + string(REPLACE "." ";" VERSION_LIST ${${prefix_upper}_VERSION_NO_SUFFIX}) list(GET VERSION_LIST 0 ${prefix_upper}_MAJOR_VERSION) list(GET VERSION_LIST 1 ${prefix_upper}_MINOR_VERSION) list(GET VERSION_LIST 2 ${prefix_upper}_MICRO_VERSION) diff --git a/dbus/Version.in b/dbus/Version.in index f6cc3676e..303f6e847 100644 --- a/dbus/Version.in +++ b/dbus/Version.in @@ -4,7 +4,7 @@ LIBDBUS_1_@SOVERSION@ { local: *; }; -LIBDBUS_PRIVATE_@DBUS_VERSION@ { +LIBDBUS_PRIVATE_@DBUS_VERSION_NO_SUFFIX@ { global: _dbus_*; }; diff --git a/dbus/dbus-misc.c b/dbus/dbus-misc.c index 0f6c2e6d5..47140c7fa 100644 --- a/dbus/dbus-misc.c +++ b/dbus/dbus-misc.c @@ -179,6 +179,9 @@ dbus_get_local_machine_id (void) * least significant byte. This means two DBUS_VERSION can be compared to see * which is higher. * + * This does not include any release-status suffix like "-alpha", "-beta", + * "-rc". + * * Consider carefully whether to use this or the runtime version from * dbus_get_version(). */ @@ -188,6 +191,10 @@ dbus_get_local_machine_id (void) * * The COMPILE TIME version of libdbus, as a string "X.Y.Z". * + * This might include additional information beyond what appears in + * DBUS_VERSION, for example an "-alpha", "-beta" or "-rc" suffix + * that is not represented elsewhere. + * * Consider carefully whether to use this or the runtime version from * dbus_get_version(). */ diff --git a/meson.build b/meson.build index bac82baa7..fd2ff7396 100644 --- a/meson.build +++ b/meson.build @@ -47,11 +47,13 @@ install_symlinks = [] not_found = dependency('', required: false) version = meson.project_version() +version_no_suffix = version.split('-')[0] config.set_quoted('VERSION', version) data_config.set('VERSION', version) data_config.set('DBUS_VERSION', version) +data_config.set('DBUS_VERSION_NO_SUFFIX', version_no_suffix) -ver_array = version.split('.') +ver_array = version_no_suffix.split('.') arch_config.set('DBUS_VERSION', version) arch_config.set('DBUS_MAJOR_VERSION', ver_array[0]) arch_config.set('DBUS_MINOR_VERSION', ver_array[1]) @@ -142,7 +144,7 @@ if platform_windows ).stdout().strip() data_config.set('BUILD_TIMESTAMP', build_timestamp) - data_config.set('BUILD_FILEVERSION', ','.join(version.split('.'))) + data_config.set('BUILD_FILEVERSION', ','.join(version_no_suffix.split('.'))) data_config.set('DBUS_VER_FILE_TYPE', 'VFT_DLL') data_config.set('DBUS_VER_INTERNAL_NAME', 'libdbus-1-@0@' .format(soversion)) diff --git a/test/internals/misc-internals.c b/test/internals/misc-internals.c index 6daa97c35..a6a54b91d 100644 --- a/test/internals/misc-internals.c +++ b/test/internals/misc-internals.c @@ -615,8 +615,11 @@ _dbus_list_test (const char *test_data_dir _DBUS_GNUC_UNUSED) static dbus_bool_t _dbus_misc_test (const char *test_data_dir _DBUS_GNUC_UNUSED) { + static const char compiled_version[] = DBUS_VERSION_STRING; + const char *runtime_version; int major, minor, micro; DBusString str; + size_t len; /* make sure we don't crash on NULL */ dbus_get_version (NULL, NULL, NULL); @@ -663,7 +666,17 @@ _dbus_misc_test (const char *test_data_dir _DBUS_GNUC_UNUSED) if (!_dbus_string_append_printf (&str, "%d.%d.%d", major, minor, micro)) _dbus_test_fatal ("no memory"); - _dbus_test_check (_dbus_string_equal_c_str (&str, DBUS_VERSION_STRING)); + runtime_version = _dbus_string_get_const_data (&str); + len = _dbus_string_get_length_uint (&str); + + /* This is not an API guarantee, but in practice we only plan to + * set the version string to either X.Y.Z (stable branches) or + * X.Y.Z-{alpha,beta,rc} (development branches), so the + * DBUS_VERSION_STRING stored in compiled_version should be + * X.Y.Z followed by either '\0' or "-...". */ + _dbus_test_check (strlen (compiled_version) >= len); + _dbus_test_check (strncmp (runtime_version, compiled_version, len) == 0); + _dbus_test_check (compiled_version[len] == '\0' || compiled_version[len] == '-'); _dbus_string_free (&str);