]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
build: Allow version number to be followed by "-" and a suffix
authorSimon McVittie <smcv@collabora.com>
Fri, 6 Dec 2024 17:48:04 +0000 (17:48 +0000)
committerSimon McVittie <smcv@collabora.com>
Tue, 10 Dec 2024 12:30:16 +0000 (12:30 +0000)
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 <https://semver.org/>.

(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 <smcv@collabora.com>
CMakeLists.txt
cmake/modules/MacrosMeson.cmake
dbus/Version.in
dbus/dbus-misc.c
meson.build
test/internals/misc-internals.c

index c2f2880010c6306dcaca47ab7b9851bd7872eede..212a093a757e4a4698d8d29579fa41d3f7aa918e 100644 (file)
@@ -20,7 +20,7 @@ else()
     set(LANGUAGES C)
 endif()
 project(dbus
-    VERSION ${DBUS_VERSION}
+    VERSION ${DBUS_VERSION_NO_SUFFIX}
     LANGUAGES C CXX
 )
 
index d26617d2b2b45c538745d998b701ff785db031f8..152672e260e894e3f6630eea62e43b15cda9998f 100644 (file)
@@ -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)
index f6cc3676e21fa7b412e6a14d264fca576a686059..303f6e84705272047f3324338206151e3d46f343 100644 (file)
@@ -4,7 +4,7 @@ LIBDBUS_1_@SOVERSION@ {
   local:
     *;
 };
-LIBDBUS_PRIVATE_@DBUS_VERSION@ {
+LIBDBUS_PRIVATE_@DBUS_VERSION_NO_SUFFIX@ {
   global:
     _dbus_*;
 };
index 0f6c2e6d524be856a83c78caa392ad6755785e93..47140c7fa5e1c399613f67346a70e8465e03461d 100644 (file)
@@ -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().
  */
index bac82baa7e034fef4d3fd03297f6a24460e5d766..fd2ff7396e6fe2d133dd84c7e85027120e5e0a8e 100644 (file)
@@ -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))
index 6daa97c3553a3b12b13d702143325c6909b819bd..a6a54b91dc2439e5085e88b561e32ad2d18000e3 100644 (file)
@@ -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);