From f88e5c349ff0107ac4a13ae00180f767741f88d1 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 24 Apr 2007 15:43:35 +0000 Subject: Build groups are finished, there may be more we could do with them, but they work just fine for what I want. They're cute though, you can put each target in as many groups as you'd like. --- build.conf | 2 +- src/action.cpp | 9 +++++++-- src/action.h | 8 +++++--- src/build.cpp | 41 ++++++++++++++++++++++++++++++----------- src/build.y | 6 ++++++ src/buildparser.cpp | 41 +++++++++++++++++++++++++++++++---------- src/buildparser.h | 16 +++++++++++++++- 7 files changed, 95 insertions(+), 28 deletions(-) diff --git a/build.conf b/build.conf index 01ef6b6..3a2f96a 100644 --- a/build.conf +++ b/build.conf @@ -1,6 +1,6 @@ # build.conf for build, kind of whacky, eh? -default action: check targets() +default action: check group "program" "clean" action: clean targets() "rebuild" action: clean "build", check "build" diff --git a/src/action.cpp b/src/action.cpp index cae4f01..2588caa 100644 --- a/src/action.cpp +++ b/src/action.cpp @@ -8,9 +8,9 @@ Action::~Action() { } -void Action::addCommand( eAction act, const std::string &sWhat ) +void Action::addCommand( eAction act, const std::string &sWhat, bool bIsGroup ) { - lCmds.push_back( Cmd( act, sWhat ) ); + lCmds.push_back( Cmd( act, sWhat, bIsGroup ) ); } void Action::begin() @@ -38,6 +38,11 @@ std::string Action::getWhat() return (*i).sWhat; } +bool Action::isGroup() +{ + return (*i).bIsGroup; +} + void Action::setMode( eAction nAct ) { for( CmdList::iterator j = lCmds.begin(); j != lCmds.end(); j++ ) diff --git a/src/action.h b/src/action.h index 25badad..929c1c5 100644 --- a/src/action.h +++ b/src/action.h @@ -20,14 +20,15 @@ public: typedef struct Cmd { - Cmd( eAction act, const std::string &sWhat ) : - act( act ), sWhat( sWhat ) + Cmd( eAction act, const std::string &sWhat, bool bIsGroup ) : + act( act ), sWhat( sWhat ), bIsGroup( bIsGroup ) {} eAction act; std::string sWhat; + bool bIsGroup; } Cmd; - void addCommand( eAction act, const std::string &sWhat ); + void addCommand( eAction act, const std::string &sWhat, bool bIsGroup ); void begin(); bool isEnded(); @@ -40,6 +41,7 @@ public: eAction getAct(); std::string getWhat(); + bool isGroup(); void setName( const std::string &sName ) { diff --git a/src/build.cpp b/src/build.cpp index db14750..a7421de 100644 --- a/src/build.cpp +++ b/src/build.cpp @@ -78,17 +78,36 @@ void Build::execAction( const std::string &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()]; - //pView->beginCommand( pAct->getAct(), pAct->getWhat() ); - if( !pTarget->wasRun() ) - pTarget->run( pAct->getAct(), *this ); - //pView->endCommand(); + if( pAct->isGroup() ) + { + if( mGroup.find( pAct->getWhat() ) == mGroup.end() ) + throw BuildException( + "No group matches %s in action %s.", + pAct->getWhat().c_str(), + sWhat.c_str() + ); + TargetList &sl = mGroup[pAct->getWhat()]; + for( TargetList::iterator i = sl.begin(); i != sl.end(); i++ ) + { + Target *pTarget = *i; + if( !pTarget->wasRun() ) + pTarget->run( pAct->getAct(), *this ); + } + } + else + { + 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()]; + //pView->beginCommand( pAct->getAct(), pAct->getWhat() ); + if( !pTarget->wasRun() ) + pTarget->run( pAct->getAct(), *this ); + //pView->endCommand(); + } } pView->endAction(); diff --git a/src/build.y b/src/build.y index bfda4b4..55940e8 100644 --- a/src/build.y +++ b/src/build.y @@ -125,7 +125,13 @@ actioncmd: TOK_CHECK list bld.addCommand( Action::actClean ); } | TOK_CHECK TOK_GROUP STRING + { + bld.addGrpCommand( $3, Action::actCheck ); + } | TOK_CLEAN TOK_GROUP STRING + { + bld.addGrpCommand( $3, Action::actClean ); + } ; // Target interpretation diff --git a/src/buildparser.cpp b/src/buildparser.cpp index 364aaa5..50fc0fc 100644 --- a/src/buildparser.cpp +++ b/src/buildparser.cpp @@ -283,7 +283,7 @@ void BuildParser::addPerformParam( const char *sParam ) // void BuildParser::addAction() { - lActions.push_back( ActionTmp("", ActionTmpCmdList()) ); + lActions.push_back( ActionTmp("", ActionTmpCmdList() ) ); } void BuildParser::addAction( const char *sName ) @@ -296,6 +296,11 @@ void BuildParser::addCommand( int nType ) lActions.back().second.push_back( ActionTmpCmd( nType, lTmp ) ); } +void BuildParser::addGrpCommand( const char *sGroup, int nType ) +{ + lActions.back().second.push_back( ActionTmpCmd( nType, sGroup ) ); +} + // // Global variable functions // @@ -324,8 +329,15 @@ void BuildParser::debugDump() for( ActionTmpCmdList::iterator j = (*i).second.begin(); j != (*i).second.end(); j++ ) { - printf(" %d ", (*j).first ); - printBuildList( (*j).second ); + printf(" %d ", (*j).nAct ); + if( (*j).bGroup ) + { + printf("!%s", (*j).sGroup.c_str() ); + } + else + { + printBuildList( (*j).lCmds ); + } printf("\n"); } } @@ -555,14 +567,23 @@ Build *BuildParser::genBuild() for( ActionTmpCmdList::iterator j = (*i).second.begin(); j != (*i).second.end(); j++ ) { - StringList lWhat = buildToStringList( - (*j).second, StringList(), bld - ); - - for( StringList::iterator k = lWhat.begin(); - k != lWhat.end(); k++ ) + if( (*j).bGroup ) + { + pAct->addCommand( + (Action::eAction)((*j).nAct), (*j).sGroup, true + ); + } + else { - pAct->addCommand( (Action::eAction)((*j).first), *k ); + StringList lWhat = buildToStringList( + (*j).lCmds, StringList(), bld + ); + + for( StringList::iterator k = lWhat.begin(); + k != lWhat.end(); k++ ) + { + pAct->addCommand( (Action::eAction)((*j).nAct), *k, false ); + } } } diff --git a/src/buildparser.h b/src/buildparser.h index fd988c6..516760c 100644 --- a/src/buildparser.h +++ b/src/buildparser.h @@ -156,10 +156,24 @@ public: // Action functions void addAction(); void addAction( const char *sName ); void addCommand( int nType ); + void addGrpCommand( const char *sGroup, int nType ); private: // Action variables - typedef std::pair ActionTmpCmd; + typedef struct ActionTmpCmd + { + ActionTmpCmd( int nAct, BuildList &l ) : + nAct( nAct ), bGroup( false ), lCmds( l ) { }; + ActionTmpCmd( int nAct, const char *s ) : + nAct( nAct ), bGroup( true ), sGroup( s ) { }; + int nAct; + bool bGroup; + BuildList lCmds; + std::string sGroup; + } ActionTmpCmd; + //typedef std::pair ActionTmpCmd; + //typedef std::pair ActionTmpGrpCmd typedef std::list ActionTmpCmdList; + //typedef std::list ActionTmpGrpCmdList; typedef std::pair ActionTmp; typedef std::list ActionTmpList; ActionTmpList lActions; -- cgit v1.2.3