From 71cc260a3ca6d3d0594fd4cadb0711ae3f142932 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 7 Sep 2006 22:49:40 +0000 Subject: About to implement Rule, the heart of the porform generation system. Once that's done, we can actually run the performs, and, most likely build things. --- src/build.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++--- src/build.h | 7 +++++++ src/buildparser.cpp | 2 ++ src/rule.cpp | 4 ++++ src/rule.h | 2 ++ src/stringprocbuild.cpp | 2 ++ src/target.h | 5 +++++ src/targetfile.cpp | 16 ++++++++++++++ src/targetfile.h | 3 +++ 9 files changed, 94 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/build.cpp b/src/build.cpp index bf867af..372e607 100644 --- a/src/build.cpp +++ b/src/build.cpp @@ -2,8 +2,8 @@ subExceptionDef( BuildException ); - -Build::Build() +Build::Build() : + pStrProc( NULL ) { } @@ -11,10 +11,52 @@ Build::~Build() { } +void Build::setStringProc( StringProc *pStrProc ) +{ + delete this->pStrProc; + this->pStrProc = pStrProc; +} + +std::string Build::replVars( const std::string &sSrc, const std::string &sCont ) +{ + if( pStrProc == NULL ) + throw BuildException( + "No valid string processor was registered with the Build object." + ); + + return pStrProc->replVars( sSrc, sCont ); +} + void Build::execAction( const std::string &sWhat ) { if( mAction.find( sWhat ) == mAction.end() ) - throw BuildException("No action matches %s.", sWhat.c_str() ); + throw BuildException( + "No action matches %s, check your build.conf.", + sWhat.c_str() + ); + + Action *pAct = mAction[sWhat]; + + for( pAct->begin(); !pAct->isEnded(); pAct->next() ) + { + if( mTarget.find( pAct->getWhat() ) == mTarget.end() ) + throw BuildException( + "No target matches %s in action %s.", + pAct->getWhat().c_str(), + sWhat.c_str() + ); + Target *pTarget = mTarget[pAct->getWhat()]; + switch( pAct->getAct() ) + { + case Action::actCheck: + pTarget->check( *this ); + break; + + case Action::actClean: + pTarget->clean( *this ); + break; + } + } return; } @@ -42,6 +84,14 @@ void Build::addRule( Rule *pRule ) mRule[pRule->getName()] = pRule; } +Rule *Build::getRule( const std::string &name ) +{ + if( mRule.find( name ) == mRule.end() ) + throw BuildException("No rule named %s found.", name.c_str() ); + + return mRule[name]; +} + void Build::addAction( Action *pAction ) { mAction[pAction->getName()] = pAction; diff --git a/src/build.h b/src/build.h index 77e40fa..d5e6604 100644 --- a/src/build.h +++ b/src/build.h @@ -10,6 +10,7 @@ #include "rule.h" #include "target.h" #include "action.h" +#include "stringproc.h" subExceptionDecl( BuildException ); @@ -36,8 +37,13 @@ public: void setAdd( const std::string &cont, const std::string &var, const std::string &val ); std::string getVar( const std::string &cont, const std::string &var ); + Rule *getRule( const std::string &name ); + void debugDump(); + void setStringProc( StringProc *pStrProc ); + std::string replVars( const std::string &sSrc, const std::string &sCont ); + private: typedef std::map TargetMap; typedef std::list StringList; @@ -53,6 +59,7 @@ private: ContextMap mContVars; RuleMap mRule; ActionMap mAction; + StringProc *pStrProc; //std::map mRule; //Action *pActDefault; diff --git a/src/buildparser.cpp b/src/buildparser.cpp index 90e21e2..f855990 100644 --- a/src/buildparser.cpp +++ b/src/buildparser.cpp @@ -5,6 +5,7 @@ #include "action.h" #include "build.h" #include "rule.h" +#include "stringprocbuild.h" BuildParser::BuildParser() : fFunction( FunctionFactory::getInstance() ), @@ -343,6 +344,7 @@ void BuildParser::printBuildList( const BuildList &lst ) Build *BuildParser::genBuild() { Build *bld = new Build; + bld->setStringProc( new StringProcBuild( bld ) ); for( SetVarList::iterator i = lGlobalVars.begin(); i != lGlobalVars.end(); i++ ) diff --git a/src/rule.cpp b/src/rule.cpp index 2212936..4426575 100644 --- a/src/rule.cpp +++ b/src/rule.cpp @@ -8,3 +8,7 @@ Rule::~Rule() { } +void Rule::execute() +{ +} + diff --git a/src/rule.h b/src/rule.h index 012073a..73d7738 100644 --- a/src/rule.h +++ b/src/rule.h @@ -17,6 +17,8 @@ public: Rule(); virtual ~Rule(); + void execute(); + std::string getName() { return sName; diff --git a/src/stringprocbuild.cpp b/src/stringprocbuild.cpp index 56eae12..d0a5951 100644 --- a/src/stringprocbuild.cpp +++ b/src/stringprocbuild.cpp @@ -48,5 +48,7 @@ std::string StringProcBuild::replVars( const std::string &sSrc, const std::strin sSrc.c_str() ); } + + return sDes; } diff --git a/src/target.h b/src/target.h index 75fcb50..5325965 100644 --- a/src/target.h +++ b/src/target.h @@ -8,12 +8,17 @@ typedef std::list StringList; +class Build; + class Target { public: Target(); virtual ~Target(); + virtual void check( Build &bld ) = 0; + virtual void clean( Build &bld ) = 0; + void setName( const std::string &sName ) { this->sName = sName; diff --git a/src/targetfile.cpp b/src/targetfile.cpp index fee41c9..8f6651e 100644 --- a/src/targetfile.cpp +++ b/src/targetfile.cpp @@ -1,5 +1,7 @@ #include "targetfile.h" #include "plugger.h" +#include "rule.h" +#include "build.h" PluginInterface2(file, TargetFile, Target, "Mike Buland", 0, 1 ); @@ -10,3 +12,17 @@ TargetFile::TargetFile() TargetFile::~TargetFile() { } + +void TargetFile::check( Build &bld ) +{ + printf("Target file checking: %s\n", getName().c_str() ); + + Rule *pRule = bld.getRule( getRule() ); + pRule->execute(); +} + +void TargetFile::clean( Build &bld ) +{ + printf("Target file cleaning: %s\n", getName().c_str() ); +} + diff --git a/src/targetfile.h b/src/targetfile.h index 28fc2b1..37e6770 100644 --- a/src/targetfile.h +++ b/src/targetfile.h @@ -11,6 +11,9 @@ public: TargetFile(); virtual ~TargetFile(); + virtual void check( Build &bld ); + virtual void clean( Build &bld ); + private: }; -- cgit v1.2.3