Move version and git constants into #defines and update bash script.

The bash script now adds a #define if the current checkout is
exactly on a tag, and it leaves all #defines empty if building
from a tarball.

The batch file still needs to be updated.
This commit is contained in:
sawinglogz 2020-01-16 17:37:43 -05:00
parent 6d53fc5ebf
commit 083fa3debd
4 changed files with 32 additions and 14 deletions

4
oscar/VERSION Normal file
View File

@ -0,0 +1,4 @@
// Update the string below to set OSCAR's version and release status.
// See https://semver.org/spec/v2.0.0.html for details on format.
#define VERSION "1.1.0-beta-1"

View File

@ -327,6 +327,7 @@ HEADERS += \
updateparser.h \
UpdaterWindow.h \
version.h \
VERSION \
Graphs/gFlagsLine.h \
Graphs/gFooBar.h \
Graphs/gGraph.h \

View File

@ -3,19 +3,23 @@
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD`
GIT_REVISION=`git rev-parse --short HEAD`
$(git diff-index --quiet HEAD --)
if [ $? -ne 0 ]; then
GIT_REVISION="${GIT_REVISION}-plus" # uncommitted changes
git rev-parse --git-dir &>/dev/null
if [ $? -eq 0 ]; then
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD`
GIT_REVISION=`git rev-parse --short HEAD`
$(git diff-index --quiet HEAD --)
if [ $? -ne 0 ]; then
GIT_REVISION="${GIT_REVISION}-plus" # uncommitted changes
else
# only use the tag if clean
GIT_TAG=`git describe --exact-match --tags 2>/dev/null`
fi
fi
[ -z "$GIT_BRANCH" ] && GIT_BRANCH="Unknown";
[ -z "$GIT_REVISION" ] && GIT_REVISION="Unknown";
echo // This is an auto generated file > $DIR/git_info.h.new
echo const QString GIT_BRANCH=\"$GIT_BRANCH\"\; >> $DIR/git_info.h.new
echo const QString GIT_REVISION=\"$GIT_REVISION\"\; >> $DIR/git_info.h.new
[ -n "$GIT_BRANCH" ] && echo "#define GIT_BRANCH \"$GIT_BRANCH\"" >> $DIR/git_info.h.new
[ -n "$GIT_REVISION" ] && echo "#define GIT_REVISION \"$GIT_REVISION\"" >> $DIR/git_info.h.new
[ -n "$GIT_TAG" ] && echo "#define GIT_TAG \"$GIT_TAG\"" >> $DIR/git_info.h.new
if diff $DIR/git_info.h $DIR/git_info.h.new &> /dev/null; then
rm $DIR/git_info.h.new

View File

@ -7,13 +7,22 @@
* for more details. */
#include "version.h"
#include "VERSION"
#include "git_info.h"
#include <QRegularExpression>
#define VERSION "1.1.0-beta-1"
// TODO: add preprocessor macros to build full version number including build metadata, accounting for tarball/non-git builds.
static const Version s_Version(VERSION "+" + GIT_BRANCH + "-" + GIT_REVISION);
// Initialize the Version instance with build metadata, if any.
#ifdef GIT_REVISION
#ifdef GIT_BRANCH
#define BUILD_METADATA "+" GIT_BRANCH "-" GIT_REVISION
#else
#define BUILD_METADATA "+" GIT_REVISION
#endif
#else
#define BUILD_METADATA ""
#endif
static const Version s_Version(VERSION BUILD_METADATA);
// Technically this is the date and time that version.cpp was compiled, but since
// it gets recompiled whenever git_info.h changes, it's about as close as we can
@ -27,7 +36,7 @@ QString getPrereleaseSuffix()
// Append branch if there is a branch specified
if (GIT_BRANCH != "master") {
suffix += "-"+GIT_BRANCH;
suffix += "-" GIT_BRANCH;
}
// Append "-test" if not release or release candidate