aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2006-09-12 17:30:23 +0000
committerMike Buland <eichlan@xagasoft.com>2006-09-12 17:30:23 +0000
commite2c430b237da5c0229fd8e0832eedc3b85045ec0 (patch)
tree2f14481a9622c1d9ee913456f12ffb6cdfd53eef /src
parentdaa9ab77fa7ff88a77e028270ec32fa4f3e6d3bb (diff)
downloadbuild-e2c430b237da5c0229fd8e0832eedc3b85045ec0.tar.gz
build-e2c430b237da5c0229fd8e0832eedc3b85045ec0.tar.bz2
build-e2c430b237da5c0229fd8e0832eedc3b85045ec0.tar.xz
build-e2c430b237da5c0229fd8e0832eedc3b85045ec0.zip
Added cache functionality, which is really nice, things go much faster now.
Diffstat (limited to '')
-rw-r--r--src/build.cpp64
-rw-r--r--src/build.h8
-rw-r--r--src/cache.cpp149
-rw-r--r--src/cache.h33
-rw-r--r--src/main.cpp25
-rw-r--r--src/performcommand.cpp8
-rw-r--r--src/targetfile.cpp32
7 files changed, 288 insertions, 31 deletions
diff --git a/src/build.cpp b/src/build.cpp
index 5c0b721..13a2aee 100644
--- a/src/build.cpp
+++ b/src/build.cpp
@@ -1,18 +1,47 @@
1#include "build.h" 1#include "build.h"
2#include "function.h" 2#include "function.h"
3#include "viewerfactory.h" 3#include "viewerfactory.h"
4#include "serializerbinary.h"
4 5
5subExceptionDef( BuildException ); 6subExceptionDef( BuildException );
6 7
7Build::Build() : 8Build::Build() :
8 pStrProc( NULL ), 9 pStrProc( NULL ),
9 pView( NULL ) 10 pView( NULL ),
11 bCacheUpdated( false )
10{ 12{
11 pView = ViewerFactory::getInstance().instantiate("plain"); 13 pView = ViewerFactory::getInstance().instantiate("plain");
12} 14}
13 15
14Build::~Build() 16Build::~Build()
15{ 17{
18 if( sCacheName.size() > 0 && bCacheUpdated )
19 {
20 try
21 {
22 SerializerBinary ar( sCacheName.c_str(), Serializer::save );
23
24 ar << cRequires;
25 }
26 catch( ExceptionBase &e )
27 {
28 }
29 }
30}
31
32void Build::setCache( const std::string &sFileName )
33{
34 sCacheName = sFileName;
35
36 try
37 {
38 SerializerBinary ar( sCacheName.c_str(), Serializer::load );
39
40 ar >> cRequires;
41 }
42 catch( ExceptionBase &e )
43 {
44 }
16} 45}
17 46
18void Build::setStringProc( StringProc *pStrProc ) 47void Build::setStringProc( StringProc *pStrProc )
@@ -271,3 +300,36 @@ StringList &Build::getRequires( std::string sName )
271 return mRequires[sName]; 300 return mRequires[sName];
272} 301}
273 302
303bool Build::getCached( const std::string &sID, int nTime, StringList &lOut )
304{
305 Cache::Entry *pEnt = cRequires.get( sID );
306 if( pEnt == NULL )
307 return false;
308 if( pEnt->tCreated < nTime )
309 return false;
310
311 lOut.insert( lOut.end(), pEnt->lData.begin(), pEnt->lData.end() );
312
313 return true;
314}
315
316void Build::updateCache( const std::string &sID, FunctionList &lFunc, StringList &lOut )
317{
318 Cache::Entry *pEnt = new Cache::Entry;
319 getView()->beginRequiresCheck( false, sID );
320 for( FunctionList::iterator f = lFunc.begin(); f != lFunc.end(); f++ )
321 {
322 StringList lTmpIn;
323 lTmpIn.push_back( sID );
324 (*f)->execute( this, lTmpIn, pEnt->lData );
325 }
326 getView()->endRequiresCheck();
327
328 lOut.insert( lOut.end(), pEnt->lData.begin(), pEnt->lData.end() );
329 cRequires.put( sID, pEnt );
330
331 pEnt->tCreated = time( NULL );
332
333 bCacheUpdated = true;
334}
335
diff --git a/src/build.h b/src/build.h
index a35b8e2..1477938 100644
--- a/src/build.h
+++ b/src/build.h
@@ -11,6 +11,7 @@
11#include "target.h" 11#include "target.h"
12#include "action.h" 12#include "action.h"
13#include "stringproc.h" 13#include "stringproc.h"
14#include "cache.h"
14 15
15subExceptionDecl( BuildException ); 16subExceptionDecl( BuildException );
16typedef std::map<std::string, std::string> VarMap; 17typedef std::map<std::string, std::string> VarMap;
@@ -66,6 +67,10 @@ public:
66 return mTarget; 67 return mTarget;
67 } 68 }
68 69
70 void setCache( const std::string &sFileName );
71 bool getCached( const std::string &sID, int nTime, StringList &lOut );
72 void updateCache( const std::string &sID, FunctionList &lFunc, StringList &lOut );
73
69private: 74private:
70 TargetMap mTarget; 75 TargetMap mTarget;
71 ReqMap mRequires; 76 ReqMap mRequires;
@@ -75,6 +80,9 @@ private:
75 ActionMap mAction; 80 ActionMap mAction;
76 StringProc *pStrProc; 81 StringProc *pStrProc;
77 Viewer *pView; 82 Viewer *pView;
83 Cache cRequires;
84 bool bCacheUpdated;
85 std::string sCacheName;
78 86
79 //std::map<std::string, Rule *> mRule; 87 //std::map<std::string, Rule *> mRule;
80 //Action *pActDefault; 88 //Action *pActDefault;
diff --git a/src/cache.cpp b/src/cache.cpp
new file mode 100644
index 0000000..10971b1
--- /dev/null
+++ b/src/cache.cpp
@@ -0,0 +1,149 @@
1#include "cache.h"
2#include "serializer.h"
3#include "staticstring.h"
4
5Cache::Cache()
6{
7}
8
9Cache::~Cache()
10{
11 for( std::map<std::string, Entry *>::iterator i = mCache.begin();
12 i != mCache.end(); i++ )
13 {
14 delete (*i).second;
15 }
16}
17
18void Cache::serialize( class Serializer &ar )
19{
20 if( ar.isLoading() )
21 {
22 int sCache, sData, sIndex;
23
24 ar >> sIndex;
25 StaticString *Index = new StaticString[sIndex];
26 for( int i = 0; i < sIndex; i++ )
27 {
28 ar >> Index[i];
29 }
30
31 ar >> sCache;
32 int nTmp;
33 for( int i = 0; i < sCache; i++ )
34 {
35 Entry *e = new Entry;
36 ar >> e->tCreated;
37 ar >> sData;
38 std::list<std::string> &lData = e->lData;
39 for( int j = 0; j < sData; j++ )
40 {
41 ar >> nTmp;
42 lData.push_back( Index[nTmp].getString() );
43 }
44 ar >> nTmp;
45 mCache[Index[nTmp].getString()] = e;
46 }
47 /*
48 int sCache, sData;
49 ar >> sCache;
50 std::string sTmp;
51
52 for( int i = 0; i < sCache; i++ )
53 {
54 Entry *e = new Entry;
55 ar >> e->tCreated;
56 ar >> sData;
57 std::list<std::string> &lData = e->lData;
58 for( int j = 0; j < sData; j++ )
59 {
60 ar >> sTmp;
61 lData.push_back( sTmp );
62 }
63 ar >> sTmp;
64 mCache[sTmp] = e;
65 }
66 */
67 }
68 else
69 {
70 std::map<std::string, int> mIndex;
71 for( std::map<std::string, Entry *>::iterator i = mCache.begin();
72 i != mCache.end(); i++ )
73 {
74 mIndex[(*i).first] = 0;
75 std::list<std::string> &lData = (*i).second->lData;
76 for( std::list<std::string>::iterator j = lData.begin();
77 j != lData.end(); j++ )
78 {
79 mIndex[(*j)] = 0;
80 }
81 }
82
83 ar << mIndex.size();
84 int cnt = 0;
85 for( std::map<std::string, int>::iterator i = mIndex.begin();
86 i != mIndex.end(); i++ )
87 {
88 (*i).second = cnt;
89 cnt++;
90 std::string s = ((*i).first);
91 ar << s;
92 }
93
94 ar << mCache.size();
95 for( std::map<std::string, Entry *>::iterator i = mCache.begin();
96 i != mCache.end(); i++ )
97 {
98 ar << (*i).second->tCreated;
99 std::list<std::string> &lData = (*i).second->lData;
100 ar << lData.size();
101 for( std::list<std::string>::iterator j = lData.begin();
102 j != lData.end(); j++ )
103 {
104 ar << mIndex[(*j)];
105 }
106
107 ar << mIndex[(*i).first];
108 }
109
110
111 /*
112 ar << mCache.size();
113 for( std::map<std::string, Entry *>::iterator i = mCache.begin();
114 i != mCache.end(); i++ )
115 {
116 ar << (*i).second->tCreated;
117 std::list<std::string> &lData = (*i).second->lData;
118 ar << lData.size();
119 for( std::list<std::string>::iterator j = lData.begin();
120 j != lData.end(); j++ )
121 {
122 ar << (*j);
123 }
124
125 std::string str = (*i).first;
126 ar << str;
127 }
128 */
129 }
130}
131
132Cache::Entry *Cache::get( const std::string &id )
133{
134 std::map<std::string, Entry *>::iterator i = mCache.find( id );
135 if( i != mCache.end() )
136 return (*i).second;
137
138 return NULL;
139}
140
141void Cache::put( const std::string &id, Entry *data )
142{
143 std::map<std::string, Entry *>::iterator i = mCache.find( id );
144 if( i != mCache.end() )
145 delete (*i).second;
146
147 mCache[id] = data;
148}
149
diff --git a/src/cache.h b/src/cache.h
new file mode 100644
index 0000000..944aa24
--- /dev/null
+++ b/src/cache.h
@@ -0,0 +1,33 @@
1#ifndef CACHE_H
2#define CACHE_H
3
4#include <stdint.h>
5#include <time.h>
6#include "serializable.h"
7#include <list>
8#include <map>
9#include <string>
10
11class Cache : public Serializable
12{
13public:
14 Cache();
15 virtual ~Cache();
16
17 virtual void serialize( class Serializer &ar );
18
19 class Entry
20 {
21 public:
22 int tCreated;
23 std::list<std::string> lData;
24 };
25
26 Entry *get( const std::string &id );
27 void put( const std::string &id, Entry *data );
28
29private:
30 std::map<std::string, Entry *> mCache;
31};
32
33#endif
diff --git a/src/main.cpp b/src/main.cpp
index 9106a74..712213b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -72,19 +72,20 @@ int main( int argc, char *argv[] )
72 Param prm; 72 Param prm;
73 prm.process( argc, argv ); 73 prm.process( argc, argv );
74 74
75 BuildParser bld;//*prm.pViewer ); 75 BuildParser bld;
76 Build *pBuild;
76 77
77 //bld.setCache( prm.sCache ); 78 try
78 //try 79 {
79 //{ 80 pBuild = bld.load( prm.sFile.c_str() );
80 Build *pBuild = bld.load( prm.sFile.c_str() ); 81 pBuild->setCache( prm.sCache );
81 //} 82 }
82 //catch( BuildException &e ) 83 catch( BuildException &e )
83 //{ 84 {
84 // fputs( e.what(), stderr ); 85 fputs( e.what(), stderr );
85 // fputs( "\n", stderr ); 86 fputs( "\n", stderr );
86 // return 1; 87 return 1;
87 //} 88 }
88 89
89 //if( prm.bDebug ) 90 //if( prm.bDebug )
90 //{ 91 //{
diff --git a/src/performcommand.cpp b/src/performcommand.cpp
index f6da4ac..5a9e746 100644
--- a/src/performcommand.cpp
+++ b/src/performcommand.cpp
@@ -1,5 +1,6 @@
1#include "performcommand.h" 1#include "performcommand.h"
2#include "plugger.h" 2#include "plugger.h"
3#include "build.h"
3 4
4PluginInterface2(command, PerformCommand, Perform, "Mike Buland", 0, 1 ); 5PluginInterface2(command, PerformCommand, Perform, "Mike Buland", 0, 1 );
5 6
@@ -20,6 +21,11 @@ Perform *PerformCommand::duplicate( Build &bld, const std::string &cont, VarMap
20 21
21void PerformCommand::execute( Build &bld ) 22void PerformCommand::execute( Build &bld )
22{ 23{
23 system( lParam.front().c_str() ); 24 int n = system( lParam.front().c_str() );
25 if( n != 0 )
26 throw BuildException(
27 "Command exited with error code %d.",
28 WEXITSTATUS(n)
29 );
24} 30}
25 31
diff --git a/src/targetfile.cpp b/src/targetfile.cpp
index 0299f9d..dd0de9e 100644
--- a/src/targetfile.cpp
+++ b/src/targetfile.cpp
@@ -27,9 +27,8 @@ void TargetFile::check( Build &bld )
27 { 27 {
28 time_t tTarget = getTime( bld, (*i)->getTarget() ); 28 time_t tTarget = getTime( bld, (*i)->getTarget() );
29 StringList &reqs = bld.getRequires( (*i)->getTarget() ); 29 StringList &reqs = bld.getRequires( (*i)->getTarget() );
30 FunctionList::iterator f = (*i)->getReqFuncs().begin(); 30 bool bExtras = false;
31 bool bBuilt = false; 31 for( StringList::iterator j = reqs.begin(); j != reqs.end(); j++ )
32aastrt: for( StringList::iterator j = reqs.begin(); j != reqs.end(); j++ )
33 { 32 {
34 if( getTime( bld, *j ) > tTarget ) 33 if( getTime( bld, *j ) > tTarget )
35 { 34 {
@@ -37,22 +36,21 @@ aastrt: for( StringList::iterator j = reqs.begin(); j != reqs.end(); j++ )
37 (*i)->execute( bld ); 36 (*i)->execute( bld );
38 bld.getView()->endPerform(); 37 bld.getView()->endPerform();
39 updateTime( (*i)->getTarget() ); 38 updateTime( (*i)->getTarget() );
40 bBuilt = true;
41 break; 39 break;
42 } 40 }
43 } 41 if( bExtras == false )
44 if( bBuilt == true ) 42 {
45 continue; 43 StringList::iterator jj = j;
46 44 jj++;
47 if( f != (*i)->getReqFuncs().end() ) 45 if( jj == reqs.end() )
48 { 46 {
49 StringList lTmpIn; 47 if( !bld.getCached( (*i)->getTarget(), tTarget, reqs ) )
50 lTmpIn.push_back( (*i)->getTarget() ); 48 {
51 bld.getView()->beginRequiresCheck( false, (*i)->getTarget() ); 49 bld.updateCache( (*i)->getTarget(), (*i)->getReqFuncs(), reqs );
52 (*f)->execute( &bld, lTmpIn, reqs ); 50 }
53 bld.getView()->endRequiresCheck(); 51 bExtras = true;
54 f++; 52 }
55 goto aastrt; 53 }
56 } 54 }
57 } 55 }
58} 56}