From 4ab0bf24ac9634a12a4a518edecae1d42fa331d9 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 2 Aug 2006 08:04:19 +0000 Subject: Fixed a few minor bugs and added the new viewer system, it allows you to add new front ends that will display what build is doing in any way you want. cool! So far we have plain and percent, verbose and make are coming, make should be really easy, just print out the commands and nothing else. --- build.conf | 2 ++ src/action.h | 5 +++++ src/builder.cpp | 13 +++++++++-- src/builder.h | 9 +++++++- src/filetarget.cpp | 31 ++++++++++++++++++-------- src/filetarget.h | 2 +- src/main.cpp | 5 ++++- src/performcmd.cpp | 3 ++- src/viewer.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/viewer.h | 33 +++++++++++++++++++++++++++ src/viewerpercent.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++ src/viewerpercent.h | 30 +++++++++++++++++++++++++ src/viewerplain.cpp | 33 +++++++++++++++++++++++++++ src/viewerplain.h | 26 +++++++++++++++++++++ 14 files changed, 297 insertions(+), 15 deletions(-) create mode 100644 src/viewer.cpp create mode 100644 src/viewer.h create mode 100644 src/viewerpercent.cpp create mode 100644 src/viewerpercent.h create mode 100644 src/viewerplain.cpp create mode 100644 src/viewerplain.h diff --git a/build.conf b/build.conf index b24d7d0..f747ddf 100644 --- a/build.conf +++ b/build.conf @@ -5,6 +5,8 @@ default action: check build create file build from files in src using rule exe +set CXXFLAGS += "-ggdb" + set CXXFLAGS += "-Ilibbu++/src" set LDFLAGS += "-Llibbu++ -lbu++" diff --git a/src/action.h b/src/action.h index 7518ed2..ea92efa 100644 --- a/src/action.h +++ b/src/action.h @@ -25,6 +25,11 @@ public: return bDefault; } + int getNumCommands() + { + return lCommand.size(); + } + void debug(); void execute( class Builder &bld ); diff --git a/src/builder.cpp b/src/builder.cpp index c4f2d12..65ae0c2 100644 --- a/src/builder.cpp +++ b/src/builder.cpp @@ -6,14 +6,16 @@ #include "target.h" #include "build.tab.h" #include "rule.h" +#include "viewer.h" subExceptionDef( BuildException ) -Builder::Builder() : +Builder::Builder( Viewer &rView ) : pDefaultAction( NULL ), pLastAddedAction( NULL ), sTmp(""), - sContext("") + sContext(""), + rView( rView ) { } @@ -44,7 +46,11 @@ void Builder::build( const char *sAct ) pAct = mAction[sAct]; } + rView.beginAction( sAct, pAct->getNumCommands() ); + pAct->execute( *this ); + + rView.endAction(); } void Builder::execute( Action *pAct ) @@ -318,6 +324,8 @@ void Builder::genRequiresFor( const char *sName ) { varmap *revars = regexVars( re ); std::string s = varRepl( (*i).second.c_str(), "", revars ); + rView.beginExtraRequiresCheck( s.c_str() ); + rView.executeCmd( s.c_str() ); FILE *fcmd = popen( s.c_str(), "r" ); std::string rhs; bool bHeader = true; @@ -366,6 +374,7 @@ void Builder::genRequiresFor( const char *sName ) } pclose( fcmd ); delete revars; + rView.endExtraRequiresCheck(); } } } diff --git a/src/builder.h b/src/builder.h index 296b9d7..82a82c4 100644 --- a/src/builder.h +++ b/src/builder.h @@ -16,6 +16,7 @@ class Action; class Command; class Rule; class Target; +class Viewer; #define YY_DECL int yylex( YYSTYPE *yylval_param, YYLTYPE *yylloc_param, Builder &bld ) YY_DECL; @@ -31,7 +32,7 @@ class Builder }; public: - Builder(); + Builder( Viewer &rView ); virtual ~Builder(); void load( const char *sFN ); @@ -43,6 +44,10 @@ public: std::string file; + Viewer &view() + { + return rView; + } void add( Action *pAct ); void add( Command *pCmd ); void add( Rule *pRule ); @@ -145,6 +150,8 @@ private: StaticString sTmp; bool bReqRegexp; + + Viewer &rView; }; void cleanList( std::list &lst ); diff --git a/src/filetarget.cpp b/src/filetarget.cpp index ca9a39f..e89cd5f 100644 --- a/src/filetarget.cpp +++ b/src/filetarget.cpp @@ -5,6 +5,7 @@ #include "rule.h" #include "filetarget.h" #include "builder.h" // for BuildException +#include "viewer.h" FileTarget::FileTarget( const char *sName ) : Target( sName ) @@ -67,25 +68,27 @@ void FileTarget::addInputDir( const char *sDir ) closedir( dir ); } -int nNew, nCache; +//int nNew, nCache; void FileTarget::check( Builder &bld ) { - printf("--- %s ---\n", getName() ); - nNew = nCache = 0; + //nNew = nCache = 0; Rule *pRule = bld.getRule( sRule ); std::list perf; std::list tmp = pRule->execute( bld, lInput, perf, getName() ); lOutput.insert( lOutput.end(), tmp.begin(), tmp.end() ); + + bld.view().beginTarget( getName(), "file", "check", lOutput.size() ); bld.processRequires( lOutput ); for( std::list::iterator i = perf.begin(); i != perf.end(); i++ ) { + bld.view().beginPerform( *i ); bool bExtraReqs = false; - time_t target = getTime( std::string((*i)->getTarget()) ); + time_t target = getTime( bld, std::string((*i)->getTarget()) ); std::list *lReqs = bld.getRequires( (*i)->getTarget() ); if( lReqs == NULL ) { @@ -95,10 +98,12 @@ void FileTarget::check( Builder &bld ) for( std::list::iterator j = lReqs->begin(); j != lReqs->end(); j++ ) { - if( getTime( *j ) > target ) + if( getTime( bld, *j ) > target ) { + bld.view().beginExecute(); (*i)->execute( bld ); updateTime( (*i)->getTarget() ); + bld.view().endExecute(); break; } if( bExtraReqs == false ) @@ -112,9 +117,12 @@ void FileTarget::check( Builder &bld ) } } } + bld.view().endPerform(); } - printf("Cache hits %d, %d new (%f%%)\n", nCache, nNew, nCache/ (double)(nNew+nCache)*100.0 ); + //printf("Cache hits %d, %d new (%f%%)\n", nCache, nNew, nCache/ (double)(nNew+nCache)*100.0 ); + + bld.view().endTarget(); } void FileTarget::clean( Builder &bld ) @@ -132,21 +140,26 @@ void FileTarget::clean( Builder &bld ) } } -time_t FileTarget::getTime( std::string str ) +time_t FileTarget::getTime( Builder &bld, std::string str ) { std::map::iterator i = mTimes.find( str ); if( i != mTimes.end() ) { - nCache++; + //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++; + //nNew++; + + bld.view().endRequiresCheck(); return st.st_mtime; } diff --git a/src/filetarget.h b/src/filetarget.h index 856e854..c78c2fd 100644 --- a/src/filetarget.h +++ b/src/filetarget.h @@ -21,7 +21,7 @@ public: virtual void check( class Builder &bld ); virtual void clean( class Builder &bld ); - time_t getTime( std::string str ); + time_t getTime( class Builder &bld, std::string str ); void updateTime( std::string str ); private: diff --git a/src/main.cpp b/src/main.cpp index ebfb745..132fb18 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,8 +1,11 @@ #include "builder.h" +#include "viewerplain.h" +#include "viewerpercent.h" int main( int argc, char *argv[] ) { - Builder bld; + ViewerPercent p; + Builder bld( p ); bld.load("build.conf"); diff --git a/src/performcmd.cpp b/src/performcmd.cpp index d9b7977..8eafc66 100644 --- a/src/performcmd.cpp +++ b/src/performcmd.cpp @@ -1,5 +1,6 @@ #include "performcmd.h" #include "builder.h" +#include "viewer.h" PerformCmd::PerformCmd( const char *sCmd, const char *sTarget ) : Perform( sTarget ), @@ -13,7 +14,7 @@ PerformCmd::~PerformCmd() void PerformCmd::execute( class Builder &bld ) { - printf("%s\n", sCommand.getString() ); + bld.view().executeCmd( sCommand ); int ret; if( (ret = system( sCommand.getString() )) != 0 ) { diff --git a/src/viewer.cpp b/src/viewer.cpp new file mode 100644 index 0000000..ed6abfb --- /dev/null +++ b/src/viewer.cpp @@ -0,0 +1,62 @@ +#include "viewer.h" + +Viewer::Viewer() +{ +} + +Viewer::~Viewer() +{ +} + +void Viewer::beginAction( const char *sName, int nCommands ) +{ +} + +void Viewer::endAction() +{ +} + +void Viewer::beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms ) +{ +} + +void Viewer::endTarget() +{ +} + +void Viewer::beginPerform( Perform *pPerf ) +{ +} + +void Viewer::beginRequiresCheck( bool bCached, const char *sName ) +{ +} + +void Viewer::endRequiresCheck() +{ +} + +void Viewer::beginExtraRequiresCheck( const char *sCommand ) +{ +} + +void Viewer::endExtraRequiresCheck() +{ +} + +void Viewer::beginExecute() +{ +} + +void Viewer::executeCmd( const char *sCmd ) +{ +} + +void Viewer::endExecute() +{ +} + +void Viewer::endPerform() +{ +} + diff --git a/src/viewer.h b/src/viewer.h new file mode 100644 index 0000000..8f2a595 --- /dev/null +++ b/src/viewer.h @@ -0,0 +1,33 @@ +#ifndef VIEWER_H +#define VIEWER_H + +#include + +class Perform; + +class Viewer +{ +public: + Viewer(); + virtual ~Viewer(); + + virtual void beginAction( const char *sName, int nCommands ); + virtual void endAction(); + virtual void beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms ); + virtual void endTarget(); + + virtual void beginPerform( Perform *pPerf ); + virtual void beginRequiresCheck( bool bCached, const char *sName ); + virtual void endRequiresCheck(); + virtual void beginExtraRequiresCheck( const char *sCommand ); + virtual void endExtraRequiresCheck(); + virtual void beginExecute(); + virtual void executeCmd( const char *sCmd ); + virtual void endExecute(); + virtual void endPerform(); + +private: + +}; + +#endif diff --git a/src/viewerpercent.cpp b/src/viewerpercent.cpp new file mode 100644 index 0000000..0b0344b --- /dev/null +++ b/src/viewerpercent.cpp @@ -0,0 +1,58 @@ +#include "viewerpercent.h" +#include "perform.h" + +ViewerPercent::ViewerPercent() : + nWidth( 25 ) +{ +} + +ViewerPercent::~ViewerPercent() +{ +} + +void ViewerPercent::beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms ) +{ + printf("--- %s ---\n", sName ); + nMax = nPerforms; + nCount = 0; + nLastLen = 0; +} + +void ViewerPercent::endTarget() +{ + printf("\n\n"); +} + +void ViewerPercent::beginPerform( Perform *pPerf ) +{ + sTarget = pPerf->getTarget(); +} + +void ViewerPercent::beginExecute() +{ +} + +void ViewerPercent::endPerform() +{ + nCount++; + + int nPer = (nCount*nWidth)/nMax; + fputc( '[', stdout ); + for( int j = 0; j < nPer; j++ ) + fputc('=', stdout ); + for( int j = nPer; j < nWidth; j++ ) + fputc(' ', stdout ); + //fputc(']', stdout ); + + printf("] %s", sTarget.getString() ); + + int diff = nLastLen-sTarget; + for( int j = 0; j < diff; j++ ) + fputc(' ', stdout ); + + nLastLen = sTarget; + + fputc('\r', stdout ); + fflush( stdout ); +} + diff --git a/src/viewerpercent.h b/src/viewerpercent.h new file mode 100644 index 0000000..d575940 --- /dev/null +++ b/src/viewerpercent.h @@ -0,0 +1,30 @@ +#ifndef VIEWER_PERCENT_H +#define VIEWER_PERCENT_H + +#include + +#include "viewer.h" +#include "staticstring.h" + +class ViewerPercent : public Viewer +{ +public: + ViewerPercent(); + virtual ~ViewerPercent(); + + virtual void beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms ); + virtual void endTarget(); + + virtual void beginPerform( Perform *pPerf ); + virtual void beginExecute(); + virtual void endPerform(); + +private: + class StaticString sTarget; + int nLastLen; + int nWidth; + int nMax; + int nCount; +}; + +#endif diff --git a/src/viewerplain.cpp b/src/viewerplain.cpp new file mode 100644 index 0000000..edc5ba8 --- /dev/null +++ b/src/viewerplain.cpp @@ -0,0 +1,33 @@ +#include +#include "viewerplain.h" +#include "perform.h" + +ViewerPlain::ViewerPlain() +{ +} + +ViewerPlain::~ViewerPlain() +{ +} + +void ViewerPlain::beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms ) +{ + printf("--- %s ---\n", sName ); +} + +void ViewerPlain::endTarget() +{ + printf("\n"); +} + +void ViewerPlain::beginPerform( Perform *pPerf ) +{ + sTarget = pPerf->getTarget(); + printf(" check: %s\n", sTarget.getString() ); +} + +void ViewerPlain::beginExecute() +{ + printf(" build: %s\n", sTarget.getString() ); +} + diff --git a/src/viewerplain.h b/src/viewerplain.h new file mode 100644 index 0000000..7b4b189 --- /dev/null +++ b/src/viewerplain.h @@ -0,0 +1,26 @@ +#ifndef VIEWER_PLAIN_H +#define VIEWER_PLAIN_H + +#include + +#include "viewer.h" +#include "staticstring.h" + +class ViewerPlain : public Viewer +{ +public: + ViewerPlain(); + virtual ~ViewerPlain(); + + virtual void beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms ); + virtual void endTarget(); + + virtual void beginPerform( Perform *pPerf ); + virtual void beginExecute(); + +private: + class StaticString sTarget; + +}; + +#endif -- cgit v1.2.3