From be23f54914abc09b65bbf4bbdd07bb9b80710a26 Mon Sep 17 00:00:00 2001 From: Konstantin Isakov Date: Fri, 2 Jul 2010 21:07:05 +0400 Subject: [PATCH] Generate the exact version string via Git. --- goldendict.pro | 19 +++++++++++++++++++ mainwindow.cc | 11 ++++++++++- resources.qrc | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/goldendict.pro b/goldendict.pro index 59f6e353..df319649 100644 --- a/goldendict.pro +++ b/goldendict.pro @@ -5,6 +5,18 @@ TEMPLATE = app TARGET = goldendict VERSION = 0.9.0+git +# Generate version file. We do this here and in a build rule described later. +# The build rule is required since qmake isn't run each time the project is +# rebuilt; and doing it here is required too since any other way the RCC +# compiler would complain if version.txt wouldn't exist (fresh checkouts). + +system(git describe --tags --always --dirty > version.txt): hasGit=1 + +isEmpty( hasGit ) { + message(Failed to precisely describe the version via Git -- using the default version string) + system(echo $$VERSION > version.txt) +} + # DEPENDPATH += . generators INCLUDEPATH += . QT += webkit @@ -241,6 +253,13 @@ TRANSLATIONS += locale/ru_RU.ts \ locale/lt_LT.ts \ locale/uk_UA.ts +# Build version file +QMAKE_EXTRA_TARGETS += revtarget +PRE_TARGETDEPS += version.txt +revtarget.target = version.txt +revtarget.commands = git describe --tags --always --dirty > $$revtarget.target +revtarget.depends = $$SOURCES $$HEADERS $$FORMS + # This makes qmake generate translations win32:# Windows doesn't seem to have *-qt4 symlinks isEmpty(QMAKE_LRELEASE):QMAKE_LRELEASE = $$[QT_INSTALL_BINS]/lrelease diff --git a/mainwindow.cc b/mainwindow.cc index af782641..0244d5f0 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -1614,7 +1614,16 @@ void MainWindow::showAbout() ui.setupUi( &about ); - ui.version->setText( PROGRAM_VERSION ); + QFile versionFile( ":/version.txt" ); + + QString version; + + if ( !versionFile.open( QFile::ReadOnly ) ) + version = tr( "[Unknown]" ); + else + version = QString::fromAscii( versionFile.readAll() ).trimmed(); + + ui.version->setText( version ); about.show(); about.exec(); diff --git a/resources.qrc b/resources.qrc index 9f4081e2..b408048a 100644 --- a/resources.qrc +++ b/resources.qrc @@ -1,5 +1,6 @@ + version.txt icons/print.png icons/arrow.png icons/prefix.png