From d19ada0aa88aba1c7b439035c0028440ac860ec3 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 12 Sep 2006 00:22:33 +0000 Subject: Build now builds, it has viewers, and dependancy checking, and everything works. Now we have to add cleaning, caching, and more viewer hooks / viewers. --- build.conf | 11 +++-- src/build.cpp | 39 ++++++++++++++- src/build.h | 24 ++++++--- src/build.l | 1 + src/build.y | 5 ++ src/buildparser.cpp | 43 +++++++++++++--- src/buildparser.h | 2 + src/function.cpp | 10 ++++ src/function.h | 4 +- src/functioncommandtolist.cpp | 53 +++++++++++++++++++- src/functioncommandtolist.h | 3 +- src/functiondirectoriesin.cpp | 9 +++- src/functiondirectoriesin.h | 3 +- src/functionfilesin.cpp | 9 +++- src/functionfilesin.h | 3 +- src/functionregexp.cpp | 19 ++++++- src/functionregexp.h | 3 +- src/functiontostring.cpp | 18 ++++++- src/functiontostring.h | 3 +- src/main.cpp | 4 +- src/perform.h | 22 ++++++++- src/performcommand.cpp | 9 +++- src/performcommand.h | 3 +- src/rule.cpp | 112 +++++++++++++++++++++++++++++++++++++++++- src/rule.h | 30 +++++++++++ src/targetfile.cpp | 80 ++++++++++++++++++++++++------ src/targetfile.h | 9 +++- src/viewer.cpp | 45 +++++++++++++++++ src/viewer.h | 17 +++++++ src/viewerfactory.cpp | 12 +++++ src/viewerfactory.h | 20 ++++++++ src/viewerplain.cpp | 42 ++++++++++++++++ src/viewerplain.h | 26 ++++++++++ 33 files changed, 638 insertions(+), 55 deletions(-) create mode 100644 src/viewerfactory.cpp create mode 100644 src/viewerfactory.h create mode 100644 src/viewerplain.cpp create mode 100644 src/viewerplain.h diff --git a/build.conf b/build.conf index 640fbff..8f06532 100644 --- a/build.conf +++ b/build.conf @@ -4,7 +4,8 @@ default action: check "build" "clean" action: clean "build" "rebuild" action: clean "build", check "build" -set "CXXFLAGS" += "-ggdb" +set "CXXFLAGS" += "-ggdb -Ilibbu++/src" +set "LDFLAGS" += "-Llibbu++ -lbu++ -ldl" "build": rule "exe", @@ -15,13 +16,13 @@ set "CXXFLAGS" += "-ggdb" rule "exe": matches regexp("(.*)\\.o$"), - input filter toString(), - perform command("g++ {LDFLAGS} -o {target} {match}") + aggregate toString(" "), + perform command("g++ -o {target} {match} {LDFLAGS}") rule "cpp": - matches regexp("(.*)\\.cpp$"), + matches regexp("(.*)\\.(cpp|c)$"), produces "{re:1}.o", - requires commandToList("g++ -M {match}", "make"), + requires commandToList("g++ -M {CXXFLAGS} {match}", "make"), perform command("g++ {CXXFLAGS} -c -o {target} {match}") rule "bison": diff --git a/src/build.cpp b/src/build.cpp index 255cbd3..5c0b721 100644 --- a/src/build.cpp +++ b/src/build.cpp @@ -1,10 +1,14 @@ #include "build.h" +#include "function.h" +#include "viewerfactory.h" subExceptionDef( BuildException ); Build::Build() : - pStrProc( NULL ) + pStrProc( NULL ), + pView( NULL ) { + pView = ViewerFactory::getInstance().instantiate("plain"); } Build::~Build() @@ -46,6 +50,7 @@ void Build::execAction( const std::string &sWhat ) sWhat.c_str() ); Target *pTarget = mTarget[pAct->getWhat()]; + pView->beginCommand( pAct->getAct(), pAct->getWhat(), 0 ); switch( pAct->getAct() ) { case Action::actCheck: @@ -56,6 +61,7 @@ void Build::execAction( const std::string &sWhat ) pTarget->clean( *this ); break; } + pView->endCommand(); } return; @@ -234,3 +240,34 @@ void Build::debugDump() } } +RuleList Build::findChainRules( Rule *pHead ) +{ + RuleList lOut; + FunctionList &lMatches = pHead->getMatchesList(); + + for( RuleMap::iterator i = mRule.begin(); i != mRule.end(); i++ ) + { + if( (*i).second == pHead ) + continue; + + for( FunctionList::iterator j = lMatches.begin(); + j != lMatches.end(); j++ ) + { + StringList lTmp; + (*j)->execute( NULL, (*i).second->getProducesList(), lTmp ); + if( !lTmp.empty() ) + { + lOut.push_back( (*i).second ); + break; + } + } + } + + return lOut; +} + +StringList &Build::getRequires( std::string sName ) +{ + return mRequires[sName]; +} + diff --git a/src/build.h b/src/build.h index 080304b..31c8bde 100644 --- a/src/build.h +++ b/src/build.h @@ -14,6 +14,15 @@ subExceptionDecl( BuildException ); typedef std::map VarMap; +typedef std::map TargetMap; +typedef std::list StringList; +typedef std::map ReqMap; +typedef std::map ContextMap; +typedef std::map RuleMap; +typedef std::list RuleList; +typedef std::map ActionMap; + +class Viewer; class Build { @@ -44,15 +53,15 @@ public: void setStringProc( StringProc *pStrProc ); std::string replVars( const std::string &sSrc, const std::string &sCont, VarMap *mExtra ); + RuleList findChainRules( Rule *pHead ); + StringList &getRequires( std::string sName ); -private: - typedef std::map TargetMap; - typedef std::list StringList; - typedef std::map ReqMap; - typedef std::map ContextMap; - typedef std::map RuleMap; - typedef std::map ActionMap; + Viewer *getView() + { + return pView; + } +private: TargetMap mTarget; ReqMap mRequires; VarMap mVars; @@ -60,6 +69,7 @@ private: RuleMap mRule; ActionMap mAction; StringProc *pStrProc; + Viewer *pView; //std::map mRule; //Action *pActDefault; diff --git a/src/build.l b/src/build.l index 41abaf4..49275c8 100644 --- a/src/build.l +++ b/src/build.l @@ -34,6 +34,7 @@ std::string strbuf; "input" return TOK_INPUT; "filter" return TOK_FILTER; "prefix" return TOK_PREFIX; +"aggregate" return TOK_AGGREGATE; \n+ { yylloc->last_line += yyleng; diff --git a/src/build.y b/src/build.y index bb30d84..0853bd9 100644 --- a/src/build.y +++ b/src/build.y @@ -39,6 +39,7 @@ void yyerror( YYLTYPE *locp, BuildParser &bld, char const *msg ); %token TOK_MATCHES "matches" %token TOK_PERFORM "perform" %token TOK_PRODUCES "produces" +%token TOK_AGGREGATE "aggregate" %token ',' ':' '=' '(' ')' @@ -86,6 +87,10 @@ rulecmd: TOK_MATCHES func { bld.addRulePerform(); } + | TOK_AGGREGATE func + { + bld.setRuleAggregate(); + } ; // Action interpretation diff --git a/src/buildparser.cpp b/src/buildparser.cpp index f855990..6c3337f 100644 --- a/src/buildparser.cpp +++ b/src/buildparser.cpp @@ -121,7 +121,7 @@ void BuildParser::filterList() { StringList lTmp2; StringList lIn = buildToStringList( lTmp, StringList() ); - pTmpFunc->execute( lIn, lTmp2 ); + pTmpFunc->execute( NULL, lIn, lTmp2 ); lTmp.clear(); for( StringList::iterator i = lTmp2.begin(); i != lTmp2.end(); i++ ) { @@ -137,7 +137,7 @@ StringList BuildParser::buildToStringList( const BuildList &lSrc, const StringLi { if( (*i).second ) { - (*i).second->execute( lIn, lOut ); + (*i).second->execute( NULL, lIn, lOut ); } else { @@ -155,6 +155,7 @@ void BuildParser::addRule( const char *sName ) { lRuleTmp.push_back( RuleInfo() ); lRuleTmp.back().sName = sName; + lRuleTmp.back().pAggregate = NULL; } void BuildParser::addRuleMatches() @@ -188,6 +189,11 @@ void BuildParser::addRulePerform() lRuleTmp.back().lPerform.push_back( pTmpPerform ); } +void BuildParser::setRuleAggregate() +{ + lRuleTmp.back().pAggregate = pTmpFunc; +} + // // Perform functions // @@ -431,14 +437,35 @@ Build *BuildParser::genBuild() pRule->getPerformList().push_back( *j ); } - /*StringList lITmp = buildToStringList( - (*i).lProduces, StringList() - ); + for( BuildList::iterator j = (*i).lProduces.begin(); + j != (*i).lProduces.end(); j++ ) + { + if( (*j).second ) + { + throw BuildException( + "You cannot have functions in produces lists (rule %s).", + (*i).sName.c_str() ); + } + pRule->getProducesList().push_back( (*j).first ); + } - for( StringList::iterator i = lITmp.begin(); i != lITmp.end(); i++ ) + if( (*i).pAggregate ) { - get - }*/ + pRule->setAggregate( (*i).pAggregate ); + } + + for( BuildList::iterator j = (*i).lRequires.begin(); + j != (*i).lRequires.end(); j++ ) + { + if( (*j).second ) + { + pRule->getReqFuncList().push_back( (*j).second ); + } + else + { + pRule->getReqStrList().push_back( (*j).first ); + } + } bld->addRule( pRule ); } diff --git a/src/buildparser.h b/src/buildparser.h index 2e1924c..dda2d80 100644 --- a/src/buildparser.h +++ b/src/buildparser.h @@ -127,6 +127,7 @@ public: // Rules functions void addRuleRequires(); void addRuleInputFilter(); void addRulePerform(); + void setRuleAggregate(); private: // Rule variables class RuleInfo @@ -138,6 +139,7 @@ private: // Rule variables BuildList lRequires; FunctionList lFilter; PerformList lPerform; + Function *pAggregate; }; typedef std::list RuleTmpList; diff --git a/src/function.cpp b/src/function.cpp index e7554e1..8debbe9 100644 --- a/src/function.cpp +++ b/src/function.cpp @@ -13,3 +13,13 @@ void Function::addParam( const char *str ) lParams.push_back( str ); } +void Function::copyData( Function *pSrc, Build &bld, const std::string &cont, VarMap *mExtra ) +{ + lParams.clear(); + for( std::list::iterator i = pSrc->lParams.begin(); + i != pSrc->lParams.end(); i++ ) + { + lParams.push_back( bld.replVars( *i, cont, mExtra ) ); + } +} + diff --git a/src/function.h b/src/function.h index 73dcb01..7035d2f 100644 --- a/src/function.h +++ b/src/function.h @@ -11,7 +11,9 @@ public: virtual ~Function(); void addParam( const char *str ); - virtual void execute( const StringList &lInput, StringList &lOutput )=0; + virtual void execute( Build *bld, const StringList &lInput, StringList &lOutput )=0; + virtual Function *duplicate( Build &bld, const std::string &cont, VarMap *mExtra ) = 0; + void copyData( Function *pSrc, Build &bld, const std::string &cont, VarMap *mExtra ); protected: StringList lParams; diff --git a/src/functioncommandtolist.cpp b/src/functioncommandtolist.cpp index 46762b5..708db5b 100644 --- a/src/functioncommandtolist.cpp +++ b/src/functioncommandtolist.cpp @@ -11,7 +11,58 @@ FunctionCommandToList::~FunctionCommandToList() { } -void FunctionCommandToList::execute( const StringList &lInput, StringList &lOutput ) +void FunctionCommandToList::execute( Build *bld, const StringList &lInput, StringList &lOutput ) { + //rView.beginExtraRequiresCheck( s.c_str() ); + //rView.executeCmd( s.c_str() ); + FILE *fcmd = popen( lParams.front().c_str(), "r" ); + std::string rhs; + bool bHeader = true; + for(;;) + { + if( feof( fcmd ) ) + break; + int cc = fgetc( fcmd ); + if( cc == EOF ) + break; + unsigned char c = cc; + if( bHeader ) + { + if( c == ':' ) + bHeader = false; + } + else + { + if( c == ' ' || c == '\t' ) + { + if( rhs != "" ) + { + lOutput.push_back( rhs ); + rhs = ""; + } + } + else + { + if( c == '\\' ) + c = fgetc( fcmd ); + if( c != '\n' ) + rhs += c; + } + } + } + if( rhs != "" ) + { + lOutput.push_back( rhs ); + rhs = ""; + } + pclose( fcmd ); + //rView.endExtraRequiresCheck(); +} + +Function *FunctionCommandToList::duplicate( Build &bld, const std::string &cont, VarMap *mExtra ) +{ + Function *pRet = new FunctionCommandToList(); + pRet->copyData( this, bld, cont, mExtra ); + return pRet; } diff --git a/src/functioncommandtolist.h b/src/functioncommandtolist.h index 176e40f..c74ce29 100644 --- a/src/functioncommandtolist.h +++ b/src/functioncommandtolist.h @@ -11,7 +11,8 @@ public: FunctionCommandToList(); virtual ~FunctionCommandToList(); - virtual void execute( const StringList &lInput, StringList &lOutput ); + virtual void execute( Build *bld, const StringList &lInput, StringList &lOutput ); + virtual Function *duplicate( Build &bld, const std::string &cont, VarMap *mExtra ); private: diff --git a/src/functiondirectoriesin.cpp b/src/functiondirectoriesin.cpp index 9452489..0e90dbc 100644 --- a/src/functiondirectoriesin.cpp +++ b/src/functiondirectoriesin.cpp @@ -11,7 +11,14 @@ FunctionDirectoriesIn::~FunctionDirectoriesIn() { } -void FunctionDirectoriesIn::execute( const StringList &lInput, StringList &lOutput ) +void FunctionDirectoriesIn::execute( Build *bld, const StringList &lInput, StringList &lOutput ) { } +Function *FunctionDirectoriesIn::duplicate( Build &bld, const std::string &cont, VarMap *mExtra ) +{ + Function *pRet = new FunctionDirectoriesIn(); + pRet->copyData( this, bld, cont, mExtra ); + return pRet; +} + diff --git a/src/functiondirectoriesin.h b/src/functiondirectoriesin.h index ba1b2e4..c387577 100644 --- a/src/functiondirectoriesin.h +++ b/src/functiondirectoriesin.h @@ -11,7 +11,8 @@ public: FunctionDirectoriesIn(); virtual ~FunctionDirectoriesIn(); - virtual void execute( const StringList &lInput, StringList &lOutput ); + virtual void execute( Build *bld, const StringList &lInput, StringList &lOutput ); + virtual Function *duplicate( Build &bld, const std::string &cont, VarMap *mExtra ); private: diff --git a/src/functionfilesin.cpp b/src/functionfilesin.cpp index 3e1233a..e3d8e92 100644 --- a/src/functionfilesin.cpp +++ b/src/functionfilesin.cpp @@ -14,7 +14,7 @@ FunctionFilesIn::~FunctionFilesIn() { } -void FunctionFilesIn::execute( const StringList &lInput, StringList &lOutput ) +void FunctionFilesIn::execute( Build *bld, const StringList &lInput, StringList &lOutput ) { DIR *d = opendir( lParams.front().c_str() ); if( d == NULL ) @@ -38,3 +38,10 @@ void FunctionFilesIn::execute( const StringList &lInput, StringList &lOutput ) closedir( d ); } +Function *FunctionFilesIn::duplicate( Build &bld, const std::string &cont, VarMap *mExtra ) +{ + Function *pRet = new FunctionFilesIn(); + pRet->copyData( this, bld, cont, mExtra ); + return pRet; +} + diff --git a/src/functionfilesin.h b/src/functionfilesin.h index b660301..dc504b9 100644 --- a/src/functionfilesin.h +++ b/src/functionfilesin.h @@ -11,7 +11,8 @@ public: FunctionFilesIn(); virtual ~FunctionFilesIn(); - virtual void execute( const StringList &lInput, StringList &lOutput ); + virtual void execute( Build *bld, const StringList &lInput, StringList &lOutput ); + virtual Function *duplicate( Build &bld, const std::string &cont, VarMap *mExtra ); private: diff --git a/src/functionregexp.cpp b/src/functionregexp.cpp index d1491e6..57a1725 100644 --- a/src/functionregexp.cpp +++ b/src/functionregexp.cpp @@ -12,7 +12,7 @@ FunctionRegexp::~FunctionRegexp() { } -void FunctionRegexp::execute( const StringList &lInput, StringList &lOutput ) +void FunctionRegexp::execute( Build *bld, const StringList &lInput, StringList &lOutput ) { if( lParams.size() == 1 ) { @@ -24,6 +24,16 @@ void FunctionRegexp::execute( const StringList &lInput, StringList &lOutput ) if( re.execute( (*i).c_str() ) ) { lOutput.push_back( *i ); + if( bld ) + { + int jmax = re.getNumSubStrings(); + for( int j = 0; j < jmax; j++ ) + { + char buf[30]; + sprintf( buf, "re:%d", j ); + bld->set( *i, buf, re.getSubString( j ) ); + } + } } } } @@ -32,3 +42,10 @@ void FunctionRegexp::execute( const StringList &lInput, StringList &lOutput ) } } +Function *FunctionRegexp::duplicate( Build &bld, const std::string &cont, VarMap *mExtra ) +{ + Function *pRet = new FunctionRegexp(); + pRet->copyData( this, bld, cont, mExtra ); + return pRet; +} + diff --git a/src/functionregexp.h b/src/functionregexp.h index 9fa2eb4..1dfd91e 100644 --- a/src/functionregexp.h +++ b/src/functionregexp.h @@ -11,7 +11,8 @@ public: FunctionRegexp(); virtual ~FunctionRegexp(); - virtual void execute( const StringList &lInput, StringList &lOutput ); + virtual void execute( Build *bld, const StringList &lInput, StringList &lOutput ); + virtual Function *duplicate( Build &bld, const std::string &cont, VarMap *mExtra ); private: diff --git a/src/functiontostring.cpp b/src/functiontostring.cpp index a76705a..0a7bb48 100644 --- a/src/functiontostring.cpp +++ b/src/functiontostring.cpp @@ -11,7 +11,23 @@ FunctionToString::~FunctionToString() { } -void FunctionToString::execute( const StringList &lInput, StringList &lOutput ) +void FunctionToString::execute( Build *bld, const StringList &lInput, StringList &lOutput ) { + std::string sOut; + + for( StringList::const_iterator i = lInput.begin(); i != lInput.end(); i++ ) + { + if( i != lInput.begin() ) sOut += " "; + sOut += *i; + } + + lOutput.push_back( sOut ); +} + +Function *FunctionToString::duplicate( Build &bld, const std::string &cont, VarMap *mExtra ) +{ + Function *pRet = new FunctionToString(); + pRet->copyData( this, bld, cont, mExtra ); + return pRet; } diff --git a/src/functiontostring.h b/src/functiontostring.h index 5e64256..4779712 100644 --- a/src/functiontostring.h +++ b/src/functiontostring.h @@ -11,7 +11,8 @@ public: FunctionToString(); virtual ~FunctionToString(); - virtual void execute( const StringList &lInput, StringList &lOutput ); + virtual void execute( Build *bld, const StringList &lInput, StringList &lOutput ); + virtual Function *duplicate( Build &bld, const std::string &cont, VarMap *mExtra ); private: diff --git a/src/main.cpp b/src/main.cpp index 02cb9d6..9106a74 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -91,8 +91,6 @@ int main( int argc, char *argv[] ) // printf("\n\n----------\nDebug dump\n----------\n"); // bld.debugDump(); //} - // printf("\n\n----------\nDebug dump\n----------\n"); - // pBuild->debugDump(); //else { if( prm.sAction > 0 ) @@ -100,6 +98,8 @@ int main( int argc, char *argv[] ) else pBuild->execAction(""); } + //printf("\n\n----------\nDebug dump\n----------\n"); + //pBuild->debugDump(); delete pBuild; } diff --git a/src/perform.h b/src/perform.h index 93c8b9a..ea8d5e3 100644 --- a/src/perform.h +++ b/src/perform.h @@ -17,7 +17,8 @@ public: virtual ~Perform(); void addParam( const char *sParam ); - virtual Perform *duplicate( Build &bld, const std::string &cont ) = 0; + virtual Perform *duplicate( Build &bld, const std::string &cont, VarMap *mExtra ) = 0; + virtual void execute( Build &bld ) = 0; void copyData( Perform *pSrc, Build &bld, const std::string &cont, VarMap *mExtra ); std::string getTarget() { @@ -28,9 +29,26 @@ public: this->sTarget = sTarget; } -private: + std::list &getReqFuncs() + { + return lReqFuncs; + } + + void setRule( const std::string &sRule ) + { + this->sRule = sRule; + } + + std::string &getRule() + { + return sRule; + } + +protected: std::list lParam; std::string sTarget; + std::string sRule; + std::list lReqFuncs; }; #endif diff --git a/src/performcommand.cpp b/src/performcommand.cpp index 6963022..f6da4ac 100644 --- a/src/performcommand.cpp +++ b/src/performcommand.cpp @@ -11,10 +11,15 @@ PerformCommand::~PerformCommand() { } -Perform *PerformCommand::duplicate( Build &bld, const std::string &cont ) +Perform *PerformCommand::duplicate( Build &bld, const std::string &cont, VarMap *mExtra ) { Perform *pRet = new PerformCommand(); - pRet->copyData( this, bld, cont, NULL ); + pRet->copyData( this, bld, cont, mExtra ); return pRet; } +void PerformCommand::execute( Build &bld ) +{ + system( lParam.front().c_str() ); +} + diff --git a/src/performcommand.h b/src/performcommand.h index b6f7f11..d128845 100644 --- a/src/performcommand.h +++ b/src/performcommand.h @@ -11,7 +11,8 @@ public: PerformCommand(); virtual ~PerformCommand(); - virtual Perform *duplicate( Build &bld, const std::string &cont ); + virtual Perform *duplicate( Build &bld, const std::string &cont, VarMap *mExtra ); + virtual void execute( Build &bld ); private: diff --git a/src/rule.cpp b/src/rule.cpp index 4919eef..c5ed1c2 100644 --- a/src/rule.cpp +++ b/src/rule.cpp @@ -1,6 +1,10 @@ #include "rule.h" +#include "build.h" +#include "function.h" +#include "perform.h" -Rule::Rule() +Rule::Rule() : + pAggregate( NULL ) { } @@ -12,6 +16,112 @@ StringList Rule::execute( Build &bld, StringList &lInput, PerformList &lPerf ) { StringList lOutput; + RuleList rl = bld.findChainRules( this ); + + for( RuleList::iterator i = rl.begin(); i != rl.end(); i++ ) + { + StringList tmp = (*i)->execute( bld, lInput, lPerf ); + lOutput.insert( lOutput.end(), tmp.begin(), tmp.end() ); + } + + StringList lMine; + for( FunctionList::iterator i = lMatches.begin(); i != lMatches.end(); i++ ) + { + (*i)->execute( &bld, lInput, lMine ); + } + + StringList lTmp; + for( FunctionList::iterator i = lFilter.begin(); i != lFilter.end(); i++ ) + { + (*i)->execute( &bld, lMine, lTmp ); + lMine.swap( lTmp ); + lTmp.clear(); + } + + bool bHasProduces = true; + if( lProduces.empty() ) + { + bHasProduces = false; + lProduces.push_back( sTarget ); + } + + StringList lNewOut; + if( pAggregate ) + { + VarMap mTmp; + std::string target = lProduces.front();//, lProduces.front(), NULL ).c_str(); + mTmp["target"] = target; + lNewOut.push_back( target ); + + for( StringList::iterator i = lMine.begin(); i != lMine.end(); i++ ) + { + bld.addRequires( target, (*i) ); + } + for( StringList::iterator i = lReqStrs.begin(); + i != lReqStrs.end(); i++ ) + { + bld.addRequires( target, (*i) ); + } + + StringList lTmp; + pAggregate->execute( &bld, lMine, lTmp ); + mTmp["match"] = lTmp.front(); + + for( PerformList::iterator k = lPerform.begin(); + k != lPerform.end(); k++ ) + { + Perform *p = (*k)->duplicate( bld, target, &mTmp ); + p->setTarget( target ); + p->setRule( sName ); + //p->setReqFuncs( &lReqFuncs ); + lPerf.push_back( p ); + } + } + else + { + for( StringList::iterator i = lMine.begin(); i != lMine.end(); i++ ) + { + for( StringList::iterator j = lProduces.begin(); + j != lProduces.end(); j++ ) + { + VarMap mTmp; + std::string target = bld.replVars( (*j), (*i), NULL ); + mTmp["target"] = target; + lNewOut.push_back( target ); + mTmp["match"] = (*i); + bld.addRequires( target, (*i) ); + for( StringList::iterator k = lReqStrs.begin(); + k != lReqStrs.end(); k++ ) + { + bld.addRequires( target, (*k) ); + } + for( PerformList::iterator k = lPerform.begin(); + k != lPerform.end(); k++ ) + { + Perform *p = (*k)->duplicate( bld, (*i), &mTmp ); + p->setTarget( target ); + p->setRule( sName ); + for( FunctionList::iterator f = lReqFuncs.begin(); + f != lReqFuncs.end(); f++ ) + { + p->getReqFuncs().push_back( + (*f)->duplicate( bld, (*i), &mTmp ) + ); + } + lPerf.push_back( p ); + } + } + } + } + + lInput.insert( lInput.end(), lNewOut.begin(), lNewOut.end() ); + lOutput.insert( lOutput.end(), lNewOut.begin(), lNewOut.end() ); + + if( bHasProduces == false ) + { + lProduces.clear(); + } + return lOutput; } diff --git a/src/rule.h b/src/rule.h index 5b2bbfd..98c95a6 100644 --- a/src/rule.h +++ b/src/rule.h @@ -21,6 +21,11 @@ public: StringList execute( Build &bld, StringList &lInput, PerformList &lPerf ); + void setTarget( const std::string &sTarget ) + { + this->sTarget = sTarget; + } + std::string getName() { return sName; @@ -46,11 +51,36 @@ public: return lMatches; } + StringList &getProducesList() + { + return lProduces; + } + + void setAggregate( Function *pAggregate ) + { + this->pAggregate = pAggregate; + } + + StringList &getReqStrList() + { + return lReqStrs; + } + + FunctionList &getReqFuncList() + { + return lReqFuncs; + } + private: std::string sName; FunctionList lMatches; FunctionList lFilter; PerformList lPerform; + StringList lProduces; + std::string sTarget; + Function *pAggregate; + StringList lReqStrs; + FunctionList lReqFuncs; }; #endif diff --git a/src/targetfile.cpp b/src/targetfile.cpp index dc9e597..0299f9d 100644 --- a/src/targetfile.cpp +++ b/src/targetfile.cpp @@ -2,6 +2,9 @@ #include "plugger.h" #include "rule.h" #include "build.h" +#include "perform.h" +#include "function.h" +#include "viewer.h" PluginInterface2(file, TargetFile, Target, "Mike Buland", 0, 1 ); @@ -15,26 +18,43 @@ TargetFile::~TargetFile() void TargetFile::check( Build &bld ) { - printf("Target file checking: %s\n", getName().c_str() ); - Rule *pRule = bld.getRule( getRule() ); PerformList lPerf; + pRule->setTarget( getName() ); StringList lFinal = pRule->execute( bld, getInput(), lPerf ); - printf("Input: "); - for( StringList::iterator i = getInput().begin(); - i != getInput().end(); i++ ) - { - if( i != getInput().begin() ) printf(", "); - printf("%s", (*i).c_str() ); - } - printf("\nFinal: "); - for( StringList::iterator i = lFinal.begin(); i != lFinal.end(); i++ ) + for( PerformList::iterator i = lPerf.begin(); i != lPerf.end(); i++ ) { - if( i != lFinal.begin() ) printf(", "); - printf("%s", (*i).c_str() ); + time_t tTarget = getTime( bld, (*i)->getTarget() ); + StringList &reqs = bld.getRequires( (*i)->getTarget() ); + FunctionList::iterator f = (*i)->getReqFuncs().begin(); + bool bBuilt = false; +aastrt: for( StringList::iterator j = reqs.begin(); j != reqs.end(); j++ ) + { + if( getTime( bld, *j ) > tTarget ) + { + bld.getView()->beginPerform( *i ); + (*i)->execute( bld ); + bld.getView()->endPerform(); + updateTime( (*i)->getTarget() ); + bBuilt = true; + break; + } + } + if( bBuilt == true ) + continue; + + if( f != (*i)->getReqFuncs().end() ) + { + StringList lTmpIn; + lTmpIn.push_back( (*i)->getTarget() ); + bld.getView()->beginRequiresCheck( false, (*i)->getTarget() ); + (*f)->execute( &bld, lTmpIn, reqs ); + bld.getView()->endRequiresCheck(); + f++; + goto aastrt; + } } - printf("\n"); } void TargetFile::clean( Build &bld ) @@ -42,3 +62,35 @@ void TargetFile::clean( Build &bld ) printf("Target file cleaning: %s\n", getName().c_str() ); } +time_t TargetFile::getTime( Build &bld, std::string str ) +{ + std::map::iterator i = mTimes.find( str ); + if( i != mTimes.end() ) + { + //nCache++; + //bld.view().beginRequiresCheck( true, str.c_str() ); + //bld.view().endRequiresCheck(); + return (*i).second; + } + + //bld.view().beginRequiresCheck( false, str.c_str() ); + struct stat st; + stat( str.c_str(), &st ); + + mTimes[str] = st.st_mtime; + + //nNew++; + + //bld.view().endRequiresCheck(); + + return st.st_mtime; +} + +void TargetFile::updateTime( std::string str ) +{ + struct stat st; + stat( str.c_str(), &st ); + + mTimes[str] = st.st_mtime; +} + diff --git a/src/targetfile.h b/src/targetfile.h index 37e6770..368e252 100644 --- a/src/targetfile.h +++ b/src/targetfile.h @@ -2,6 +2,10 @@ #define TARGET_FILE_H #include +#include +#include +#include +#include #include "target.h" @@ -14,8 +18,11 @@ public: virtual void check( Build &bld ); virtual void clean( Build &bld ); -private: + time_t getTime( class Build &bld, std::string str ); + void updateTime( std::string str ); +private: + std::map mTimes; }; #endif diff --git a/src/viewer.cpp b/src/viewer.cpp index 93b2ac1..51acc3b 100644 --- a/src/viewer.cpp +++ b/src/viewer.cpp @@ -7,3 +7,48 @@ Viewer::Viewer() Viewer::~Viewer() { } + +void Viewer::beginAction( const std::string &sName, int nCommands ) +{ +} + +void Viewer::endAction() +{ +} + +void Viewer::beginCommand( Action::eAction nAct, const std::string &sTarget, int nPerforms ) +{ +} + +void Viewer::endCommand() +{ +} + +void Viewer::beginRequiresCheck( bool bCached, const std::string &sName ) +{ +} + +void Viewer::endRequiresCheck() +{ +} + +void Viewer::beginPerform( Perform *pPerform ) +{ +} + +void Viewer::endPerform() +{ +} + +void Viewer::beginExecute() +{ +} + +void Viewer::endExecute() +{ +} + +void Viewer::executeCmd( const std::string &sCmd ) +{ +} + diff --git a/src/viewer.h b/src/viewer.h index 04f4ea7..93cebb7 100644 --- a/src/viewer.h +++ b/src/viewer.h @@ -2,7 +2,10 @@ #define VIEWER_H #include +#include +#include "action.h" +class Perform; class Viewer { @@ -10,6 +13,20 @@ public: Viewer(); virtual ~Viewer(); + virtual void beginAction( const std::string &sName, int nCommands ); + virtual void endAction(); + + virtual void beginCommand( Action::eAction nAct, const std::string &sTarget, int nPerforms ); + virtual void endCommand(); + + virtual void beginRequiresCheck( bool bCached, const std::string &sName ); + virtual void endRequiresCheck(); + virtual void beginPerform( Perform *pPerform ); + virtual void endPerform(); + virtual void beginExecute(); + virtual void endExecute(); + virtual void executeCmd( const std::string &sCmd ); + private: }; diff --git a/src/viewerfactory.cpp b/src/viewerfactory.cpp new file mode 100644 index 0000000..3778c37 --- /dev/null +++ b/src/viewerfactory.cpp @@ -0,0 +1,12 @@ +#include "viewerfactory.h" + +extern struct PluginInfo plain; + +ViewerFactory::ViewerFactory() +{ + registerBuiltinPlugin( &plain ); +} + +ViewerFactory::~ViewerFactory() +{ +} diff --git a/src/viewerfactory.h b/src/viewerfactory.h new file mode 100644 index 0000000..8704e03 --- /dev/null +++ b/src/viewerfactory.h @@ -0,0 +1,20 @@ +#ifndef VIEWER_FACTORY_H +#define VIEWER_FACTORY_H + +#include + +#include "viewer.h" +#include "plugger.h" +#include "singleton.h" + +class ViewerFactory : public Plugger, public Singleton +{ +public: + ViewerFactory(); + virtual ~ViewerFactory(); + +private: + +}; + +#endif diff --git a/src/viewerplain.cpp b/src/viewerplain.cpp new file mode 100644 index 0000000..f2123b0 --- /dev/null +++ b/src/viewerplain.cpp @@ -0,0 +1,42 @@ +#include "viewerplain.h" +#include "perform.h" +#include "plugger.h" + +PluginInterface2( plain, ViewerPlain, Viewer, "Mike Buland", 0, 1 ); + +ViewerPlain::ViewerPlain() +{ +} + +ViewerPlain::~ViewerPlain() +{ +} + +void ViewerPlain::beginCommand( Action::eAction nAct, const std::string &sTarget, int nPerforms ) +{ + printf("--- check %s ---\n", sTarget.c_str() ); +} + +void ViewerPlain::endCommand() +{ + printf("---\n"); +} + +void ViewerPlain::beginRequiresCheck( bool bCached, const std::string &sName ) +{ + printf(" deps: %s\n", sName.c_str() ); +} + +void ViewerPlain::endRequiresCheck() +{ +} + +void ViewerPlain::beginPerform( Perform *pPerform ) +{ + printf(" %8s: %s\n", pPerform->getRule().c_str(), pPerform->getTarget().c_str() ); +} + +void ViewerPlain::endPerform() +{ +} + diff --git a/src/viewerplain.h b/src/viewerplain.h new file mode 100644 index 0000000..6e37c28 --- /dev/null +++ b/src/viewerplain.h @@ -0,0 +1,26 @@ +#ifndef VIEWER_PLAIN_H +#define VIEWER_PLAIN_H + +#include + +#include "viewer.h" + +class ViewerPlain : public Viewer +{ +public: + ViewerPlain(); + virtual ~ViewerPlain(); + + virtual void beginCommand( Action::eAction nAct, const std::string &sTarget, int nPerforms ); + virtual void endCommand(); + + virtual void beginRequiresCheck( bool bCached, const std::string &sName ); + virtual void endRequiresCheck(); + virtual void beginPerform( Perform *pPerform ); + virtual void endPerform(); + +private: + +}; + +#endif -- cgit v1.2.3