From 935bc7d5223883d87f58a6798f4a0ade7df95afc Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 1 Aug 2006 03:09:58 +0000 Subject: It actually builds, now it just needs dependancy tracking, and maybe auto-target check triggering. --- src/builder.cpp | 33 ++++++++++++----- src/builder.h | 9 ++++- src/filetarget.cpp | 12 +++++-- src/filetarget.h | 1 + src/main.cpp | 4 +-- src/perform.cpp | 3 +- src/perform.h | 8 ++++- src/performcmd.cpp | 9 +++-- src/performcmd.h | 1 - src/rule.cpp | 103 ++++++++++++++++++++++++++--------------------------- src/rule.h | 5 +-- 11 files changed, 116 insertions(+), 72 deletions(-) (limited to 'src') diff --git a/src/builder.cpp b/src/builder.cpp index 852d70d..6bde1b4 100644 --- a/src/builder.cpp +++ b/src/builder.cpp @@ -248,9 +248,8 @@ void Builder::processRequires( std::list &lInput ) if( re->execute( (*j).c_str() ) ) { varmap *revars = regexVars( re ); - FILE *fcmd = popen( - varRepl( (*i).second.c_str(), "", revars ).c_str(), - "r" ); + std::string s = varRepl( (*i).second.c_str(), "", revars ); + FILE *fcmd = popen( s.c_str(), "r" ); std::string rhs; bool bHeader = true; for(;;) @@ -296,7 +295,7 @@ void Builder::processRequires( std::list &lInput ) ); rhs = ""; } - fclose( fcmd ); + pclose( fcmd ); delete revars; } } @@ -407,17 +406,17 @@ std::string Builder::varRepl( const char *sSrc, const char *cont, varmap *mExtra } else if( *s == '}' && bVar ) { - if( hasVar( &mVar, var ) ) + if( hasVar( mExtra, var ) ) { - out += mVar[var]; + out += (*mExtra)[var]; } else if( hasVar( mCont, var ) ) { out += (*mCont)[var]; } - else if( hasVar( mExtra, var ) ) + else if( hasVar( &mVar, var ) ) { - out += (*mExtra)[var]; + out += mVar[var]; } var = ""; bVar = false; @@ -464,3 +463,21 @@ std::list Builder::findRuleChain( Rule *pRule ) return ret; } +void cleanList( std::list &lst ) +{ + std::map m; + + for( std::list::iterator i = lst.begin(); i != lst.end(); i++ ) + { + if( m.find( *i ) == m.end() ) + m[ *i ] = true; + else + { + std::list::iterator j = i; + j--; + lst.erase( i ); + i = j; + } + } +} + diff --git a/src/builder.h b/src/builder.h index faa82c2..f21e411 100644 --- a/src/builder.h +++ b/src/builder.h @@ -100,11 +100,16 @@ public: return mTarget[sName]; } + std::list getRequires( const char *sReq ) + { + return mRequires[sReq]; + } + typedef std::map varmap; varmap *regexVars( RegExp *re ); std::string varRepl( const char *sSrc, const char *cont, varmap *mExtra ); -private: +private: void requiresNormal( const char *sBase, const char *sReq ); void requiresRegexp( const char *sBase, const char *sReq ); void checkVar( const char *cont, const char *sName ); @@ -139,4 +144,6 @@ private: bool bReqRegexp; }; +void cleanList( std::list &lst ); + #endif diff --git a/src/filetarget.cpp b/src/filetarget.cpp index 3fefd9f..1880c35 100644 --- a/src/filetarget.cpp +++ b/src/filetarget.cpp @@ -70,10 +70,18 @@ void FileTarget::check( Builder &bld ) { Rule *pRule = bld.getRule( sRule ); - std::list tmp = pRule->execute( bld, lInput, getName() ); + std::list perf; + std::list tmp = pRule->execute( bld, lInput, perf, getName() ); lOutput.insert( lOutput.end(), tmp.begin(), tmp.end() ); - bld.processRequires( lInput ); + bld.processRequires( lOutput ); + + for( std::list::iterator i = perf.begin(); + i != perf.end(); i++ ) + { + std::list lReqs = bld.getRequires( (*i)->getTarget() ); + + } } void FileTarget::clean( Builder &bld ) diff --git a/src/filetarget.h b/src/filetarget.h index 11dc180..c872c0a 100644 --- a/src/filetarget.h +++ b/src/filetarget.h @@ -18,6 +18,7 @@ public: virtual void clean( class Builder &bld ); private: + // start here with the file time cache }; diff --git a/src/main.cpp b/src/main.cpp index 2e13b16..ebf0cfd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,8 +7,8 @@ int main() bld.load("build.conf"); bld.build(); - +/* printf("\n\n----------\nDebug dump\n----------\n"); - bld.debug(); + bld.debug();*/ } diff --git a/src/perform.cpp b/src/perform.cpp index 937a76c..d7082a0 100644 --- a/src/perform.cpp +++ b/src/perform.cpp @@ -1,6 +1,7 @@ #include "perform.h" -Perform::Perform() +Perform::Perform( const char *sTarget ) : + sTarget( sTarget ) { } diff --git a/src/perform.h b/src/perform.h index fefb05e..2eb8cb0 100644 --- a/src/perform.h +++ b/src/perform.h @@ -6,12 +6,18 @@ class Perform { public: - Perform(); + Perform( const char *sTarget ); virtual ~Perform(); virtual void execute( class Builder &bld ) = 0; + const char *getTarget() + { + return sTarget; + } + private: + StaticString sTarget; }; diff --git a/src/performcmd.cpp b/src/performcmd.cpp index 21ba737..724f42b 100644 --- a/src/performcmd.cpp +++ b/src/performcmd.cpp @@ -2,8 +2,8 @@ #include "builder.h" PerformCmd::PerformCmd( const char *sCmd, const char *sTarget ) : + Perform( sTarget ), sCommand( sCmd ), - sTarget( sTarget ) { } @@ -14,6 +14,11 @@ PerformCmd::~PerformCmd() void PerformCmd::execute( class Builder &bld ) { printf("%s\n", sCommand.getString() ); - system( sCommand.getString() ); + int ret; + if( (ret = system( sCommand.getString() )) != 0 ) + { + printf("Error code: %d\n", WEXITSTATUS(ret) ); + exit( WEXITSTATUS(ret) ); + } } diff --git a/src/performcmd.h b/src/performcmd.h index 3bc83aa..59510a6 100644 --- a/src/performcmd.h +++ b/src/performcmd.h @@ -16,7 +16,6 @@ public: private: StaticString sCommand; - StaticString sTarget; }; #endif diff --git a/src/rule.cpp b/src/rule.cpp index 4425ea5..979075b 100644 --- a/src/rule.cpp +++ b/src/rule.cpp @@ -67,20 +67,48 @@ void Rule::setPerforms( ePerform pwhat, const char *sperfcmd ) sPerfCmd = sperfcmd; } -Perform *Rule::buildCommand( Builder &bld, const char *sCmd, const char *sTarget, const char *sMatches ) +Perform *Rule::buildCommand( Builder &bld, const char *sCmd, Builder::varmap *vars ) { - Builder::varmap vars; - vars["target"] = sTarget; - vars["match"] = sMatches; - return new PerformCmd( bld.varRepl( sCmd, "", &vars ).c_str(), sTarget ); + return new PerformCmd( + bld.varRepl( sCmd, (*vars)["target"].c_str(), vars ).c_str(), + (*vars)["target"].c_str() + ); } -std::list Rule::findTargets( Builder &bld, std::list &lIn, std::string &sMatches, const char *sTarget ) +std::list Rule::execute( Builder &bld, std::list lInput, std::list &lPerf, const char *sTarget ) { - std::list lTmp; + std::list lRule = bld.findRuleChain( this ); + /* + if( !lRule.empty() ) + { + printf("Rule %s chains to: ", sName.getString() ); + for( std::list::iterator i = lRule.begin(); + i != lRule.end(); i++ ) + { + if( i != lRule.begin() ) + printf(", "); + printf("%s", (*i)->sName.getString() ); + } + printf("\n"); + }*/ - for( std::list::iterator i = lIn.begin(); - i != lIn.end(); i++ ) + std::list lOutput; + std::string sMatches; + + for( std::list::iterator i = lRule.begin(); i != lRule.end(); i++ ) + { + std::list lTmp = (*i)->execute( bld, lInput, lPerf ); + lOutput.insert( lOutput.end(), lTmp.begin(), lTmp.end() ); + } + + std::list lTest; + lTest.insert( lTest.end(), lInput.begin(), lInput.end() ); + lTest.insert( lTest.end(), lOutput.begin(), lOutput.end() ); + + cleanList( lTest ); + + for( std::list::iterator i = lTest.begin(); + i != lTest.end(); i++ ) { if( rWhat.execute( (*i).c_str() ) ) { @@ -90,21 +118,22 @@ std::list Rule::findTargets( Builder &bld, std::list & { if( mHow == matchOne ) { - lTmp.push_back( + lOutput.push_back( bld.varRepl( (*j).c_str(), "", revars ) ); + (*revars)["target"] = (sTarget==NULL)? + (lOutput.back().c_str()):(sTarget); + (*revars)["match"] = (*i).c_str(); Perform *p = buildCommand( bld, sPerfCmd, - (sTarget==NULL)?(lTmp.back().c_str()):(sTarget), - (*i).c_str() + revars ); - p->execute( bld ); - delete p; + lPerf.push_back( p ); } else if( mHow == matchAll ) { @@ -115,57 +144,27 @@ std::list Rule::findTargets( Builder &bld, std::list & delete revars; } } - - return lTmp; -} - -std::list Rule::execute( Builder &bld, std::list lInput, const char *sTarget ) -{ - std::list lRule = bld.findRuleChain( this ); - - if( !lRule.empty() ) - { - printf("Rule %s chains to: ", sName.getString() ); - for( std::list::iterator i = lRule.begin(); - i != lRule.end(); i++ ) - { - if( i != lRule.begin() ) - printf(", "); - printf("%s", (*i)->sName.getString() ); - } - printf("\n"); - } - - std::list lOutput; - std::string sMatches; - - for( std::list::iterator i = lRule.begin(); i != lRule.end(); i++ ) - { - std::list lTmp = (*i)->execute( bld, lInput ); - lOutput.insert( lOutput.end(), lTmp.begin(), lTmp.end() ); - } - - std::list lTmp = findTargets( bld, lInput, sMatches, sTarget ); - lOutput.insert( lOutput.end(), lTmp.begin(), lTmp.end() ); - lTmp = findTargets( bld, lOutput, sMatches, sTarget ); - lOutput.insert( lOutput.end(), lTmp.begin(), lTmp.end() ); + //std::list lTmp = findTargets( bld, lTest, sMatches, sTarget ); + //lOutput.insert( lOutput.end(), lTmp.begin(), lTmp.end() ); if( mHow == matchAll ) { lOutput.push_back( bld.varRepl( sTarget, - "", + sTarget, NULL ) ); + Builder::varmap vars; + vars["target"] = sTarget; + vars["match"] = sMatches; Perform *p = buildCommand( bld, sPerfCmd, - sTarget, - sMatches.c_str() + &vars ); - p->execute( bld ); + lPerf.push_back( p ); } return lOutput; diff --git a/src/rule.h b/src/rule.h index 8246cc9..b7c0049 100644 --- a/src/rule.h +++ b/src/rule.h @@ -6,6 +6,7 @@ #include #include "regexp.h" #include "staticstring.h" +#include "builder.h" class Perform; @@ -40,10 +41,10 @@ public: bool willChain( Rule *pRule ); - std::list execute( class Builder &bld, std::list lInput, const char *sTarget=NULL ); + std::list execute( class Builder &bld, std::list lInput, std::list &lPerf, const char *sTarget=NULL ); private: - class Perform *buildCommand( class Builder &bld, const char *sCmd, const char *sTarget, const char *sMatches ); + class Perform *buildCommand( class Builder &bld, const char *sCmd, Builder::varmap *vars ); std::list findTargets( class Builder &bld, std::list &lIn, std::string &sMatches, const char *sTarget ); StaticString sName; std::list lProduces; -- cgit v1.2.3