From c83e39e612aa4abb931857213667b88da190d2e2 Mon Sep 17 00:00:00 2001 From: Siegfried Siegert Date: Mon, 8 Jul 2024 11:45:01 +0200 Subject: [PATCH] Add automatic version generation --- .gitignore | 38 ++++++++++++- APservice.pro | 17 ++++++ generate-version.sh | 126 ++++++++++++++++++++++++++++++++++++++++++++ main.cpp | 2 + 4 files changed, 181 insertions(+), 2 deletions(-) create mode 100755 generate-version.sh diff --git a/.gitignore b/.gitignore index a2ce144..597f8bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,36 @@ -*.user -*.user.* +# C++ objects and libs + +*.slo +*.lo +*.o +*.a +*.la +*.lai +*.so +*.dll +*.dylib + +# Qt-es + +*.pro.user +*.pro.user.* +moc_*.cpp +qrc_*.cpp +Makefile +Makefile.* +*-build-* + +# +*.autosave +ui_*.h +version.h +version.txt + +packages/* +*.pro.orig +Output/setup.exe + +.directory + +*~ + diff --git a/APservice.pro b/APservice.pro index c326b2a..1150318 100755 --- a/APservice.pro +++ b/APservice.pro @@ -104,3 +104,20 @@ HEADERS += \ win_template.h \ datei.h \ plugin.h + + +OTHER_FILES += \ + generate-version.sh + +CONFIG(DesktopLinux, DesktopLinux|PTU5):DEFINES += SYSTEM_DESKTOP_LINUX +CONFIG(PTU5, DesktopLinux|PTU5):DEFINES += SYSTEM_PTU5 + +# Define how to create version.h +VERSION_H = $$PWD/version.h +version.output = $$PWD/version.h +version.commands = $$PWD/generate-version.sh $${ARCH} $${TARGET} $${VERSION_H} +version.depends = FORCE +version.input = VERSION_H +version.variable_out = HEADERS +QMAKE_EXTRA_COMPILERS += version +QMAKE_CLEAN += $${PWD}/version.h diff --git a/generate-version.sh b/generate-version.sh new file mode 100755 index 0000000..f7651cc --- /dev/null +++ b/generate-version.sh @@ -0,0 +1,126 @@ +#!/bin/bash + +VERSION_STRING="" + +#GIT='/cygdrive/c/Program Files \(x86\)/Git/bin/git' +GIT=git + + + + +parse_git_branch () { + $GIT branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/" +} + + +ARCH=$1 +TARGET=$2 +VERSION_H=$3 + +SCRIPT=$(readlink -f $0) +SCRIPTPATH=`dirname $SCRIPT` +OUTPUTDIR=$(pwd) +echo " current dir is : " $(pwd) +echo $SCRIPT +echo $SCRIPTPATH + +echo "changing dir to script path: " $SCRIPTPATH +cd $SCRIPTPATH + +# set version string ################################################################## +if [ -z $VERSION_STRING ] ; then + VERSION_STRING=$(date +%Y%m%d_%H%M) +fi +GIT_DESCRIBE=$($GIT describe) +GIT_BRANCH=$(parse_git_branch) + +# extract path from branchname: +IFS='_' read -ra TMP_ARRAY <<< "${GIT_BRANCH}" +BRANCH_PATH=${TMP_ARRAY[0]} + + + +# detect if we have a development version: +if [ ${#TMP_ARRAY[1]} -gt 0 ] ; then + DEV_SUFFIX="_dev" +else + DEV_SUFFIX="" +fi + +# detect if git status is dirty +GIT_DESCRIBE_DIRTY=$($GIT describe --dirty) +if [ "${GIT_DESCRIBE_DIRTY:(-6)}" == "-dirty" ] ; then + DIRTY_SUFFIX="_dirty" +else + DIRTY_SUFFIX="" +fi + + +if [ -n "$DIRTY_SUFFIX" ] || [ -n "$DEV_SUFFIX" ] ; then + DEVDIRTY=true +else + DEVDIRTY=false +fi + + + +# +# write version.h + + +echo " TARGET is: $TARGET" +echo " ARCH is: $ARCH" +echo " " +echo " PluginName: $TARGET" +echo " " +echo " new version is: $VERSION_STRING" +echo " git describe is: $GIT_DESCRIBE" +echo " git branch is: $GIT_BRANCH" +echo " branch-path is: $BRANCH_PATH" +echo " " + +echo " dev suffix: $DEV_SUFFIX" +echo " dirty suffix: $DIRTY_SUFFIX" + + +APP_VERSION=${VERSION_STRING} +#ATB_QT_GIT_DESCRIBE=${GIT_DESCRIBE}_${GIT_BRANCH} +APP_GIT_DESCRIBE=${GIT_DESCRIBE}_${BRANCH_PATH}${DEV_SUFFIX}${DIRTY_SUFFIX} + +#TARGET=IngenicoZVT_CCPlugin + + +# build version.h ##################################################################### + +echo " building new version info (version.h) ..." + + + + +echo "#ifndef VERSION_H" > ${VERSION_H} +echo "#define VERSION_H" >> ${VERSION_H} +echo "" >> ${VERSION_H} +echo "" >> ${VERSION_H} +echo "#define APP_VERSION \"${APP_VERSION}\"" >> ${VERSION_H} +echo "" >> ${VERSION_H} +echo "#define APP_GIT_DESCRIBE \"${APP_GIT_DESCRIBE}\"" >> ${VERSION_H} +echo "" >> ${VERSION_H} +echo "" >> ${VERSION_H} + +echo "" >> ${VERSION_H} +echo "" >> ${VERSION_H} +if [ ${DEVDIRTY} == "true" ] ; then +echo "#define DEVDIRTY" >> ${VERSION_H} +echo "" >> ${VERSION_H} +echo "" >> ${VERSION_H} +fi +echo "#define SYSTEM_ARCH \"${ARCH}\"" >> ${VERSION_H} +echo "#define ARCH_${ARCH}" >> ${VERSION_H} +echo "" >> ${VERSION_H} +echo "" >> ${VERSION_H} +echo "#endif //VERSION_H" >> ${VERSION_H} + + + + + diff --git a/main.cpp b/main.cpp index 37a277b..215ff92 100755 --- a/main.cpp +++ b/main.cpp @@ -2,6 +2,8 @@ //#include "message_handler.h" #include +#include "version.h" + int thisisglobal; int main(int argc, char *argv[])