From e9aa6e953243848a5f8acf5958d7c6fd5e68339d Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Mon, 24 Jul 2023 18:28:59 +0200 Subject: [PATCH] Use proper code for version info, add git info in cmake. Fixes #205 --- CMakeLists.txt | 35 ++++++++++++++++++++++++++++++++++- src/CMakeLists.txt | 2 ++ src/archiveman.cpp | 2 +- src/documenttemplate.cpp | 6 +++--- src/kraftdb.cpp | 2 +- src/main.cpp | 2 +- src/portalview.cpp | 22 ++++++++++++++++++---- src/version.h | 6 ------ src/version.h.in | 21 +++++++++++++++++++++ views/systemviewdetails.thtml | 6 ++++++ 10 files changed, 87 insertions(+), 17 deletions(-) delete mode 100644 src/version.h create mode 100644 src/version.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 82b4e078..92bef058 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ project(kraft) -cmake_minimum_required(VERSION 2.8.12) +cmake_minimum_required(VERSION 3.16.0) cmake_policy(SET CMP0063 NEW) find_package(ECM REQUIRED NO_MODULE) @@ -17,6 +17,39 @@ if (AKONADI_LEGACY_BUILD) endif() message("Akonadi Prefix is ${AKO_PREFIX}") +include(GetGitRevisionDescription) + +# set git revision info +get_git_head_revision(GIT_REFSPEC GIT_SHA1) +# if we cannot get it from git, directly try .tag (packages) +# this will work if the tar balls have been properly created +# via git-archive. +if ("${GIT_SHA1}" STREQUAL "GITDIR-NOTFOUND") + file(READ ${CMAKE_SOURCE_DIR}/.tag sha1_candidate) + string(REPLACE "\n" "" sha1_candidate ${sha1_candidate}) + if (NOT ${sha1_candidate} STREQUAL "$Format:%H$") + message("${sha1_candidate}") + set (GIT_SHA1 "${sha1_candidate}") + endif() +endif() + +message(STATUS "Git dynamic information") +message("GIT_SHA1: ${GIT_SHA1}") + +execute_process( + COMMAND git rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE +) +message("GIT_BRANCH: ${GIT_BRANCH}") + +cmake_host_system_information(RESULT BUILD_HOST_NAME QUERY HOSTNAME) +cmake_host_system_information(RESULT BUILD_HOST_DISTRI QUERY DISTRIB_PRETTY_NAME) +message("Build host name: ${BUILD_HOST_NAME}") +message("Build host distribution: ${BUILD_HOST_DISTRI}") + + include(KDEInstallDirs) include(KDECMakeSettings) include(ECMInstallIcons) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8e9b0696..e4468390 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,8 @@ include_directories(${QT_INCLUDES} src) add_subdirectory(pics) +configure_file(${CMAKE_CURRENT_LIST_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h @ONLY) + ########### next target ############### qt5_add_resources(KRAFT_RC_SRC pics/kraft.qrc) diff --git a/src/archiveman.cpp b/src/archiveman.cpp index 35ee45d6..be806998 100644 --- a/src/archiveman.cpp +++ b/src/archiveman.cpp @@ -128,7 +128,7 @@ QDomDocument ArchiveMan::archiveDocumentXml( KraftDoc *doc, const QString& archI { QDomDocument xmldoc( "kraftdocument" ); QDomElement root = xmldoc.createElement( "kraftdocument" ); - root.setAttribute(QStringLiteral("kraft_version"), QStringLiteral(KRAFT_VERSION)); + root.setAttribute(QStringLiteral("kraft_version"), Kraft::Version::number()); xmldoc.appendChild( root ); QDomElement cust = xmldoc.createElement( "client" ); diff --git a/src/documenttemplate.cpp b/src/documenttemplate.cpp index f864f1c9..8e39677c 100644 --- a/src/documenttemplate.cpp +++ b/src/documenttemplate.cpp @@ -141,11 +141,11 @@ QVariantHash labelVariantHash() QVariantHash kraftVariantHash() { QVariantHash hash; - QString h = QString("Kraft %1 %2").arg(KRAFT_VERSION). - arg(KRAFT_CODENAME); + QString h = QString("Kraft %1 %2").arg(Kraft::Version::number()). + arg(Kraft::Version::codeName()); hash.insert(TAG("VERSION"), h); - h = QString("DB-Scheme %1").arg(KRAFT_REQUIRED_SCHEMA_VERSION); + h = QString("DB-Scheme %1").arg(Kraft::Version::dbSchemaVersion()); hash.insert(TAG("DB_SCHEME"), h); h = qgetenv("USER"); diff --git a/src/kraftdb.cpp b/src/kraftdb.cpp index 21302922..12f7c16e 100644 --- a/src/kraftdb.cpp +++ b/src/kraftdb.cpp @@ -512,7 +512,7 @@ int KraftDB::processSqlCommands( const SqlCommandList& commands ) int KraftDB::requiredSchemaVersion() { - return KRAFT_REQUIRED_SCHEMA_VERSION; + return Kraft::Version::dbSchemaVersion(); } int KraftDB::currentSchemaVersion() diff --git a/src/main.cpp b/src/main.cpp index e9529779..ae628364 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,7 +45,7 @@ int main(int argc, char *argv[]) app.setWindowIcon(QIcon(":/kraft/custom-icons/kraft-simple.svg")); app.setApplicationName("kraft"); app.setApplicationDisplayName("Kraft"); - app.setApplicationVersion(QString("version %1").arg(KRAFT_VERSION)); + app.setApplicationVersion(QString("version %1").arg(Kraft::Version::number())); const QString path = QCoreApplication::applicationDirPath()+ QStringLiteral("/../share/locale"); qDebug() << "Setting additional Locale path:" << path; diff --git a/src/portalview.cpp b/src/portalview.cpp index 81d49d01..9e3160e2 100644 --- a/src/portalview.cpp +++ b/src/portalview.cpp @@ -287,9 +287,23 @@ QString PortalView::systemView( const QString& htmlMsg ) const tmpl.setValue("KRAFT_INTRO_DESC", i18n("Kraft helps you to handle documents like quotes and invoices in your small business.")); tmpl.setValue( "KRAFT_WELCOME_LABEL", i18n( "Welcome to Kraft" ) ); tmpl.setValue( "KRAFT_VERSION_LABEL", i18n( "Kraft Version" ) ); - tmpl.setValue( "KRAFT_VERSION", KRAFT_VERSION ); + tmpl.setValue( "KRAFT_VERSION", Kraft::Version::number()); tmpl.setValue( "KRAFT_CODENAME_LABEL", i18n( "Codename" ) ); - tmpl.setValue( "KRAFT_CODENAME", KRAFT_CODENAME ); + tmpl.setValue( "KRAFT_CODENAME", Kraft::Version::codeName() ); + + // string like + // git sha on branch built on () + tmpl.setValue( "GIT_BRANCH", Kraft::Version::gitBranch()); + tmpl.setValue( "GIT_SHA1", Kraft::Version::gitSha()); + tmpl.setValue( "BUILD_HOST", Kraft::Version::buildHost()); + tmpl.setValue( "BUILD_HOST_DISTRO", Kraft::Version::buildHostDistro()); + tmpl.setValue( "GIT_BUILD_LABEL", i18n("Git Information")); + tmpl.setValue( "GIT_BUILD_STRING", QString("git sha %1 on branch %2 built on %3 (%4)") + .arg(Kraft::Version::gitSha()) + .arg(Kraft::Version::gitBranch()) + .arg(Kraft::Version::buildHost()) + .arg(Kraft::Version::buildHostDistro())); + const QString countryName = DefaultProvider::self()->locale()->nativeCountryName(); tmpl.setValue( "COUNTRY_SETTING_LABEL", i18n( "Country Setting" ) ); tmpl.setValue( "COUNTRY_SETTING", QString( "%1 (%2)" ).arg( countryName ).arg( DefaultProvider::self()->locale()->country() )); @@ -311,9 +325,9 @@ QString PortalView::systemView( const QString& htmlMsg ) const tmpl.setValue( "DATABASE_NAME", KraftDB::self()->databaseName() ); QString schemaVersion = QString::number( KraftDB::self()->currentSchemaVersion() ); - if ( KraftDB::self()->currentSchemaVersion() != KRAFT_REQUIRED_SCHEMA_VERSION ) { + if ( KraftDB::self()->currentSchemaVersion() != Kraft::Version::dbSchemaVersion() ) { schemaVersion += " - " + QString( "%1: %2" ).arg( i18n ( "Required Version" )) - .arg( KRAFT_REQUIRED_SCHEMA_VERSION ); + .arg( Kraft::Version::dbSchemaVersion() ); } tmpl.setValue( "DATABASE_SCHEMA_VERSION_LABEL", i18n( "Database schema version" ) ); tmpl.setValue( "DATABASE_SCHEMA_VERSION", schemaVersion ); diff --git a/src/version.h b/src/version.h deleted file mode 100644 index 2ebf4d48..00000000 --- a/src/version.h +++ /dev/null @@ -1,6 +0,0 @@ -#define KRAFT_VERSION "1.0" - -#define KRAFT_CODENAME "Lyonel" - -#define KRAFT_REQUIRED_SCHEMA_VERSION 24 - diff --git a/src/version.h.in b/src/version.h.in new file mode 100644 index 00000000..f3abcf36 --- /dev/null +++ b/src/version.h.in @@ -0,0 +1,21 @@ +#pragma once + +namespace Kraft::Version { + + // Static content. Maintain values here. + inline QString number() { return QStringLiteral("1.1"); } + + inline QString codeName() { return QStringLiteral("Lynoel"); } + inline int dbSchemaVersion() { return 24; } + + // dynamic content. These values get defined at build time in the top CMakeLists.txt + inline QString gitSha() { return QStringLiteral("@GIT_SHA1@"); } + + inline QString gitBranch() { return QStringLiteral("@GIT_BRANCH@"); } + + inline QString buildHost() { return QStringLiteral("@BUILD_HOST_NAME@"); } + + inline QString buildHostDistro() { return QStringLiteral("@BUILD_HOST_DISTRI@"); } + +} + diff --git a/views/systemviewdetails.thtml b/views/systemviewdetails.thtml index f308bb0c..52b25194 100644 --- a/views/systemviewdetails.thtml +++ b/views/systemviewdetails.thtml @@ -37,6 +37,12 @@ + + {{GIT_BUILD_LABEL}}: + {{GIT_BUILD_STRING}} + + + {{COUNTRY_SETTING_LABEL}}: {{COUNTRY_SETTING}}