aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/cache.cpp31
-rw-r--r--src/cache.h7
-rw-r--r--src/conditionfiletime.cpp5
-rw-r--r--src/main.cpp14
-rw-r--r--src/target.cpp17
-rw-r--r--src/target.h6
6 files changed, 74 insertions, 6 deletions
diff --git a/src/cache.cpp b/src/cache.cpp
index 1646d0a..de505b8 100644
--- a/src/cache.cpp
+++ b/src/cache.cpp
@@ -1,14 +1,18 @@
1#include "cache.h" 1#include "cache.h"
2#include <bu/file.h> 2#include <bu/file.h>
3#include <bu/archive.h> 3#include <bu/archive.h>
4#include <bu/sio.h>
5using namespace Bu;
4 6
5Cache::Cache() : 7Cache::Cache() :
8 bCacheChanged( false ),
6 bIsLoaded( false ) 9 bIsLoaded( false )
7{ 10{
8} 11}
9 12
10Cache::~Cache() 13Cache::~Cache()
11{ 14{
15 save();
12} 16}
13 17
14void Cache::bind( const Bu::FString &sCacheFile ) 18void Cache::bind( const Bu::FString &sCacheFile )
@@ -21,19 +25,40 @@ void Cache::load()
21{ 25{
22 if( bIsLoaded ) 26 if( bIsLoaded )
23 return; 27 return;
24 Bu::File fIn( sCacheFile, Bu::File::Read );
25 Bu::Archive ar( fIn, Bu::Archive::load );
26 28
27 ar >> hRequires >> hVariables; 29 try
30 {
31 Bu::File fIn( sCacheFile, Bu::File::Read );
32 Bu::Archive ar( fIn, Bu::Archive::load );
33
34 ar >> hRequires >> hVariables;
35 }
36 catch(...) { }
28 37
29 bIsLoaded = true; 38 bIsLoaded = true;
30} 39}
31 40
32void Cache::save() 41void Cache::save()
33{ 42{
43 if( !bIsLoaded )
44 return;
45 if( bCacheChanged == false )
46 return;
47
34 Bu::File fIn( sCacheFile, Bu::File::WriteNew ); 48 Bu::File fIn( sCacheFile, Bu::File::WriteNew );
35 Bu::Archive ar( fIn, Bu::Archive::save ); 49 Bu::Archive ar( fIn, Bu::Archive::save );
36 50
37 ar << hRequires << hVariables; 51 ar << hRequires << hVariables;
38} 52}
39 53
54StrList Cache::getRequires( const Bu::FString &sOutput )
55{
56 return hRequires.get( sOutput );
57}
58
59void Cache::setRequires( const Bu::FString &sOutput, StrList lReqs )
60{
61 hRequires.insert( sOutput, lReqs );
62 bCacheChanged = true;
63}
64
diff --git a/src/cache.h b/src/cache.h
index 31da981..8932091 100644
--- a/src/cache.h
+++ b/src/cache.h
@@ -7,6 +7,7 @@
7#include <bu/list.h> 7#include <bu/list.h>
8 8
9#include "variable.h" 9#include "variable.h"
10#include "types.h"
10 11
11class Cache : public Bu::Singleton<Cache> 12class Cache : public Bu::Singleton<Cache>
12{ 13{
@@ -21,12 +22,14 @@ public:
21 void load(); 22 void load();
22 void save(); 23 void save();
23 24
24 25 StrList getRequires( const Bu::FString &sOutput );
26 void setRequires( const Bu::FString &sOutput, StrList lReqs );
25 27
26private: 28private:
29 bool bCacheChanged;
27 Bu::FString sCacheFile; 30 Bu::FString sCacheFile;
28 bool bIsLoaded; 31 bool bIsLoaded;
29 typedef Bu::Hash<Bu::FString, Bu::List<Bu::FString> > ReqHash; 32 typedef Bu::Hash<Bu::FString, StrList> ReqHash;
30 ReqHash hRequires; 33 ReqHash hRequires;
31 typedef Bu::Hash<Bu::FString, Variable> VarHash; 34 typedef Bu::Hash<Bu::FString, Variable> VarHash;
32 VarHash hVariables; 35 VarHash hVariables;
diff --git a/src/conditionfiletime.cpp b/src/conditionfiletime.cpp
index 224caf1..148ffac 100644
--- a/src/conditionfiletime.cpp
+++ b/src/conditionfiletime.cpp
@@ -25,6 +25,7 @@ bool ConditionFileTime::shouldExec( class Runner &r, Target &rTarget )
25 //sio << "-- Target processed because '" << *j << "' doesn't exist." 25 //sio << "-- Target processed because '" << *j << "' doesn't exist."
26 // << sio.nl; 26 // << sio.nl;
27 // Output doesn't exist 27 // Output doesn't exist
28 rTarget.buildRequires( r );
28 return true; 29 return true;
29 } 30 }
30 } 31 }
@@ -48,10 +49,11 @@ bool ConditionFileTime::shouldExec( class Runner &r, Target &rTarget )
48 { 49 {
49 //sio << "-- Target processed because '" << *j 50 //sio << "-- Target processed because '" << *j
50 // << "' is newer than output." << sio.nl; 51 // << "' is newer than output." << sio.nl;
52 rTarget.buildRequires( r );
51 return true; 53 return true;
52 } 54 }
53 } 55 }
54 rTarget.buildRequires( r ); 56 rTarget.gatherRequires( r );
55 for( StrList::const_iterator j = rTarget.getRequiresList().begin(); 57 for( StrList::const_iterator j = rTarget.getRequiresList().begin();
56 j; j++ ) 58 j; j++ )
57 { 59 {
@@ -60,6 +62,7 @@ bool ConditionFileTime::shouldExec( class Runner &r, Target &rTarget )
60 { 62 {
61 //sio << "-- Target processed because '" << *j 63 //sio << "-- Target processed because '" << *j
62 // << "' is newer than output." << sio.nl; 64 // << "' is newer than output." << sio.nl;
65 rTarget.buildRequires( r );
63 return true; 66 return true;
64 } 67 }
65 } 68 }
diff --git a/src/main.cpp b/src/main.cpp
index 142927d..1bed895 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -6,6 +6,8 @@
6 6
7#include "viewplugger.h" 7#include "viewplugger.h"
8 8
9#include "cache.h"
10
9#include <bu/optparser.h> 11#include <bu/optparser.h>
10#include <bu/sio.h> 12#include <bu/sio.h>
11#include <sys/types.h> 13#include <sys/types.h>
@@ -24,11 +26,13 @@ public:
24 sView("default"), 26 sView("default"),
25 sAction("default"), 27 sAction("default"),
26 sConfig("default.bld"), 28 sConfig("default.bld"),
29 sCacheFile(".build_cache"),
27 bDot( false ), 30 bDot( false ),
28 bDebug( false ), 31 bDebug( false ),
29 bAutoInclude( true ), 32 bAutoInclude( true ),
30 bAstDump( false ), 33 bAstDump( false ),
31 bEnviron( true ), 34 bEnviron( true ),
35 bCache( true ),
32 iInfoLevel( 0 ) 36 iInfoLevel( 0 )
33 { 37 {
34 bool bClean = false; 38 bool bClean = false;
@@ -54,6 +58,8 @@ public:
54 "action is specified, this will modify it to run 'clean-action'."); 58 "action is specified, this will modify it to run 'clean-action'.");
55 addOption( slot(this, &Options::onChdir), 'C', "chdir", 59 addOption( slot(this, &Options::onChdir), 'C', "chdir",
56 "Change to directory before doing anything else."); 60 "Change to directory before doing anything else.");
61 addOption( sCacheFile, "cache", "Select a different cache file.");
62 addOption( bCache, "no-cache", "Disable using the cache.");
57 63
58 addHelpBanner("\nThe following options control debugging:"); 64 addHelpBanner("\nThe following options control debugging:");
59 addOption( bEnviron, "no-env", "Do not import environment variables."); 65 addOption( bEnviron, "no-env", "Do not import environment variables.");
@@ -71,6 +77,7 @@ public:
71 setOverride( "debug-ast", "true" ); 77 setOverride( "debug-ast", "true" );
72 setOverride( "info", "1" ); 78 setOverride( "info", "1" );
73 setOverride( 'c', "true" ); 79 setOverride( 'c', "true" );
80 setOverride( "no-cache", "false" );
74 81
75 addHelpOption(); 82 addHelpOption();
76 83
@@ -111,11 +118,13 @@ public:
111 Bu::FString sView; 118 Bu::FString sView;
112 Bu::FString sAction; 119 Bu::FString sAction;
113 Bu::FString sConfig; 120 Bu::FString sConfig;
121 Bu::FString sCacheFile;
114 bool bDot; 122 bool bDot;
115 bool bDebug; 123 bool bDebug;
116 bool bAutoInclude; 124 bool bAutoInclude;
117 bool bAstDump; 125 bool bAstDump;
118 bool bEnviron; 126 bool bEnviron;
127 bool bCache;
119 int iInfoLevel; 128 int iInfoLevel;
120}; 129};
121 130
@@ -155,6 +164,11 @@ int main( int argc, char *argv[] )
155 return 1; 164 return 1;
156 } 165 }
157 166
167 if( opts.bCache )
168 {
169 Cache::getInstance().bind( opts.sCacheFile );
170 }
171
158 // Load up the environment as vars. 172 // Load up the environment as vars.
159 if( opts.bEnviron ) 173 if( opts.bEnviron )
160 { 174 {
diff --git a/src/target.cpp b/src/target.cpp
index 1846044..4f9dd77 100644
--- a/src/target.cpp
+++ b/src/target.cpp
@@ -7,6 +7,7 @@
7#include "context.h" 7#include "context.h"
8#include "profile.h" 8#include "profile.h"
9#include "view.h" 9#include "view.h"
10#include "cache.h"
10 11
11#include <bu/membuf.h> 12#include <bu/membuf.h>
12#include <bu/formatter.h> 13#include <bu/formatter.h>
@@ -76,6 +77,19 @@ const StrList &Target::getRequiresList() const
76 return lsRequires; 77 return lsRequires;
77} 78}
78 79
80void Target::gatherRequires( Runner &r )
81{
82 Cache &c = Cache::getInstance();
83 try
84 {
85 lsRequires = c.getRequires( lsOutput.first() );
86 }
87 catch( Bu::HashException &e )
88 {
89 buildRequires( r );
90 }
91}
92
79void Target::buildRequires( Runner &r ) 93void Target::buildRequires( Runner &r )
80{ 94{
81 r.getContext().getView()->buildRequires( *this ); 95 r.getContext().getView()->buildRequires( *this );
@@ -108,6 +122,9 @@ void Target::buildRequires( Runner &r )
108 } 122 }
109 } 123 }
110 r.getContext().popScope(); 124 r.getContext().popScope();
125
126 Cache &c = Cache::getInstance();
127 c.setRequires( lsOutput.first(), lsRequires );
111} 128}
112 129
113void Target::addOutput( const Bu::FString &sOutput ) 130void Target::addOutput( const Bu::FString &sOutput )
diff --git a/src/target.h b/src/target.h
index 766366a..25af1f4 100644
--- a/src/target.h
+++ b/src/target.h
@@ -19,6 +19,12 @@ public:
19 void addRequires( const Bu::FString &sReq ); 19 void addRequires( const Bu::FString &sReq );
20 void addRequires( const AstBranch *pBr ); 20 void addRequires( const AstBranch *pBr );
21 const StrList &getRequiresList() const; 21 const StrList &getRequiresList() const;
22 /**
23 * This function will get the cached requires if they exist, build them
24 * if they don't. Use this is conditions, but use buildRequires to force
25 * a rebuild even if cached data exists.
26 */
27 void gatherRequires( class Runner &r );
22 void buildRequires( class Runner &r ); 28 void buildRequires( class Runner &r );
23 29
24 void addOutput( const Bu::FString &sOutput ); 30 void addOutput( const Bu::FString &sOutput );