From 8dd79b7b5a0309f9bc1185019a4af16b3b52aece Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 5 Aug 2006 00:04:34 +0000 Subject: Build now uses a cachefile for all of it's requires that are generated from other means (running other programs). It's really fast, and seems to work pretty well. --- src/builder.cpp | 113 +++++++++++++++++++++++++------------------------------- 1 file changed, 51 insertions(+), 62 deletions(-) (limited to 'src/builder.cpp') diff --git a/src/builder.cpp b/src/builder.cpp index d3cb2c0..a21bc99 100644 --- a/src/builder.cpp +++ b/src/builder.cpp @@ -7,6 +7,8 @@ #include "build.tab.h" #include "rule.h" #include "viewer.h" +#include "cache.h" +#include "serializerbinary.h" subExceptionDef( BuildException ) @@ -21,6 +23,18 @@ Builder::Builder( Viewer &rView ) : Builder::~Builder() { + if( sCacheFile.getLength() > 0 ) + { + try + { + SerializerBinary ar( sCacheFile, Serializer::save ); + + ar << cRequires; + } + catch( ExceptionBase &e ) + { + } + } } void yyparse( Builder &bld ); @@ -53,6 +67,21 @@ void Builder::build( const char *sAct ) rView.endAction(); } +void Builder::setCache( const std::string &sFile ) +{ + sCacheFile = sFile.c_str(); + + try + { + SerializerBinary ar( sCacheFile, Serializer::load ); + + ar >> cRequires; + } + catch( ExceptionBase &e ) + { + } +} + void Builder::execute( Action *pAct ) { pAct->execute( *this ); @@ -247,75 +276,31 @@ void Builder::processRequires( std::list &lInput ) } } - // These are only done on request now, they were too expensive - /* - for( regreqlist::iterator i = lRequiresRegexpCommand.begin(); - i != lRequiresRegexpCommand.end(); i++ ) +} + +void Builder::genRequiresFor( const char *sName, time_t tNewTime ) +{ + Cache::Entry *ent = cRequires.get( sName ); + if( ent && tNewTime > 0 ) { - RegExp *re = (*i).first; - for( std::list::iterator j = lInput.begin(); - j != lInput.end(); j++ ) + if( ent->tCreated >= tNewTime ) { - if( re->execute( (*j).c_str() ) ) + for( std::list::iterator i = ent->lData.begin(); + i != ent->lData.end(); i++ ) { - varmap *revars = regexVars( re ); - std::string s = varRepl( (*i).second.c_str(), "", revars ); - FILE *fcmd = popen( s.c_str(), "r" ); - std::string rhs; - bool bHeader = true; - for(;;) - { - if( feof( fcmd ) ) - break; - int cc = fgetc( fcmd ); - if( cc == EOF ) - break; - unsigned char c = cc; - if( bHeader ) - { - if( c == ':' ) - bHeader = false; - } - else - { - if( c == ' ' || c == '\t' ) - { - if( rhs != "" ) - { - requiresNormal( - (*j).c_str(), - rhs.c_str() - ); - rhs = ""; - } - } - else - { - if( c == '\\' ) - c = fgetc( fcmd ); - if( c != '\n' ) - rhs += c; - } - } - } - if( rhs != "" ) - { - requiresNormal( - (*j).c_str(), - rhs.c_str() - ); - rhs = ""; - } - pclose( fcmd ); - delete revars; + requiresNormal( + sName, + (*i).c_str() + ); } + + return; } } - */ -} -void Builder::genRequiresFor( const char *sName ) -{ + ent = new Cache::Entry; + ent->tCreated = tNewTime; + for( regreqlist::iterator i = lRequiresRegexpCommand.begin(); i != lRequiresRegexpCommand.end(); i++ ) { @@ -352,6 +337,7 @@ void Builder::genRequiresFor( const char *sName ) sName, rhs.c_str() ); + ent->lData.push_back( rhs ); rhs = ""; } } @@ -370,6 +356,7 @@ void Builder::genRequiresFor( const char *sName ) sName, rhs.c_str() ); + ent->lData.push_back( rhs ); rhs = ""; } pclose( fcmd ); @@ -377,6 +364,8 @@ void Builder::genRequiresFor( const char *sName ) rView.endExtraRequiresCheck(); } } + + cRequires.put( sName, ent ); } std::map *Builder::regexVars( RegExp *re ) -- cgit v1.2.3