aboutsummaryrefslogtreecommitdiff
path: root/src/builder.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2006-08-05 00:04:34 +0000
committerMike Buland <eichlan@xagasoft.com>2006-08-05 00:04:34 +0000
commit8dd79b7b5a0309f9bc1185019a4af16b3b52aece (patch)
treea703325cb9bc074179aeaf38f4851a4c38ebfd87 /src/builder.cpp
parent13bda5d4f77ca469bbbe0d9b1f268682a9f0ec71 (diff)
downloadbuild-8dd79b7b5a0309f9bc1185019a4af16b3b52aece.tar.gz
build-8dd79b7b5a0309f9bc1185019a4af16b3b52aece.tar.bz2
build-8dd79b7b5a0309f9bc1185019a4af16b3b52aece.tar.xz
build-8dd79b7b5a0309f9bc1185019a4af16b3b52aece.zip
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.
Diffstat (limited to 'src/builder.cpp')
-rw-r--r--src/builder.cpp113
1 files changed, 51 insertions, 62 deletions
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 @@
7#include "build.tab.h" 7#include "build.tab.h"
8#include "rule.h" 8#include "rule.h"
9#include "viewer.h" 9#include "viewer.h"
10#include "cache.h"
11#include "serializerbinary.h"
10 12
11subExceptionDef( BuildException ) 13subExceptionDef( BuildException )
12 14
@@ -21,6 +23,18 @@ Builder::Builder( Viewer &rView ) :
21 23
22Builder::~Builder() 24Builder::~Builder()
23{ 25{
26 if( sCacheFile.getLength() > 0 )
27 {
28 try
29 {
30 SerializerBinary ar( sCacheFile, Serializer::save );
31
32 ar << cRequires;
33 }
34 catch( ExceptionBase &e )
35 {
36 }
37 }
24} 38}
25 39
26void yyparse( Builder &bld ); 40void yyparse( Builder &bld );
@@ -53,6 +67,21 @@ void Builder::build( const char *sAct )
53 rView.endAction(); 67 rView.endAction();
54} 68}
55 69
70void Builder::setCache( const std::string &sFile )
71{
72 sCacheFile = sFile.c_str();
73
74 try
75 {
76 SerializerBinary ar( sCacheFile, Serializer::load );
77
78 ar >> cRequires;
79 }
80 catch( ExceptionBase &e )
81 {
82 }
83}
84
56void Builder::execute( Action *pAct ) 85void Builder::execute( Action *pAct )
57{ 86{
58 pAct->execute( *this ); 87 pAct->execute( *this );
@@ -247,75 +276,31 @@ void Builder::processRequires( std::list<std::string> &lInput )
247 } 276 }
248 } 277 }
249 278
250 // These are only done on request now, they were too expensive 279}
251 /* 280
252 for( regreqlist::iterator i = lRequiresRegexpCommand.begin(); 281void Builder::genRequiresFor( const char *sName, time_t tNewTime )
253 i != lRequiresRegexpCommand.end(); i++ ) 282{
283 Cache::Entry *ent = cRequires.get( sName );
284 if( ent && tNewTime > 0 )
254 { 285 {
255 RegExp *re = (*i).first; 286 if( ent->tCreated >= tNewTime )
256 for( std::list<std::string>::iterator j = lInput.begin();
257 j != lInput.end(); j++ )
258 { 287 {
259 if( re->execute( (*j).c_str() ) ) 288 for( std::list<std::string>::iterator i = ent->lData.begin();
289 i != ent->lData.end(); i++ )
260 { 290 {
261 varmap *revars = regexVars( re ); 291 requiresNormal(
262 std::string s = varRepl( (*i).second.c_str(), "", revars ); 292 sName,
263 FILE *fcmd = popen( s.c_str(), "r" ); 293 (*i).c_str()
264 std::string rhs; 294 );
265 bool bHeader = true;
266 for(;;)
267 {
268 if( feof( fcmd ) )
269 break;
270 int cc = fgetc( fcmd );
271 if( cc == EOF )
272 break;
273 unsigned char c = cc;
274 if( bHeader )
275 {
276 if( c == ':' )
277 bHeader = false;
278 }
279 else
280 {
281 if( c == ' ' || c == '\t' )
282 {
283 if( rhs != "" )
284 {
285 requiresNormal(
286 (*j).c_str(),
287 rhs.c_str()
288 );
289 rhs = "";
290 }
291 }
292 else
293 {
294 if( c == '\\' )
295 c = fgetc( fcmd );
296 if( c != '\n' )
297 rhs += c;
298 }
299 }
300 }
301 if( rhs != "" )
302 {
303 requiresNormal(
304 (*j).c_str(),
305 rhs.c_str()
306 );
307 rhs = "";
308 }
309 pclose( fcmd );
310 delete revars;
311 } 295 }
296
297 return;
312 } 298 }
313 } 299 }
314 */
315}
316 300
317void Builder::genRequiresFor( const char *sName ) 301 ent = new Cache::Entry;
318{ 302 ent->tCreated = tNewTime;
303
319 for( regreqlist::iterator i = lRequiresRegexpCommand.begin(); 304 for( regreqlist::iterator i = lRequiresRegexpCommand.begin();
320 i != lRequiresRegexpCommand.end(); i++ ) 305 i != lRequiresRegexpCommand.end(); i++ )
321 { 306 {
@@ -352,6 +337,7 @@ void Builder::genRequiresFor( const char *sName )
352 sName, 337 sName,
353 rhs.c_str() 338 rhs.c_str()
354 ); 339 );
340 ent->lData.push_back( rhs );
355 rhs = ""; 341 rhs = "";
356 } 342 }
357 } 343 }
@@ -370,6 +356,7 @@ void Builder::genRequiresFor( const char *sName )
370 sName, 356 sName,
371 rhs.c_str() 357 rhs.c_str()
372 ); 358 );
359 ent->lData.push_back( rhs );
373 rhs = ""; 360 rhs = "";
374 } 361 }
375 pclose( fcmd ); 362 pclose( fcmd );
@@ -377,6 +364,8 @@ void Builder::genRequiresFor( const char *sName )
377 rView.endExtraRequiresCheck(); 364 rView.endExtraRequiresCheck();
378 } 365 }
379 } 366 }
367
368 cRequires.put( sName, ent );
380} 369}
381 370
382std::map<std::string, std::string> *Builder::regexVars( RegExp *re ) 371std::map<std::string, std::string> *Builder::regexVars( RegExp *re )