Skip to content

Commit

Permalink
Add better versioning info.
Browse files Browse the repository at this point in the history
  • Loading branch information
adtreat committed Mar 22, 2019
1 parent cfcd2be commit 0003aaf
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 7 deletions.
15 changes: 15 additions & 0 deletions lib/git.pri
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Need to discard STDERR so get path to NULL device
win32 {
NULL_DEVICE = NUL # Windows doesn't have /dev/null but has NUL
} else {
NULL_DEVICE = /dev/null
}

# Need to call git with manually specified paths to repository
BASE_GIT_COMMAND = git --git-dir $$PWD/../.git rev-parse --short HEAD

# Get the short git sha
GIT_SHA = $$system($$BASE_GIT_COMMAND 2> $$NULL_DEVICE)

# Adding C preprocessor #DEFINE so we can use it in C++ code
DEFINES += GIT_SHA=\\\"$$GIT_SHA\\\"
43 changes: 43 additions & 0 deletions lib/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
This file is part of Allie Chess.
Copyright (C) 2018, 2019 Adam Treat
Allie Chess is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Allie Chess is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Allie Chess. If not, see <http://www.gnu.org/licenses/>.
Additional permission under GNU GPL version 3 section 7
*/

#ifndef VERSION_H
#define VERSION_H

#include <QString>

static int s_majorVersion = 0;
static int s_minorVersion = 2;
static bool s_isDev = true;

static QString versionString()
{
const QString maj = QString::number(s_majorVersion);
const QString min = QString::number(s_minorVersion);
#if defined(GIT_SHA)
const QString git = QString("(%0)").arg(GIT_SHA);
#else
const QString git = QString();
#endif
const QString dev = s_isDev ? QLatin1String("-dev") : QLatin1String("");
return QString("v%0.%1%2 %3").arg(maj).arg(min).arg(dev).arg(git);
}

#endif // VERSION_H
9 changes: 6 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@
#include "options.h"
#include "searchengine.h"
#include "uciengine.h"
#include "version.h"
#include "zobrist.h"

#define APP_NAME "Allie"
#define APP_VERSION "0.2"

int main(int argc, char *argv[])
{
qInstallMessageHandler(g_uciMessageHandler);

QCoreApplication a(argc, argv);
a.setApplicationName(APP_NAME);
a.setApplicationVersion(APP_VERSION);
a.setApplicationVersion(versionString());
a.setOrganizationName("Adam Treat");

QCommandLineParser parser;
Expand Down Expand Up @@ -75,7 +75,10 @@ int main(int argc, char *argv[])
" / _` | | | |/ _ \\\n"
"| (_| | | | | __/ \n"
" \\__,_|_|_|_|\\___|");
fprintf(stderr, "%s %s uci chess engine\n", ascii.toLatin1().constData(), APP_VERSION);
fprintf(stderr, "%s %s built on %s at %s\n", ascii.toLatin1().constData(),
QString("%0").arg(a.applicationVersion()).toLatin1().constData(),
QString("%0").arg(__DATE__).toLatin1().constData(),
QString("%0").arg(__TIME__).toLatin1().constData());

Zobrist::globalInstance();
Movegen::globalInstance();
Expand Down
5 changes: 5 additions & 0 deletions src/src.pro
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ DESTDIR=../bin
QT -= gui network
CONFIG += c++14 console

include($$PWD/../lib/git.pri)

CONFIG(release, debug|release) {
CONFIG += optimize_full
}
Expand All @@ -18,6 +20,9 @@ DEFINES += QT_DEPRECATED_WARNINGS

INCLUDEPATH += $$PWD/../lib

HEADERS += \
$$PWD/../lib/version.h

SOURCES += \
main.cpp

Expand Down
11 changes: 7 additions & 4 deletions tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@
#include "nn.h"
#include "options.h"
#include "testgames.h"
#include "version.h"
#include "zobrist.h"

#define APP_NAME "Allie"
#define APP_NAME "AllieTests"

int main(int argc, char* argv[])
{
QCoreApplication app(argc, argv);
app.setApplicationName(APP_NAME);
QCoreApplication a(argc, argv);
a.setApplicationName(APP_NAME);
a.setApplicationVersion(versionString());

Options::globalInstance()->setOption("SyzygyPath", QCoreApplication::applicationDirPath() + QDir::separator() + "../../syzygy/");
Options::globalInstance()->setOption("SyzygyPath",
QCoreApplication::applicationDirPath() + QDir::separator() + "../../syzygy/");

int rc = 0;
TestGames test1;
Expand Down
3 changes: 3 additions & 0 deletions tests/tests.pro
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ QT += testlib
QT -= gui network
CONFIG += c++14 console

include($$PWD/../lib/git.pri)

CONFIG(release, debug|release) {
CONFIG += optimize_full
}
Expand All @@ -21,6 +23,7 @@ INCLUDEPATH += $$PWD/../lib

HEADERS += \
testgames.h
$$PWD/../lib/version.h

SOURCES += \
main.cpp \
Expand Down

0 comments on commit 0003aaf

Please sign in to comment.