From cb05a5278089269ff92145a3df42912b08bac838 Mon Sep 17 00:00:00 2001 From: Arvin Schnell Date: Thu, 14 Sep 2023 16:47:17 +0200 Subject: [PATCH] - show snapper and libsnapper versions --- LIBVERSION | 2 +- client/snapper.cc | 9 +++++++-- configure.ac | 1 + snapper/Makefile.am | 2 +- snapper/Snapper.cc | 4 +++- snapper/Version.cc | 35 +++++++++++++++++++++++++++++++++++ snapper/Version.h.in | 21 ++++++++++++++++++--- 7 files changed, 66 insertions(+), 8 deletions(-) create mode 100644 snapper/Version.cc diff --git a/LIBVERSION b/LIBVERSION index a8a18875..0ee843cc 100644 --- a/LIBVERSION +++ b/LIBVERSION @@ -1 +1 @@ -7.1.2 +7.2.0 diff --git a/client/snapper.cc b/client/snapper.cc index 3ddebe1e..0f8e532a 100644 --- a/client/snapper.cc +++ b/client/snapper.cc @@ -23,13 +23,14 @@ #include "config.h" -#include -#include +#include +#include #include #include #include #include +#include #include "utils/text.h" #include "utils/Table.h" @@ -178,6 +179,10 @@ main(int argc, char** argv) if (global_options.version()) { cout << "snapper " << Snapper::compileVersion() << endl; + cout << "libsnapper " << LIBSNAPPER_VERSION_STRING; + if (strcmp(LIBSNAPPER_VERSION_STRING, get_libversion_string()) != 0) + cout << " (" << get_libversion_string() << ")"; + cout << '\n'; cout << "flags " << Snapper::compileFlags() << endl; exit(EXIT_SUCCESS); } diff --git a/configure.ac b/configure.ac index 30be7b9c..fbb0e103 100644 --- a/configure.ac +++ b/configure.ac @@ -188,6 +188,7 @@ fi AC_CHECK_HEADER(acl/libacl.h,[],[AC_MSG_ERROR([Cannout find libacl headers. Please install libacl-devel])]) AC_SUBST(VERSION) +AC_SUBST(LIBVERSION) AC_SUBST(LIBVERSION_MAJOR) AC_SUBST(LIBVERSION_MINOR) AC_SUBST(LIBVERSION_PATCHLEVEL) diff --git a/snapper/Makefile.am b/snapper/Makefile.am index 383b45eb..a03beceb 100644 --- a/snapper/Makefile.am +++ b/snapper/Makefile.am @@ -31,7 +31,7 @@ libsnapper_la_SOURCES = \ SnapperTmpl.h \ SnapperTypes.h \ SnapperDefines.h \ - Version.h + Version.cc Version.h if ENABLE_BTRFS libsnapper_la_SOURCES += \ diff --git a/snapper/Snapper.cc b/snapper/Snapper.cc index 9504b050..8375178e 100644 --- a/snapper/Snapper.cc +++ b/snapper/Snapper.cc @@ -48,6 +48,7 @@ #include "snapper/Hooks.h" #include "snapper/ComparisonImpl.h" #include "snapper/Systemctl.h" +#include "snapper/Version.h" #ifdef ENABLE_BTRFS #include "snapper/Btrfs.h" #include "snapper/BtrfsUtils.h" @@ -94,7 +95,8 @@ namespace snapper : snapshots(this) { y2mil("Snapper constructor"); - y2mil("libsnapper version " VERSION); + y2mil("snapper version " VERSION); + y2mil("libsnapper version " LIBSNAPPER_VERSION_STRING); y2mil("config_name:" << config_name << " root_prefix:" << root_prefix << " disable_filters:" << disable_filters); diff --git a/snapper/Version.cc b/snapper/Version.cc new file mode 100644 index 00000000..cff47a04 --- /dev/null +++ b/snapper/Version.cc @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 SUSE LLC + * + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, contact Novell, Inc. + * + * To contact Novell about this file by physical or electronic mail, you may + * find current contact information at www.novell.com. + */ + + +#include "snapper/Version.h" + + +namespace snapper +{ + + const char* + get_libversion_string() + { + return LIBSNAPPER_VERSION_STRING; + } + +} diff --git a/snapper/Version.h.in b/snapper/Version.h.in index b92b6c50..f7be4f27 100644 --- a/snapper/Version.h.in +++ b/snapper/Version.h.in @@ -1,5 +1,6 @@ /* * Copyright (c) 2013 Novell, Inc. + * Copyright (c) 2023 SUSE LLC * * All Rights Reserved. * @@ -24,13 +25,27 @@ #define SNAPPER_VERSION_H +#define LIBSNAPPER_VERSION_STRING "@LIBVERSION@" + #define LIBSNAPPER_MAJOR "@LIBVERSION_MAJOR@" #define LIBSNAPPER_MINOR "@LIBVERSION_MINOR@" #define LIBSNAPPER_PATCHLEVEL "@LIBVERSION_PATCHLEVEL@" -#define LIBSNAPPER_VERSION ( LIBSNAPPER_MAJOR * 10000 + \\ - LIBSNAPPER_MINOR * 100 + \\ - LIBSNAPPER_PATCHLEVEL ) +#define LIBSNAPPER_VERSION_AT_LEAST(major, minor) \ + ((LIBSNAPPER_VERSION_MAJOR > (major)) || \ + (LIBSNAPPER_VERSION_MAJOR == (major) && LIBSNAPPER_VERSION_MINOR >= (minor))) + + +namespace snapper +{ + + /** + * Return LIBSNAPPER_VERSION_STRING libsnapper was compiled with. May differ + * from the define (compile time vs. link time). + */ + const char* get_libversion_string(); + +} #endif -- 2.47.3