From 6aedf75408f0a8fa50edf9457b00f413227ec2d8 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 21 Sep 2006 15:47:56 +0000 Subject: Added two command line parameters, -i or --info will list available actions, maybe more later. -c or --clean will set all of the commands in the current action to clean, so now you don't have to create clean rules. Also, every viewer should now support stacks of targets, they don't now, and it can look a little funny. --- src/action.cpp | 8 ++++++++ src/action.h | 2 ++ src/build.cpp | 27 +++++++++++++++++++++++++-- src/build.h | 4 ++++ src/main.cpp | 25 +++++++++++++++++++++++-- src/target.cpp | 4 ++++ 6 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/action.cpp b/src/action.cpp index be11f48..cae4f01 100644 --- a/src/action.cpp +++ b/src/action.cpp @@ -38,3 +38,11 @@ std::string Action::getWhat() return (*i).sWhat; } +void Action::setMode( eAction nAct ) +{ + for( CmdList::iterator j = lCmds.begin(); j != lCmds.end(); j++ ) + { + (*j).act = nAct; + } +} + diff --git a/src/action.h b/src/action.h index 0e08192..25badad 100644 --- a/src/action.h +++ b/src/action.h @@ -50,6 +50,8 @@ public: { return sName; } + + void setMode( eAction nAct ); private: typedef std::list CmdList; diff --git a/src/build.cpp b/src/build.cpp index 5121d1f..889efa4 100644 --- a/src/build.cpp +++ b/src/build.cpp @@ -85,10 +85,10 @@ void Build::execAction( const std::string &sWhat ) sWhat.c_str() ); Target *pTarget = mTarget[pAct->getWhat()]; - pView->beginCommand( pAct->getAct(), pAct->getWhat() ); + //pView->beginCommand( pAct->getAct(), pAct->getWhat() ); if( !pTarget->wasRun() ) pTarget->run( pAct->getAct(), *this ); - pView->endCommand(); + //pView->endCommand(); } pView->endAction(); @@ -364,3 +364,26 @@ void Build::chainTarget( const std::string &sName ) (*i).second->run( Action::actCheck, *this ); } +void Build::printInfo() +{ + printf("---- Build Info ----\n"); + printf("Valid actions: "); + for( ActionMap::iterator i = mAction.begin(); i != mAction.end(); i++ ) + { + if( i != mAction.begin() ) printf(", "); + if( (*i).first == "" ) + printf("*default*"); + else + printf("%s", (*i).first.c_str() ); + } + printf("\n\n"); +} + +void Build::setMode( Action::eAction nAct ) +{ + for( ActionMap::iterator i = mAction.begin(); i != mAction.end(); i++ ) + { + (*i).second->setMode( nAct ); + } +} + diff --git a/src/build.h b/src/build.h index 6e98405..dd8c11b 100644 --- a/src/build.h +++ b/src/build.h @@ -76,6 +76,10 @@ public: void chainTarget( const std::string &sName ); + void printInfo(); + + void setMode( Action::eAction nAct ); + private: TargetMap mTarget; ReqMap mRequires; diff --git a/src/main.cpp b/src/main.cpp index 1576b0c..85886f5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include "paramproc.h" #include "staticstring.h" #include "build.h" +#include "action.h" class Param : public ParamProc { @@ -14,17 +15,23 @@ public: sCache(".build.cache"), bDebug( false ), bPostDebug( false ), - sView("plain") + sView("plain"), + bInfo( false ), + bCleanMode( false ) { addHelpBanner("Build r?\n\n"); addParam("file", 'f', &sFile, "Set the input script, default: build.conf"); + addParam("info", 'i', &bInfo, + "Display useful info about the loaded config file.", NULL, "true" ); + addParam("clean", 'c', &bCleanMode, + "Clean instead of checking the given action.", NULL, "true" ); addParam('p', mkproc(Param::procViewPercent), "Switch to percent view."); addParam('m', mkproc(Param::procViewMake), "Switch to 'make' style view."); addParam("cache", &sCache, - "Set an alternative cache file." ); + "Set an alternative cache file, default: .build.cache" ); addParam('d', &bDebug, "Display debug info instead of building", NULL, "true" ); addParam('D', &bPostDebug, @@ -67,6 +74,8 @@ public: //Viewer *pViewer; bool bDebug; bool bPostDebug; + bool bInfo; + bool bCleanMode; private: }; @@ -84,6 +93,15 @@ int main( int argc, char *argv[] ) pBuild = bld.load( prm.sFile.c_str() ); pBuild->setCache( prm.sCache ); pBuild->setView( prm.sView ); + if( prm.bCleanMode ) + pBuild->setMode( Action::actClean ); + + if( prm.bInfo ) + { + pBuild->printInfo(); + delete pBuild; + return 0; + } if( prm.bDebug ) { printf("\n\n----------\nDebug dump\n----------\n"); @@ -111,9 +129,12 @@ int main( int argc, char *argv[] ) printf("\n\n----------\nDebug dump\n----------\n"); pBuild->debugDump(); } + delete pBuild; return 1; } delete pBuild; + + return 0; } diff --git a/src/target.cpp b/src/target.cpp index a26f76f..3150c38 100644 --- a/src/target.cpp +++ b/src/target.cpp @@ -1,4 +1,6 @@ #include "target.h" +#include "build.h" +#include "viewer.h" Target::Target() : bRun( false ) @@ -13,6 +15,7 @@ void Target::run( Action::eAction nAct, Build &bld ) { bRun = true; + bld.getView()->beginCommand( nAct, sName ); switch( nAct ) { case Action::actCheck: @@ -23,5 +26,6 @@ void Target::run( Action::eAction nAct, Build &bld ) clean( bld ); break; } + bld.getView()->endCommand(); } -- cgit v1.2.3