Commit 31702179 authored by Victor Yacovlev's avatar Victor Yacovlev

PROJECT: Fixed updating GIT timestamp/tag/branch/hash on each CMake run

parent dd12edfd
#!/usr/bin/env python
import sys
import os.path
import os
from subprocess import Popen, PIPE
GIT = "git"
if os.name=="nt":
PATH = os.environ["PATH"].split(";")
for entry in PATH:
if os.path.exists(entry+"/git.cmd"):
GIT = entry+"/../bin/git.exe"
break
OUT = sys.stdout
CWD = "."
for arg in sys.argv:
if arg.startswith("--git="):
GIT = arg[6:]
if arg.startswith("--out="):
if os.path.exists(arg[6:]):
sys.exit(0) # for faster re-build
OUT = open(arg[6:], "w")
if arg.startswith("--root="):
CWD = arg[7:]
COMMAND = "$GIT --no-pager show".replace("$GIT", GIT)
BCOMMAND = "$GIT branch".replace("$GIT", GIT)
try:
process = Popen(COMMAND.split(), stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=CWD)
except:
sys.stderr.write("Warning: can't run GIT to get version info: "+COMMAND+"\n")
OUT.close()
sys.exit(0)
out, err = process.communicate()
err = err.strip()
sys.stderr.write(err)
if not err:
lines = out.split("\n")
for line in lines:
if line.startswith("commit "):
GIT_HASH = line[7:].strip()
OUT.write("#define GIT_HASH \""+GIT_HASH+"\"\n")
if line.startswith("Date: "):
DATE = line[6:].strip()
OUT.write("#define GIT_LAST_MODIFIED \""+DATE+"\"\n")
try:
process = Popen(BCOMMAND.split(), stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=CWD)
except:
OUT.close()
sys.exit(0)
out, err = process.communicate()
err = err.strip()
sys.stderr.write(err)
if not err:
lines = out.split("\n")
for line in lines:
if line.startswith("*"):
BRANCH = line[1:].strip()
OUT.write("#define GIT_BRANCH \""+BRANCH+"\"\n")
OUT.close()
\ No newline at end of file
......@@ -43,10 +43,50 @@ if(XCODE)
endif(XCODE)
add_custom_target(
GitInfoHeader ALL
${CMAKE_SOURCE_DIR}/scripts/git_info.py --out=${CMAKE_CURRENT_BINARY_DIR}/GITINFO.h --root=${CMAKE_SOURCE_DIR}
)
if(EXISTS(version_info.cmake))
include(version_info.cmake)
else()
set(GIT_HASH unknown)
set(GIT_TIMESTAMP unknown)
set(GIT_BRANCH unknown)
set(GIT_TAG unknown)
find_program(GIT git)
if(GIT)
execute_process(
COMMAND ${GIT} --no-pager show --pretty=format:%H
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_HASH
)
execute_process(
COMMAND ${GIT} tag
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_TAG
)
execute_process(
COMMAND ${GIT} --no-pager show --pretty=format:%ct
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_TIMESTAMP
)
execute_process(
COMMAND ${GIT} rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
)
string(STRIP "${GIT_BRANCH}" GIT_BRANCH)
string(STRIP "${GIT_HASH}" GIT_HASH)
string(STRIP "${GIT_TAG}" GIT_TAG)
string(STRIP "${GIT_TIMESTAMP}" GIT_TIMESTAMP)
else()
message(WARNING "git not found and no version info provided")
endif()
add_definitions(-DGIT_HASH=\"${GIT_HASH}\")
add_definitions(-DGIT_TIMESTAMP=${GIT_TIMESTAMP})
add_definitions(-DGIT_TAG=\"${GIT_TAG}\")
add_definitions(-DGIT_BRANCH=\"${GIT_BRANCH}\")
endif()
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
......
#ifndef VERSION_H
#define VERSION_H
#define VERSION_MAJOR 2
#define VERSION_MINOR 0
#define VERSION_RELEASE 0
#endif
#include <QtCore>
#include <QtGui>
#include "VERSION.h"
#include "GITINFO.h"
#include "extensionsystem/pluginmanager.h"
#ifdef Q_OS_MAC
......@@ -84,6 +81,7 @@ public:
: QApplication(argc, argv, gui)
, timerId_(-1)
, splashScreen_(nullptr)
, started_(false)
{}
inline bool notify(QObject * receiver, QEvent * event) {
bool result = false;
......@@ -103,6 +101,10 @@ public:
}
inline void initialize() {
if (started_) {
return;
}
started_ = true;
bool gui = true;
#ifdef Q_WS_X11
gui = gui && getenv("DISPLAY")!=0;
......@@ -188,8 +190,7 @@ public:
}
}
inline void timerEvent(QTimerEvent * event) {
killTimer(timerId_);
inline void timerEvent(QTimerEvent * event) {
event->accept();
initialize();
}
......@@ -197,6 +198,7 @@ public:
inline int main() {
timerId_ = startTimer(250);
int ret = exec();
killTimer(timerId_);
if (ret == 0) {
return property("returnCode").isValid()
? property("returnCode").toInt() : 0;
......@@ -208,10 +210,17 @@ public:
private:
int timerId_;
QSplashScreen * splashScreen_;
bool started_;
};
int main(int argc, char **argv)
{
QString gitHash = QString::fromAscii(GIT_HASH);
QString gitTag = QString::fromAscii(GIT_TAG);
QString gitBranch = QString::fromAscii(GIT_BRANCH);
QDateTime gitTimeStamp = QDateTime::fromTime_t(GIT_TIMESTAMP);
bool gui = true;
#ifdef Q_WS_X11
gui = gui && getenv("DISPLAY")!=0;
......@@ -220,35 +229,15 @@ int main(int argc, char **argv)
QLocale russian = QLocale("ru_RU");
QLocale::setDefault(russian);
#ifdef Q_OS_WIN32
// app->setAttribute(Qt::AA_DontShowIconsInMenus);
app->addLibraryPath(app->applicationDirPath());
#endif
#ifdef Q_OS_MAC
// app->setAttribute(Qt::AA_DontUseNativeMenuBar, true);
#endif
#ifndef Q_OS_WIN32
app->addLibraryPath(QDir::cleanPath(app->applicationDirPath()+"/../"+IDE_LIBRARY_BASENAME+"/kumir2/"));
#endif
#ifdef GIT_BRANCH
static const QString branch = QString::fromAscii(GIT_BRANCH);
#else
static const QString branch = QString::fromAscii("release");
#endif
app->setApplicationVersion(QString("%1.%2.%3-%4")
.arg(VERSION_MAJOR)
.arg(VERSION_MINOR)
.arg(VERSION_RELEASE)
.arg(branch));
#ifdef GIT_HASH
app->setProperty("gitHash", QString::fromAscii(GIT_HASH));
#endif
#ifdef GIT_LAST_MODIFIED
app->setProperty("lastModified", QString::fromAscii(GIT_LAST_MODIFIED));
#endif
app->setApplicationVersion(gitTag.length() > 0
? gitTag : gitBranch + "/" + gitHash);
app->setProperty("gitTimeStamp", gitTimeStamp);
QSplashScreen * splashScreen = 0;
const QString sharePath = QDir(app->applicationDirPath()+SHARE_PATH).canonicalPath();
......
......@@ -14,10 +14,10 @@ AboutDialog::AboutDialog(QWidget *parent) :
ui->setupUi(this);
ui->version->setText(qApp->applicationVersion());
if (qApp->property("gitHash").isValid())
ui->gitHash->setText(qApp->property("gitHash").toString());
if (qApp->property("lastModified").isValid())
ui->lastModified->setText(qApp->property("lastModified").toString());
if (qApp->property("gitTimeStamp").isValid()) {
QDateTime timeStamp = qApp->property("gitTimeStamp").toDateTime();
ui->lastModified->setText(timeStamp.toString());
}
ui->tableWidget->setColumnCount(2);
ui->tableWidget->setColumnWidth(1, 1000);
......@@ -36,7 +36,6 @@ void AboutDialog::copySystemInformationToClipboard()
{
QString textToCopy;
textToCopy += "Version: "+ui->version->text()+"\n";
textToCopy += "Git: "+ui->gitHash->text() + "\n";
for (int i=0; i<ui->tableWidget->rowCount(); i++) {
const QString key = ui->tableWidget->item(i, 0)->text();
const QString value = ui->tableWidget->item(i, 1)->text();
......
......@@ -41,23 +41,6 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>GIT hash:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="gitHash">
<property name="text">
<string>unknown</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
......@@ -175,7 +158,6 @@ p, li { white-space: pre-wrap; }
<tabstop>btnCopyEnvironmentAndVersion</tabstop>
<tabstop>tabWidget</tabstop>
<tabstop>version</tabstop>
<tabstop>gitHash</tabstop>
<tabstop>lastModified</tabstop>
<tabstop>textBrowser</tabstop>
<tabstop>tableWidget</tabstop>
......
......@@ -803,7 +803,7 @@ void AnalizerPrivate::doCompilation(AnalizeSubject whatToCompile
, int whereInserted
)
{
if (qApp->applicationVersion()<"2.1.0-release")
// if (qApp->applicationVersion()<"2.1.0-release")
whatToCompile = SubjWholeText; // Not tested well yet
foreach (Statement * st, oldStatements) {
foreach (AST::Variable * var, st->variables) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment