From d5b78aeaa9af689b52046eb5577624fb6d031835 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 21 Sep 2006 15:21:53 +0000 Subject: Auto target chaining based on requirements is now in place. This means that if a requirement is set for a target that needs to be built, and that requirement is another target, that target will be processed when it is needed. --- src/build.cpp | 21 +++++++++++---------- src/build.h | 2 ++ src/target.cpp | 19 ++++++++++++++++++- src/target.h | 10 ++++++++++ src/targetfile.cpp | 1 + 5 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/build.cpp b/src/build.cpp index c81c885..5121d1f 100644 --- a/src/build.cpp +++ b/src/build.cpp @@ -86,16 +86,8 @@ void Build::execAction( const std::string &sWhat ) ); Target *pTarget = mTarget[pAct->getWhat()]; pView->beginCommand( pAct->getAct(), pAct->getWhat() ); - switch( pAct->getAct() ) - { - case Action::actCheck: - pTarget->check( *this ); - break; - - case Action::actClean: - pTarget->clean( *this ); - break; - } + if( !pTarget->wasRun() ) + pTarget->run( pAct->getAct(), *this ); pView->endCommand(); } @@ -363,3 +355,12 @@ void Build::updateCache( const std::string &sID, FunctionList &lFunc, StringList bCacheUpdated = true; } +void Build::chainTarget( const std::string &sName ) +{ + TargetMap::iterator i = mTarget.find(sName); + if( i == mTarget.end() ) return; + + if( !(*i).second->wasRun() ) + (*i).second->run( Action::actCheck, *this ); +} + diff --git a/src/build.h b/src/build.h index 9229617..6e98405 100644 --- a/src/build.h +++ b/src/build.h @@ -74,6 +74,8 @@ public: bool getCached( const std::string &sID, int nTime, StringList &lOut ); void updateCache( const std::string &sID, FunctionList &lFunc, StringList &lOut ); + void chainTarget( const std::string &sName ); + private: TargetMap mTarget; ReqMap mRequires; diff --git a/src/target.cpp b/src/target.cpp index 834dbaa..a26f76f 100644 --- a/src/target.cpp +++ b/src/target.cpp @@ -1,6 +1,7 @@ #include "target.h" -Target::Target() +Target::Target() : + bRun( false ) { } @@ -8,3 +9,19 @@ Target::~Target() { } +void Target::run( Action::eAction nAct, Build &bld ) +{ + bRun = true; + + switch( nAct ) + { + case Action::actCheck: + check( bld ); + break; + + case Action::actClean: + clean( bld ); + break; + } +} + diff --git a/src/target.h b/src/target.h index 5325965..f51e0e0 100644 --- a/src/target.h +++ b/src/target.h @@ -6,6 +6,8 @@ #include #include +#include "action.h" + typedef std::list StringList; class Build; @@ -16,6 +18,7 @@ public: Target(); virtual ~Target(); + void run( Action::eAction nAct, Build &bld ); virtual void check( Build &bld ) = 0; virtual void clean( Build &bld ) = 0; @@ -44,10 +47,17 @@ public: return lInput; } + bool wasRun() + { + return bRun; + } + + private: std::string sName; std::string sRule; StringList lInput; + bool bRun; }; #endif diff --git a/src/targetfile.cpp b/src/targetfile.cpp index 6ea83d5..950fc7b 100644 --- a/src/targetfile.cpp +++ b/src/targetfile.cpp @@ -32,6 +32,7 @@ void TargetFile::check( Build &bld ) bool bExtras = false; for( StringList::iterator j = reqs.begin(); j != reqs.end(); j++ ) { + bld.chainTarget( *j ); if( getTime( bld, *j ) > tTarget ) { bld.getView()->beginPerform( *i ); -- cgit v1.2.3