From cd81df17fa23277159d2a2d8d11788ed70c5cb17 Mon Sep 17 00:00:00 2001 From: konrad Date: Sat, 3 Dec 2011 20:12:20 +0000 Subject: [PATCH] unified version info, more info for svn git-svn-id: https://silmor.de/svn/softmagic/pack/trunk@751 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- .gitignore | 15 ++++ Makefile | 30 ++++++++ qtbase/include/WOb | 1 + qtbase/include/interface.h | 18 +++++ qtbase/include/wob.h | 42 +++++++++++ qtbase/src/interface.cpp | 13 +++- qtbase/src/nullscript.cpp | 5 +- woc/htmlout.cpp | 10 ++- woc/php/phptrans.cpp | 7 +- woc/proc/proc.pri | 4 + woc/proc/processor.cpp | 174 +++++++++++++++++++++++++++++++++++--------- woc/proc/processor.h | 18 +++-- woc/proc/version.qrc | 11 +++ woc/proc/version.wolf | 9 ++ woc/qt/qt.pri | 2 + woc/qt/qtout.cpp | 82 +++++++++++++++++++-- woc/qt/qtout.h | 2 + woc/woc.pro | 20 +++-- 18 files changed, 400 insertions(+), 63 deletions(-) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 qtbase/include/WOb create mode 100644 qtbase/include/wob.h create mode 100644 woc/proc/version.qrc create mode 100644 woc/proc/version.wolf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..28296fd --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*~ +woc/woc +woc/prewoc +*.exe +*.o +*.obj +*.dll +*.so +*.a +*.prl +vinfo +.ctmp +.ptmp +qtbase/Makefile* +woc/Makefile* diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6f22cba --- /dev/null +++ b/Makefile @@ -0,0 +1,30 @@ +####################################################### +# Main Makefile for PACK +# +# see README for details +####################################################### + +QMAKE = qmake +DOXYGEN = doxygen + +all: prewoc woc qtbase doc + +.PHONY: prewoc woc qtbase doc + +prewoc: + cd woc && $(QMAKE) -o Makefile.prewoc CONFIG+=prewoc + $(MAKE) -C woc -f Makefile.prewoc + cd woc && ./prewoc :/version.wolf + +woc: + cd woc && $(QMAKE) CONFIG+=woc + $(MAKE) -C woc + +qtbase: + cd qtbase && $(QMAKE) + $(MAKE) -C qtbase + +doc: + cd woc && $(DOXYGEN) + cd qtbase && $(DOXYGEN) + cd phpbase && $(DOXYGEN) diff --git a/qtbase/include/WOb b/qtbase/include/WOb new file mode 100644 index 0000000..8069465 --- /dev/null +++ b/qtbase/include/WOb @@ -0,0 +1 @@ +#include "wob.h" diff --git a/qtbase/include/interface.h b/qtbase/include/interface.h index bb0470b..f64aee8 100644 --- a/qtbase/include/interface.h +++ b/qtbase/include/interface.h @@ -12,6 +12,8 @@ #include #include +#include + class QNetworkAccessManager; class QNetworkRequest; class QNetworkReply; @@ -92,6 +94,22 @@ class WInterface:public QObject /**returns the current log level*/ LogLevel logLevel()const{return loglvl;} + ///returns version info about the library + QString libraryVersionInfo(WOb::VersionInfo)const; + ///returns version info about the library + QString staticLibraryVersionInfo(WOb::VersionInfo); + ///returns version info about the WOC that was used to generate the interface + virtual QString wocVersionInfo(WOb::VersionInfo)const=0; + ///returns version info about the interface itself + virtual QString versionInfo(WOb::VersionInfo)const=0; + + ///convenience function: return the protocol version of this interface + virtual QString commVersion()const{return versionInfo(WOb::VersionComm);} + ///convenience function: return the oldest protocol version this interface is compatible with + virtual QString needCommVersion()const{return versionInfo(WOb::VersionNeedComm);} + ///convenience function: return human readable version + virtual QString version()const{return versionInfo(WOb::VersionHR);} + public slots: /**set log level*/ void setLogLevel(WInterface::LogLevel l){loglvl=l;} diff --git a/qtbase/include/wob.h b/qtbase/include/wob.h new file mode 100644 index 0000000..85db756 --- /dev/null +++ b/qtbase/include/wob.h @@ -0,0 +1,42 @@ +// Copyright (C) 2009-2011 by Konrad Rosenbaum +// protected under the GNU LGPL version 3 or at your option any newer. +// See COPYING.LGPL file that comes with this distribution. +// + + +#ifndef WOB_WOB_H +#define WOB_WOB_H + +namespace WOb { + + +///version information, used in conjunction with versionInfo() +enum VersionInfo{ + ///the version of the protocol that the interface implements + VersionComm, + ///the oldest version of the protocol that the interface is compatible with + VersionNeedComm, + ///human readable version number + VersionHumanReadable, + ///alias for VersionHumanReadable, + VersionHR=VersionHumanReadable, + ///the source control system used to determine version information + VersionSystem, + ///the path within the repository that contained the interface source + VersionPath, + ///the base URL of the repository + VersionRootURL, + ///the version number determined from the source control system + VersionNumber, + ///the timestamp of the latest commit that went into the interface + VersionTime, + ///the author(s) of the latest commit that went into the interface + VersionAuthor, + ///contains "modified" if the source tree contained local modifications, "unmodified" if it was pristine, "local" if it was not under source control, depending on the source control system and circumstances this can also contain other values + VersionLocallyModified, +}; + + +}; + +#endif diff --git a/qtbase/src/interface.cpp b/qtbase/src/interface.cpp index da81d8c..57028b0 100644 --- a/qtbase/src/interface.cpp +++ b/qtbase/src/interface.cpp @@ -83,4 +83,15 @@ WServerReply WInterface::execute(const WServerRequest&) rp.setHeader("Content-Type","text/html; charset=utf-8"); rp.setBody((QString)"

Sorry

Not implemented."); return rp; -} \ No newline at end of file +} + +#include "../../vinfo/staticVersion.h" + +QString WInterface::libraryVersionInfo(WOb::VersionInfo vi)const +{ + return WOCgenerated_versionInfo(vi); +} +QString WInterface::staticLibraryVersionInfo(WOb::VersionInfo vi) +{ + return WOCgenerated_versionInfo(vi); +} diff --git a/qtbase/src/nullscript.cpp b/qtbase/src/nullscript.cpp index 2573801..ce4a045 100644 --- a/qtbase/src/nullscript.cpp +++ b/qtbase/src/nullscript.cpp @@ -1,6 +1,9 @@ //start: nullscript.cpp +// +//this adapts PACK nullable values to be usable with QtScript +// //currently this file is copied verbatim into the generated -//interface code, in the future it may be included here instead +//interface code, in the future it may be included there instead #include #include diff --git a/woc/htmlout.cpp b/woc/htmlout.cpp index 0c88f13..8c94b4b 100644 --- a/woc/htmlout.cpp +++ b/woc/htmlout.cpp @@ -42,9 +42,13 @@ WocHtmlOut::WocHtmlOut(QDomElement&el) inf+="Communication Layer Version: "+woc->verComm()+"
"; inf+="Minimum Compatible Version: "+woc->verNeedComm()+"

"; - inf+="SVN Repository URL: "+woc->svnRepositoryUrl()+"
"; - inf+="SVN Repository Root: "+woc->svnRepositoryRoot()+"
"; - inf+="SVN Revision: "+woc->svnRevision()+"

"; + QMap vinfo=woc->versionInfo(); + inf+="Repository Type: "+vinfo.value("System")+"
"; + inf+="Repository URL: "+vinfo.value("RootURL")+"
"; + inf+="Repository Path: "+vinfo.value("Path")+"
"; + inf+="Author: "+vinfo.value("Author")+"
"; + inf+="Time Stamp: "+vinfo.value("Time")+"
"; + inf+="Revision: "+vinfo.value("Number")+"

"; inf+="Database Instance Object: "+woc->dbInst()+"
"; inf+="Database Schema Object: "+woc->dbSchema()+"
"; diff --git a/woc/php/phptrans.cpp b/woc/php/phptrans.cpp index 9924dcd..8763a35 100644 --- a/woc/php/phptrans.cpp +++ b/woc/php/phptrans.cpp @@ -40,9 +40,10 @@ void WocPHPTransaction::transInfo() code+=" static public function commVersion(){return \""+woc->verComm()+"\";}\n"; code+=" static public function needCommVersion(){return \""+woc->verNeedComm()+"\";}\n"; code+=" static public function version(){return \""+woc->verHR()+"\";}\n"; - code+=" static public function svnVersion(){return \""+woc->svnRevision()+"\";}\n"; - code+=" static public function svnRepositoryRoot(){return \""+woc->svnRepositoryRoot()+"\";}\n"; - code+=" static public function svnRepositoryUrl(){return \""+woc->svnRepositoryUrl()+"\";}\n"; +#warning "TODO: add version info to PHP generator" +// code+=" static public function svnVersion(){return \""+woc->svnRevision()+"\";}\n"; +// code+=" static public function svnRepositoryRoot(){return \""+woc->svnRepositoryRoot()+"\";}\n"; +// code+=" static public function svnRepositoryUrl(){return \""+woc->svnRepositoryUrl()+"\";}\n"; code+="\n"; code+=" static public function xmlProjectNamespace(){return \""+woc->xmlProjectNamespace()+"\";}\n"; code+=" static public function xmlPackNamespace(){return \""+woc->xmlPackNamespace()+"\";}\n"; diff --git a/woc/proc/proc.pri b/woc/proc/proc.pri index 58acc4d..5209b44 100644 --- a/woc/proc/proc.pri +++ b/woc/proc/proc.pri @@ -9,4 +9,8 @@ HEADERS+= \ proctrans.h \ proctable.h +CONFIG(prewoc, prewoc|woc){ + RESOURCES += proc/version.qrc +} + INCLUDEPATH += proc \ No newline at end of file diff --git a/woc/proc/processor.cpp b/woc/proc/processor.cpp index b9812fd..56e7e8d 100644 --- a/woc/proc/processor.cpp +++ b/woc/proc/processor.cpp @@ -13,12 +13,17 @@ #include "domquery.h" +#include +#include +#include #include #include #include #include #include +#include + QListelementsByTagName(const QDomElement&root,QString tag) { QDomNodeList cn=root.childNodes(); @@ -42,9 +47,9 @@ WocProcessor::WocProcessor() m_verComm="0"; m_verNeedComm="0"; m_verHR="0.0"; - m_svnTarget="."; - m_svnRev="unknown uncertain"; m_svnExe="svn"; + m_gitExe="git"; + m_verSys=QStringList()<<"none"; m_dbInst="dbInst"; m_dbSchema="dbSchema"; m_dbUpd=false; @@ -124,6 +129,10 @@ bool WocProcessor::processFile(QString fn) if(tn=="Project"){ if(el.hasAttribute("baseDir")) m_baseDir=el.attribute("baseDir"); + if(m_baseDir=="::woc::"){ + m_baseDir=QCoreApplication::applicationDirPath(); + qDebug()<<"Info: special value '::woc::' given as base dir, correcting it to"<lrev)lrev=r; + } + //parse it: revisions of updates + rl=MDomQuery(doc,"/*/entry/@revision"); + int minv=-1,maxv=-1; + QDateTime mint,maxt; if(rl.size()==0){ - m_svnRev="unknown"; + svnRev="unknown"; }else{ - int minv,maxv; minv=maxv=rl[0].toInt(); for(int i=1;imaxv)maxv=cv; } + //compare to last change revision; what counts is last change + if(maxv>lrev)maxv=lrev; + if(minv>maxv)minv=maxv; + //remember if(minv==maxv) - m_svnRev=QString::number(maxv); + svnRev=QString::number(maxv); else - m_svnRev=QString::number(minv)+"-"+QString::number(maxv); + svnRev=QString::number(minv)+"-"+QString::number(maxv); + } + //get authors + rl=MDomQuery(doc,"/*/entry/commit/author"); + rl=rl.toSet().toList();//reduce + qSort(rl); + for(int i=0;i0)m_svnUrl=rl[0]; + if(rl.size()>0)svnUrl=rl[0]; rl=MDomQuery(el,"repository/root"); - if(rl.size()>0)m_svnRoot=rl[0]; + if(rl.size()>0)svnRoot=rl[0]; break;//we can stop now } } } //svn status - svn.start(m_svnExe,QStringList()<<"status"<<"--xml"<<"--non-interactive"<<"."); + svn.start(m_svnExe,QStringList()<<"status"<<"-v"<<"--xml"<<"--non-interactive"<<"."); svn.waitForFinished(); if(svn.exitCode()!=0){ qDebug("Warning: error while calling svn status."); - m_svnRev+=" uncertain"; - return; + svnMod="uncertain"; + return false; }else{ QDomDocument doc; if(!doc.setContent(svn.readAllStandardOutput())){ qDebug("Warning: unable to parse output of svn status."); - m_svnRev+=" uncertain"; - return; - } - QStringList rl=MDomQuery(doc,"/status/target/entry/wc-status/@item"); - bool ismod=false; - for(int i=0;i versionInfo()const{return m_verInfo;} /**returns the variable name that will contain the database driver instance*/ QString dbInst()const{return m_dbInst;} /**returns the variable name that will contain the database schema object*/ @@ -165,7 +161,9 @@ class WocProcessor:public QObject void errorFound(); private: QString m_baseDir,m_wobDir,m_verComm,m_verNeedComm,m_verHR,m_projname; - QString m_svnTarget,m_svnRev,m_svnExe,m_svnRoot,m_svnUrl; + QString m_verTarget,m_svnExe,m_gitExe; + QMapm_verInfo; + QStringList m_verSys; QString m_dbInst,m_dbSchema,m_dbVer; QString m_xmlNS,m_xmlPackNS,m_xmlSoap12NS,m_xmlSchemaNS,m_xmlXmlNS; QStringList m_docstrings; @@ -180,7 +178,11 @@ class WocProcessor:public QObject static WocProcessor*inst; /**helper: calls SVN and parses its output*/ - void callSvn(); + bool callSvn(); + ///helper: calls GIT and parses its output + bool callGit(); + ///helper: fallback for version control check + bool callNoVer(); /**helper: looks up some schema files and finds the corresponding namespaces*/ void parseNamespaces(); diff --git a/woc/proc/version.qrc b/woc/proc/version.qrc new file mode 100644 index 0000000..2c1fe30 --- /dev/null +++ b/woc/proc/version.qrc @@ -0,0 +1,11 @@ + + + + + version.wolf + + diff --git a/woc/proc/version.wolf b/woc/proc/version.wolf new file mode 100644 index 0000000..265b638 --- /dev/null +++ b/woc/proc/version.wolf @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/woc/qt/qt.pri b/woc/qt/qt.pri index 912dcdb..e3c4ebd 100644 --- a/woc/qt/qt.pri +++ b/woc/qt/qt.pri @@ -12,4 +12,6 @@ HEADERS+= \ qt/qtctrans.h \ qt/qtstrans.cpp +RESOURCES += qt/qtfiles.qrc + INCLUDEPATH += qt \ No newline at end of file diff --git a/woc/qt/qtout.cpp b/woc/qt/qtout.cpp index 895b632..ec37dd1 100644 --- a/woc/qt/qtout.cpp +++ b/woc/qt/qtout.cpp @@ -64,12 +64,21 @@ WocQtOut::WocQtOut(QDomElement&el) m_iface.write(QString("class "+ifaceClassName()+":public WInterface\n{\n Q_OBJECT\n").toAscii()); m_iface.write(QString(" public:\n "+ifaceClassName()+"(QString name=\""+pn+"\"):WInterface(name){}\n").toAscii()); m_iface.write(QString(" static "+ifaceClassName()+"*instance(QString name=\""+pn+"\")\n\t{return qobject_cast<"+ifaceClassName()+"*>(WInterface::instance(name));}\n\n").toAscii()); - m_iface.write(QString(" Q_INVOKABLE static QString commVersion(){return \""+woc->verComm()+"\";}\n").toAscii()); - m_iface.write(QString(" Q_INVOKABLE static QString needCommVersion(){return \""+woc->verNeedComm()+"\";}\n").toAscii()); - m_iface.write(QString(" Q_INVOKABLE static QString version(){return \""+woc->verHR()+"\";}\n").toAscii()); - m_iface.write(QString(" Q_INVOKABLE static QString svnVersion(){return \""+woc->svnRevision()+"\";}\n\n").toAscii()); - m_iface.write(QString(" Q_INVOKABLE static QString svnRepositoryRoot(){return \""+woc->svnRepositoryRoot()+"\";}\n\n").toAscii()); - m_iface.write(QString(" Q_INVOKABLE static QString svnRepositoryUrl(){return \""+woc->svnRepositoryUrl()+"\";}\n\n").toAscii()); +// m_iface.write(QString(" Q_INVOKABLE static QString commVersion(){return \""+woc->verComm()+"\";}\n").toAscii()); +// m_iface.write(QString(" Q_INVOKABLE static QString needCommVersion(){return \""+woc->verNeedComm()+"\";}\n").toAscii()); +// m_iface.write(QString(" Q_INVOKABLE static QString version(){return \""+woc->verHR()+"\";}\n").toAscii()); + //version info, static + m_iface.write(QByteArray(" Q_INVOKABLE static QString staticVersionInfo(WOb::VersionInfo);\n")); + m_ifacecpp.write(QByteArray("#include \"staticVersion.h\"\n")); + m_ifacecpp.write(QString("QString "+ifaceClassName()+"::staticVersionInfo(WOb::VersionInfo vi){return WOCgenerated_versionInfo(vi);}\n").toAscii()); + m_iface.write(QByteArray(" Q_INVOKABLE static QString staticWocVersionInfo(WOb::VersionInfo);\n")); + m_ifacecpp.write(QString("QString "+ifaceClassName()+"::staticWocVersionInfo(WOb::VersionInfo vi){return WOCcopied_versionInfo(vi);}\n").toAscii()); + //version info, virtual + m_iface.write(QByteArray(" Q_INVOKABLE QString versionInfo(WOb::VersionInfo)const;\n")); + m_ifacecpp.write(QByteArray("#include \"staticVersion.h\"\n")); + m_ifacecpp.write(QString("QString "+ifaceClassName()+"::versionInfo(WOb::VersionInfo vi)const{return WOCgenerated_versionInfo(vi);}\n").toAscii()); + m_iface.write(QByteArray(" Q_INVOKABLE QString wocVersionInfo(WOb::VersionInfo)const;\n")); + m_ifacecpp.write(QString("QString "+ifaceClassName()+"::wocVersionInfo(WOb::VersionInfo vi)const{return WOCcopied_versionInfo(vi);}\n").toAscii()); //init scripting initScripting(); @@ -98,6 +107,8 @@ void WocQtOut::finalize() m_scriptcode+="}\n\n"; m_ifacecpp.write(m_scriptcode.toAscii()); } + //generate versionInfo + initVersionH(); //add interface class addFile(ifaceClassName().toAscii()); //finish sources @@ -263,3 +274,62 @@ void WocQtOut::initScripting() //register nullables m_scriptcode+="\tinitNullableScripting(engine);\n"; } + +#ifndef NO_PACK_VERSION_H +#include "../../vinfo/staticVersion.h" +#endif + +static inline QString escapeStr(QString s) +{ + return s.replace("\\","\\\\").replace("\"","\\\"").replace("\n","\\n"); +} + +void WocQtOut::initVersionH() +{ + //create file + MFile vhf; + vhf.setFileName(m_basedir+"/"+m_subdir+"/staticVersion.h"); + if(!vhf.open(QIODevice::WriteOnly|QIODevice::Truncate)){ + qDebug("Error: cannot create Qt version info file %s.",vhf.fileName().toAscii().data()); + emit errorFound(); + return; + } + vhf.write(QByteArray(HDRSTART).replace("%",m_prefix.toAscii()+"STATIC_VERSION_H")); + //generate functions for project's own values + QString data="#include \n#include \n\n" + "static inline QString WOCgenerated_versionInfo(WOb::VersionInfo vi){\nswitch(vi){\n"; + QString data2; + QMap vm=WocProcessor::instance()->versionInfo(); + QStringList vi=vm.keys(); + for(int i=0;i