From 42ae1b7def6188bd9c2733d7e25be3c7a0aae182 Mon Sep 17 00:00:00 2001 From: CalciteM Team Date: Sun, 18 Aug 2019 08:37:18 +0800 Subject: [PATCH] Add version.sh to generate Git revsivion --- NineChess/git_version.h.template | 1 + NineChess/include/.gitignore | 1 + NineChess/include/version.h | 8 ++++++ NineChess/ninechess.pro | 1 + NineChess/ninechess.vcxproj | 2 ++ NineChess/ninechess.vcxproj.filters | 6 +++++ NineChess/src/ninechesswindow.cpp | 41 +++++++++++++++++++---------- NineChess/version.h.template | 6 ----- NineChess/version.sh | 18 +++++++++---- 9 files changed, 59 insertions(+), 25 deletions(-) create mode 100644 NineChess/git_version.h.template create mode 100644 NineChess/include/.gitignore create mode 100644 NineChess/include/version.h delete mode 100644 NineChess/version.h.template diff --git a/NineChess/git_version.h.template b/NineChess/git_version.h.template new file mode 100644 index 00000000..0728327f --- /dev/null +++ b/NineChess/git_version.h.template @@ -0,0 +1 @@ +static const char *versionNumber = "$FULL_VERSION"; \ No newline at end of file diff --git a/NineChess/include/.gitignore b/NineChess/include/.gitignore new file mode 100644 index 00000000..9b53678e --- /dev/null +++ b/NineChess/include/.gitignore @@ -0,0 +1 @@ +git_version.h diff --git a/NineChess/include/version.h b/NineChess/include/version.h new file mode 100644 index 00000000..424c0db4 --- /dev/null +++ b/NineChess/include/version.h @@ -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 diff --git a/NineChess/ninechess.pro b/NineChess/ninechess.pro index ff9e7eb6..f2ccd6b7 100644 --- a/NineChess/ninechess.pro +++ b/NineChess/ninechess.pro @@ -34,6 +34,7 @@ SOURCES += \ HEADERS += \ include/config.h \ + include/version.h \ src/HashNode.h \ src/MemoryPool.h \ src/MemoryPool.tcc \ diff --git a/NineChess/ninechess.vcxproj b/NineChess/ninechess.vcxproj index 43143dbd..03510890 100644 --- a/NineChess/ninechess.vcxproj +++ b/NineChess/ninechess.vcxproj @@ -394,6 +394,7 @@ + .\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 @@ -535,6 +536,7 @@ + diff --git a/NineChess/ninechess.vcxproj.filters b/NineChess/ninechess.vcxproj.filters index 597e4953..92d744d1 100644 --- a/NineChess/ninechess.vcxproj.filters +++ b/NineChess/ninechess.vcxproj.filters @@ -131,6 +131,9 @@ Header Files + + Header Files + @@ -269,6 +272,9 @@ Model + + Header Files + diff --git a/NineChess/src/ninechesswindow.cpp b/NineChess/src/ninechesswindow.cpp index 1af8f745..99f2b0cb 100644 --- a/NineChess/src/ninechesswindow.cpp +++ b/NineChess/src/ninechesswindow.cpp @@ -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); // 运行对话框 diff --git a/NineChess/version.h.template b/NineChess/version.h.template deleted file mode 100644 index a7f486a3..00000000 --- a/NineChess/version.h.template +++ /dev/null @@ -1,6 +0,0 @@ -#ifudef VERSION_H -#define VERSION_H - -#define VERSION_NUMBER $FULL_VERSION - -#endif // VERSION_H diff --git a/NineChess/version.sh b/NineChess/version.sh index 28493607..afb618dc 100644 --- a/NineChess/version.sh +++ b/NineChess/version.sh @@ -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"