Procházet zdrojové kódy

add ivversion.sh for create ivversion_def.h for create versioncode from git.

yuchuli před 3 roky
rodič
revize
e5aa22f92b
3 změnil soubory, kde provedl 98 přidání a 53 odebrání
  1. 3 0
      include/common.pri
  2. 56 53
      include/ivversion.h
  3. 39 0
      include/ivversion.sh

+ 3 - 0
include/common.pri

@@ -1,4 +1,7 @@
 
+system("./ivversion.sh ")
+
+
 INCLUDEPATH += $$PWD/../include/
 LIBS += -L$$PWD/../bin/ -lxmlparam -lmodulecomm  -livlog -livfault -livexit -livbacktrace
 

+ 56 - 53
include/ivversion.h

@@ -1,58 +1,61 @@
 #ifndef IVVERSION_H
 #define IVVERSION_H
 
-#define VERSION "1.1.0-develop"
-
-
-#include <iostream>
-#include <stdio.h>
-#include <fstream>
-#include <string.h>
-
-#include <QFile>
-
-std::string getgitversion()
-{
-    std::string strrtn;
-    bool bfileok = false;
-    char strpath[256];
-    char strtem[256];
-    char strbase[256];
-    snprintf(strbase,256,"./.git/refs/heads/master");
-    snprintf(strtem,256,"./.");
-    int i;
-    for(i=0;i<5;i++)
-    {
-        strncpy(strpath,strtem,256);
-        int j;
-        for(j=0;j<i;j++)strncat(strpath,strtem,256);
-        strncat(strpath,strbase,256);
-        std::ifstream f(strpath);
-        if(f.good())
-        {
-            char strdata[256];
-            f.read(strdata,256);
-            if(f.gcount()>0)strrtn.append(strdata,f.gcount());
-
-            //        std::cout<<"file ok"<<"size is "<<f.gcount()<<std::endl;
-            bfileok = true;
-            f.close();
-            break;
-        }
-        else
-        {
-            //        std::cout<<" not ok"<<std::endl;
-        }
-    }
-    if(bfileok == false)
-    {
-        strrtn = VERSION;
-    }
-    return strrtn;
-}
-
-//#define showversion(modulename) do{std::cout<<"ADC IV Version:"<<VERSION<<" | Module name: "<<modulename<<" | Build Time: "<<__DATE__<<" "<<__TIME__<<std::endl;}while(0);
-
-#define showversion(modulename) do{std::cout<<"ADC IV Version:"<<getgitversion()<<" | Module name: "<<modulename<<" | Build Time: "<<__DATE__<<" "<<__TIME__<<std::endl;}while(0);
+#include "ivversion_def.h"
+
+#ifndef IVVERSION
+#define IVVERSION "1.1.0-develop"
+#endif
+
+//#include <iostream>
+//#include <stdio.h>
+//#include <fstream>
+//#include <string.h>
+
+//#include <QFile>
+
+//std::string getgitversion()
+//{
+//    std::string strrtn;
+//    bool bfileok = false;
+//    char strpath[256];
+//    char strtem[256];
+//    char strbase[256];
+//    snprintf(strbase,256,"./.git/refs/heads/master");
+//    snprintf(strtem,256,"./.");
+//    int i;
+//    for(i=0;i<5;i++)
+//    {
+//        strncpy(strpath,strtem,256);
+//        int j;
+//        for(j=0;j<i;j++)strncat(strpath,strtem,256);
+//        strncat(strpath,strbase,256);
+//        std::ifstream f(strpath);
+//        if(f.good())
+//        {
+//            char strdata[256];
+//            f.read(strdata,256);
+//            if(f.gcount()>0)strrtn.append(strdata,f.gcount());
+
+//            //        std::cout<<"file ok"<<"size is "<<f.gcount()<<std::endl;
+//            bfileok = true;
+//            f.close();
+//            break;
+//        }
+//        else
+//        {
+//            //        std::cout<<" not ok"<<std::endl;
+//        }
+//    }
+//    if(bfileok == false)
+//    {
+//        strrtn = VERSION;
+//    }
+//    return strrtn;
+//}
+
+#define showversion(modulename) do{std::cout<<"ADC IV Version:"<<IVVERSION<<" | Module name: "<<modulename<<" | Build Time: "<<__DATE__<<" "<<__TIME__<<std::endl;}while(0);
+
+//#define showversion(modulename) do{std::cout<<"ADC IV Version:"<<getgitversion()<<" | Module name: "<<modulename<<" | Build Time: "<<__DATE__<<" "<<__TIME__<<std::endl;}while(0);
 
 #endif

+ 39 - 0
include/ivversion.sh

@@ -0,0 +1,39 @@
+folder=$(echo $PWD) ; 
+#echo $folder;
+filepath=$folder/../.git/refs/heads/master;
+#echo $filepath;
+VERSIONCODE="v1.0"
+if [  -f "$filepath" ]; then
+  gitversion=$(cat $folder/../.git/refs/heads/master)
+#  echo $gitversion
+  VERSIONCODE=$gitversion
+else
+  echo "not found file "$filepath
+  VERSIONCODE="v1.0-develop"
+fi
+echo $VERSIONCODE
+
+
+VERSIONINFO=$(echo "#define IVVERSION \"$VERSIONCODE\"")
+echo $VERSIONINFO
+if [ ! -f "ivversion_def.h" ]; then
+  echo "ivversion_def.h not exit."
+  echo "#ifndef IVVERSION_DEF_H" >> ivversion_def.h
+  echo "#define IVVERSION_DEF_H" >> ivversion_def.h
+  echo $VERSIONINFO >> ivversion_def.h
+  echo "#endif" >> ivversion_def.h
+else
+  echo "file exit."
+  OLDVERSIONINFO=$(sed -n "3p" ivversion_def.h)
+  echo "old:"$OLDVERSIONINFO
+  if [ ! "$OLDVERSIONINFO"x = "$VERSIONINFO"x ]; then
+    cat /dev/null > ivversion_def.h
+    echo "#ifndef IVVERSION_DEF_H" >> ivversion_def.h
+    echo "#define IVVERSION_DEF_H" >> ivversion_def.h
+    echo $VERSIONINFO >> ivversion_def.h
+    echo "#endif" >> ivversion_def.h
+  else
+    echo "VERSION Not Change. so not need update ivversion_def.h"
+  fi
+fi
+