From f36d8e98512f31742ab5a32d560c8e4a89fc1e76 Mon Sep 17 00:00:00 2001 From: Emmanuel Engelhart Date: Wed, 29 Dec 2021 08:20:49 +0100 Subject: [PATCH] New kiwix::getVersions() and printVersions() --- include/kiwix.h | 2 +- include/meson.build | 3 +- include/version.h | 33 +++++++++++++++++++ src/meson.build | 3 +- src/version.cpp | 77 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 include/version.h create mode 100644 src/version.cpp diff --git a/include/kiwix.h b/include/kiwix.h index 16cd27b4a..0b5e8ac4a 100644 --- a/include/kiwix.h +++ b/include/kiwix.h @@ -22,4 +22,4 @@ #include "library.h" -#endif \ No newline at end of file +#endif diff --git a/include/meson.build b/include/meson.build index d19b159eb..50eabfbfa 100644 --- a/include/meson.build +++ b/include/meson.build @@ -14,7 +14,8 @@ headers = [ 'server.h', 'kiwixserve.h', 'name_mapper.h', - 'tools.h' + 'tools.h', + 'version.h' ] install_headers(headers, subdir:'kiwix') diff --git a/include/version.h b/include/version.h new file mode 100644 index 000000000..c0a21b584 --- /dev/null +++ b/include/version.h @@ -0,0 +1,33 @@ +/* + * Copyright 2021 Emmanuel Engelhart + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#ifndef KIWIX_VERSION_H +#define KIWIX_VERSION_H + +#include +#include + +namespace kiwix +{ + typedef std::vector> LibVersions; + LibVersions getVersions(); + void printVersions(std::ostream& out = std::cout); +} + +#endif // KIWIX_VERSION_H diff --git a/src/meson.build b/src/meson.build index 43f863e07..545d1bc99 100644 --- a/src/meson.build +++ b/src/meson.build @@ -28,7 +28,8 @@ kiwix_sources = [ 'server/response.cpp', 'server/internalServer.cpp', 'server/internalServer_catalog_v2.cpp', - 'opds_catalog.cpp' + 'opds_catalog.cpp', + 'version.cpp' ] kiwix_sources += lib_resources diff --git a/src/version.cpp b/src/version.cpp new file mode 100644 index 000000000..d804fc88e --- /dev/null +++ b/src/version.cpp @@ -0,0 +1,77 @@ +/* + * Copyright 2021 Emmanuel Engelhart + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace kiwix +{ + LibVersions getVersions() { + LibVersions versions = { + { "libkiwix", LIBKIWIX_VERSION }, + { "libzim", LIBZIM_VERSION }, + { "libxapian", XAPIAN_VERSION }, + { "libcurl", LIBCURL_VERSION }, + { "libmicrohttpd", MHD_get_version() }, + { "libz", ZLIB_VERSION } + }; + + // U_ICU_VERSION does not include the patch level if 0 + std::ostringstream libicu_version; + libicu_version << U_ICU_VERSION_MAJOR_NUM << "." << U_ICU_VERSION_MINOR_NUM << "." << U_ICU_VERSION_PATCHLEVEL_NUM; + versions.push_back({ "libicu", libicu_version.str() }); + + // No human readable version string for pugixml + const unsigned pugixml_major = (PUGIXML_VERSION - PUGIXML_VERSION % 1000) / 1000; + const unsigned pugixml_minor = (PUGIXML_VERSION - pugixml_major * 1000 - PUGIXML_VERSION % 10) / 10; + const unsigned pugixml_patch = PUGIXML_VERSION - pugixml_major * 1000 - pugixml_minor * 10; + std::ostringstream libpugixml_version; + libpugixml_version << pugixml_major << "." << pugixml_minor << "." << pugixml_patch; + versions.push_back({ "libpugixml", libpugixml_version.str() }); + + // Needs version 5.0 of Mustache +#if defined(KAINJOW_MUSTACHE_VERSION_MAJOR) + std::ostringstream libmustache_version; + libmustache_version << KAINJOW_MUSTACHE_VERSION_MAJOR << "." << + KAINJOW_MUSTACHE_VERSION_MINOR << "." << KAINJOW_MUSTACHE_VERSION_PATCH; + versions.push_back({ "libmustache", libmustache_version.str() }); +#endif + + return versions; + } + + void printVersions(std::ostream& out) { + LibVersions versions = getVersions(); + for (const auto& iter : versions) { + out << (iter != versions.front() ? "+ " : "") + << iter.first << " " << iter.second << std::endl; + } + } +} //namespace kiwix