Add version.sh to generate Git revsivion

This commit is contained in:
CalciteM Team 2019-08-18 08:37:18 +08:00
parent c0132b630e
commit 42ae1b7def
9 changed files with 59 additions and 25 deletions

View File

@ -0,0 +1 @@
static const char *versionNumber = "$FULL_VERSION";

1
NineChess/include/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
git_version.h

View File

@ -0,0 +1,8 @@
#ifndef VERSION_H
#define VERSION_H
// Please generate git_version.h with version.sh
#include "git_version.h"
#endif // VERSION_H

View File

@ -34,6 +34,7 @@ SOURCES += \
HEADERS += \
include/config.h \
include/version.h \
src/HashNode.h \
src/MemoryPool.h \
src/MemoryPool.tcc \

View File

@ -394,6 +394,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\config.h" />
<ClInclude Include="include\version.h" />
<ClInclude Include="resource.h" />
<QtMoc Include="src\aithread.h">
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\GeneratedFiles\$(ConfigurationName)\.;.\GeneratedFiles;.;$(QTDIR)\include;.\debug;\include;$(QTDIR)\mkspecs\win32-msvc;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtMultimedia;$(QTDIR)\include\QtNetwork</IncludePath>
@ -535,6 +536,7 @@
</ItemGroup>
<ItemGroup>
<None Include="..\Readme.md" />
<None Include="git_version.h.template" />
<None Include="ninechess.pro" />
<None Include="Resources\icon\ActualSizeHS.png" />
<None Include="Resources\icon\Black.png" />

View File

@ -131,6 +131,9 @@
<ClInclude Include="include\config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\version.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="debug\moc_predefs.h.cbt">
@ -269,6 +272,9 @@
<None Include="src\MemoryPool.tcc">
<Filter>Model</Filter>
</None>
<None Include="git_version.h.template">
<Filter>Header Files</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Text Include="..\History.txt">

View File

@ -48,6 +48,7 @@
#include "graphicsconst.h"
#include "server.h"
#include "client.h"
#include "version.h"
NineChessWindow::NineChessWindow(QWidget * parent) :
QMainWindow(parent),
@ -893,32 +894,44 @@ void NineChessWindow::on_actionAbout_A_triggered()
// 生成各个控件
QVBoxLayout *vLayout = new QVBoxLayout(dialog);
QHBoxLayout *hLayout = new QHBoxLayout;
QLabel *label_icon1 = new QLabel(dialog);
QLabel *label_icon2 = new QLabel(dialog);
//QLabel *label_icon1 = new QLabel(dialog);
//QLabel *label_icon2 = new QLabel(dialog);
QLabel *date_text = new QLabel(dialog);
QLabel *version_text = new QLabel(dialog);
QLabel *donate_text = new QLabel(dialog);
QLabel *label_text = new QLabel(dialog);
QLabel *label_image = new QLabel(dialog);
// 设置各个控件数据
label_icon1->setPixmap(QPixmap(QString::fromUtf8(":/image/resources/image/black_piece.png")));
label_icon2->setPixmap(QPixmap(QString::fromUtf8(":/image/resources/image/white_piece.png")));
label_icon1->setAlignment(Qt::AlignCenter);
label_icon2->setAlignment(Qt::AlignCenter);
label_icon1->setFixedSize(32, 32);
label_icon2->setFixedSize(32, 32);
label_icon1->setScaledContents(true);
label_icon2->setScaledContents(true);
//label_icon1->setPixmap(QPixmap(QString::fromUtf8(":/image/resources/image/black_piece.png")));
//label_icon2->setPixmap(QPixmap(QString::fromUtf8(":/image/resources/image/white_piece.png")));
//label_icon1->setAlignment(Qt::AlignCenter);
//label_icon2->setAlignment(Qt::AlignCenter);
//label_icon1->setFixedSize(32, 32);
//label_icon2->setFixedSize(32, 32);
//label_icon1->setScaledContents(true);
//label_icon2->setScaledContents(true);
date_text->setText(__DATE__);
version_text->setText(tr("Version:"));
label_text->setAlignment(Qt::AlignLeft);
label_text->setText(versionNumber);
label_text->setAlignment(Qt::AlignLeft);
donate_text->setText("Donate");
donate_text->setAlignment(Qt::AlignCenter);
label_text->setText(tr("Donate"));
label_text->setAlignment(Qt::AlignCenter);
label_image->setPixmap(QPixmap(QString::fromUtf8(":/image/resources/image/donate.png")));
label_image->setAlignment(Qt::AlignCenter);
label_image->setScaledContents(true);
// 布局
vLayout->addLayout(hLayout);
hLayout->addWidget(label_icon1);
hLayout->addWidget(label_icon2);
//hLayout->addWidget(label_icon1);
//hLayout->addWidget(label_icon2);
hLayout->addWidget(version_text);
hLayout->addWidget(label_text);
vLayout->addWidget(date_text);
vLayout->addWidget(donate_text);
vLayout->addWidget(label_image);
// 运行对话框

View File

@ -1,6 +0,0 @@
#ifudef VERSION_H
#define VERSION_H
#define VERSION_NUMBER $FULL_VERSION
#endif // VERSION_H

View File

@ -1,20 +1,24 @@
#!/bin/bash
rm -f include/version.h
VERSION_H=include/git_version.h
TEMPLATE_FILE=git_version.h.template
GIT_BRANCH=master
rm -f $VERSION_H
git rev-list HEAD | sort > config.git-hash
LOCALVER=`wc -l config.git-hash | awk '{print $1}'`
if [ $LOCALVER \> 1 ] ; then
VER=`git rev-list origin/master | sort | join config.git-hash - | wc -l | awk '{print $1}'`
VER=`git rev-list origin/$GIT_BRANCH | sort | join config.git-hash - | wc -l | awk '{print $1}'`
if [ $VER != $LOCALVER ] ; then
VER="$VER+$(($LOCALVER-$VER))"
fi
if git status | grep -q "modified:" ; then
VER="${VER}M"
fi
VER="$VER $(git rev-list HEAD -n 1 | cut -c 1-7)"
VER="$VER g$(git rev-list HEAD -n 1 | cut -c 1-7)"
GIT_VERSION=r$VER
else
GIT_VERSION=
@ -23,6 +27,10 @@ fi
rm -f config.git-hash
cat version.h.template | sed "s/\$FULL_VERSION/$GIT_VERSION/g" > include/version.h
cat $TEMPLATE_FILE | sed "s/\$FULL_VERSION/$GIT_VERSION/g" > $VERSION_H
echo "Generated $VERSION_H"
echo
cat $VERSION_H
echo "Generated version.h"