diff options
author | ubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2013-03-29 02:49:47 +0000 |
---|---|---|
committer | ubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2013-03-29 02:49:47 +0000 |
commit | 527bd4cdd0a19f0b9412a9924c9710cc4ec55dfc (patch) | |
tree | d258002bf3620d451c5aca7905ff5ae560a3c94b | |
parent | updated TODO (diff) | |
download | gpg4usb-527bd4cdd0a19f0b9412a9924c9710cc4ec55dfc.tar.gz gpg4usb-527bd4cdd0a19f0b9412a9924c9710cc4ec55dfc.zip |
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
-rw-r--r-- | tools/version/version.cpp | 106 | ||||
-rw-r--r-- | tools/version/version.pro | 11 |
2 files changed, 117 insertions, 0 deletions
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 <iostream> +#include <QProcess> +#include <QStringList> +#include <QFile> +#include <QTextStream> +#include <QDate> +#include <QTime> +#include <QFileInfo> +#include <QTemporaryFile> +#include <cstdlib> + +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 |