Skip to content

Commit

Permalink
Use proper code for version info, add git info in cmake.
Browse files Browse the repository at this point in the history
Fixes #205
  • Loading branch information
dragotin committed Jul 24, 2023
1 parent a412524 commit e9aa6e9
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 17 deletions.
35 changes: 34 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/archiveman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down
6 changes: 3 additions & 3 deletions src/documenttemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/kraftdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 18 additions & 4 deletions src/portalview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sha> on branch <branch> built on <host> (<distro>)
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() ));
Expand All @@ -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( "<font color='red'>%1: %2</font>" ).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 );
Expand Down
6 changes: 0 additions & 6 deletions src/version.h

This file was deleted.

21 changes: 21 additions & 0 deletions src/version.h.in
Original file line number Diff line number Diff line change
@@ -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@"); }

}

6 changes: 6 additions & 0 deletions views/systemviewdetails.thtml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
<td></td>
</tr>

<tr>
<td class="label">{{GIT_BUILD_LABEL}}:</td>
<td class="value">{{GIT_BUILD_STRING}}</i></td>
<td></td>
</tr>

<tr>
<td class="label">{{COUNTRY_SETTING_LABEL}}:</td>
<td class="value"><i>{{COUNTRY_SETTING}}</i></td>
Expand Down

0 comments on commit e9aa6e9

Please sign in to comment.