From 527bd4cdd0a19f0b9412a9924c9710cc4ec55dfc Mon Sep 17 00:00:00 2001 From: ubbo Date: Fri, 29 Mar 2013 02:49:47 +0000 Subject: add tools dir, including one tool for writing svn rev number to header, copied from http://qtcreator.blogspot.de/2010/01/code-to-generate-version-number-header.html git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@1030 34ebc366-c3a9-4b3c-9f84-69acf7962910 --- tools/version/version.cpp | 106 ++++++++++++++++++++++++++++++++++++++++++++++ tools/version/version.pro | 11 +++++ 2 files changed, 117 insertions(+) create mode 100644 tools/version/version.cpp create mode 100644 tools/version/version.pro diff --git a/tools/version/version.cpp b/tools/version/version.cpp new file mode 100644 index 0000000..d59d110 --- /dev/null +++ b/tools/version/version.cpp @@ -0,0 +1,106 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +static int getBuildNumber() +{ + const QDate today(QDate::currentDate()); + return ((today.year() - 1994) * 1000) + today.dayOfYear(); +} + +static int getSubversionRevision() +{ + int revision = 0; + QProcess process; + process.start("svnversion", QStringList() << "." << "--no-newline"); + if (process.waitForStarted() && process.waitForReadyRead()) + { + const QString str(process.readAll().constData()); + const int pos = str.indexOf(':'); + if (pos != -1) + { + revision = atoi(str.mid(pos + 1).toAscii().constData()); + } + else + { + revision = atoi(str.toAscii().constData()); + } + process.waitForFinished(); + } + return revision; +} + +static QByteArray readFile(const QString& fileName) +{ + QFile file(fileName); + if (!file.open(QIODevice::ReadOnly)) + { + return QByteArray(); + } + return file.readAll(); +} + +static int writeFile(const QString& fileName, const int major, const int minor, const int revision, const int build) +{ + // Create a temp file containing the version info and + // only replace the existing one if they are different + QTemporaryFile tempFile; + if (tempFile.open()) + { + QTextStream out(&tempFile); + out << "#ifndef VERSION_H\r\n"; + out << "#define VERSION_H\r\n\r\n"; + out << "namespace Version\r\n"; + out << "{\r\n"; + out << "\tstatic const int MAJOR = " << major << ";\r\n"; + out << "\tstatic const int MINOR = " << minor << ";\r\n"; + out << "\tstatic const int REVISION = " << revision << ";\r\n"; + out << "\tstatic const int BUILD = " << build << ";\r\n"; + out << "}\r\n\r\n"; + out << "#endif // VERSION_H\r\n"; + + const QString tempFileName = tempFile.fileName(); + tempFile.close(); + + if (!QFile::exists(fileName) || readFile(fileName) != readFile(tempFileName)) + { + QFile::remove(fileName); + QFile::copy(tempFileName, fileName); + } + + return 0; + } + else + { + cout << "Error creating temporary file!" << endl; + return 1; + } +} + +int main(int argc, char *argv[]) +{ + if (argc != 4) + { + cout << "Usage: version major minor filename" << endl; + return 1; + } + + const int major = atoi(argv[1]); + const int minor = atoi(argv[2]); + const int revision = getSubversionRevision(); + const int build = getBuildNumber(); + + cout << major << '.' << minor << '.' << revision << '.' << build << endl; + + return writeFile(argv[3], major, minor, revision, build); +} + diff --git a/tools/version/version.pro b/tools/version/version.pro new file mode 100644 index 0000000..bb1d7ed --- /dev/null +++ b/tools/version/version.pro @@ -0,0 +1,11 @@ +###################################################################### +# Automatically generated by qmake (2.01a) Fr. Mär 29 03:44:24 2013 +###################################################################### + +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . + +# Input +SOURCES += version.cpp -- cgit v1.2.3