aboutsummaryrefslogtreecommitdiff
path: root/src/build.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-12-21 18:03:28 +0000
committerMike Buland <eichlan@xagasoft.com>2009-12-21 18:03:28 +0000
commit51e21a316be6e052251b3dfc7d671061ebd67cee (patch)
tree4b825dc642cb6eb9a060e54bf8d69288fbee4904 /src/build.cpp
parentad6f4dfcc671d3f8d458c42b0992956f2a2cf979 (diff)
downloadbuild-51e21a316be6e052251b3dfc7d671061ebd67cee.tar.gz
build-51e21a316be6e052251b3dfc7d671061ebd67cee.tar.bz2
build-51e21a316be6e052251b3dfc7d671061ebd67cee.tar.xz
build-51e21a316be6e052251b3dfc7d671061ebd67cee.zip
Removed the old trunk contents. About to load up m3
Diffstat (limited to 'src/build.cpp')
-rw-r--r--src/build.cpp442
1 files changed, 0 insertions, 442 deletions
diff --git a/src/build.cpp b/src/build.cpp
deleted file mode 100644
index dd6db1e..0000000
--- a/src/build.cpp
+++ /dev/null
@@ -1,442 +0,0 @@
1#include "build.h"
2#include "function.h"
3#include "viewerfactory.h"
4#include "bu/archive.h"
5#include "bu/file.h"
6
7#include <stdlib.h>
8
9subExceptionDef( BuildException );
10
11Build::Build() :
12 pStrProc( NULL ),
13 pView( NULL ),
14 bCacheUpdated( false )
15{
16}
17
18Build::~Build()
19{
20 if( sCacheName.size() > 0 && bCacheUpdated )
21 {
22 try
23 {
24 Bu::File f( sCacheName.c_str(),
25 Bu::File::Write|Bu::File::Create|Bu::File::Truncate );
26 Bu::Archive ar( f, Bu::Archive::save );
27
28 ar << cRequires;
29 }
30 catch( Bu::ExceptionBase &e )
31 {
32 }
33 }
34}
35
36void Build::setView( const std::string &sView )
37{
38 pView = ViewerFactory::getInstance().instantiate( sView.c_str() );
39}
40
41void Build::setCache( const std::string &sFileName )
42{
43 sCacheName = sFileName;
44
45 try
46 {
47 Bu::File f( sCacheName.c_str(), Bu::File::Read );
48 Bu::Archive ar( f, Bu::Archive::load );
49
50 ar >> cRequires;
51 }
52 catch( Bu::ExceptionBase &e )
53 {
54 }
55}
56
57void Build::setStringProc( StringProc *pStrProc )
58{
59 delete this->pStrProc;
60 this->pStrProc = pStrProc;
61}
62
63std::string Build::replVars( const std::string &sSrc, const StringList *pCont, VarMap *mExtra )
64{
65 if( pStrProc == NULL )
66 throw BuildException(
67 "No valid string processor was registered with the Build object."
68 );
69
70 return pStrProc->replVars( sSrc, pCont, mExtra );
71}
72
73void Build::execAction( const std::string &sWhat )
74{
75 if( mAction.find( sWhat ) == mAction.end() )
76 throw BuildException(
77 "No action matches %s, check your build.conf.",
78 sWhat.c_str()
79 );
80
81 Action *pAct = mAction[sWhat];
82
83 pView->beginAction( sWhat, pAct->size() );
84
85 for( pAct->begin(); !pAct->isEnded(); pAct->next() )
86 {
87 if( pAct->isGroup() )
88 {
89 if( mGroup.find( pAct->getWhat() ) == mGroup.end() )
90 throw BuildException(
91 "No group matches %s in action %s.",
92 pAct->getWhat().c_str(),
93 sWhat.c_str()
94 );
95 TargetList &sl = mGroup[pAct->getWhat()];
96 for( TargetList::iterator i = sl.begin(); i != sl.end(); i++ )
97 {
98 Target *pTarget = *i;
99 if( !pTarget->wasRun() )
100 pTarget->run( pAct->getAct(), *this );
101 }
102 }
103 else
104 {
105 if( mTarget.find( pAct->getWhat() ) == mTarget.end() )
106 throw BuildException(
107 "No target matches %s in action %s.",
108 pAct->getWhat().c_str(),
109 sWhat.c_str()
110 );
111 Target *pTarget = mTarget[pAct->getWhat()];
112 //pView->beginCommand( pAct->getAct(), pAct->getWhat() );
113 if( !pTarget->wasRun() )
114 pTarget->run( pAct->getAct(), *this );
115 //pView->endCommand();
116 }
117 }
118
119 pView->endAction();
120
121 return;
122}
123
124void Build::addTarget( Target *pTarget )
125{
126 TargetMap::iterator i = mTarget.find( pTarget->getName() );
127 if( i == mTarget.end() )
128 {
129 mTarget[pTarget->getName()] = pTarget;
130 }
131 else
132 {
133 throw BuildException("Merging targets isn't working yet.");
134 }
135}
136
137void Build::addRequires( const std::string &who, const std::string &what )
138{
139 mRequires[who].push_back( what );
140}
141
142void Build::addRule( Rule *pRule )
143{
144 mRule[pRule->getName()] = pRule;
145}
146
147Rule *Build::getRule( const std::string &name )
148{
149 if( mRule.find( name ) == mRule.end() )
150 throw BuildException("No rule named %s found.", name.c_str() );
151
152 return mRule[name];
153}
154
155void Build::addAction( Action *pAction )
156{
157 mAction[pAction->getName()] = pAction;
158}
159
160void Build::set( const std::string &cont, const std::string &var, const std::string &val )
161{
162 if( cont == "" )
163 {
164 mVars[var] = replVars( val, NULL, NULL );
165 }
166 else
167 {
168 StringList cl;
169 cl.push_front( cont );
170 mContVars[cont][var] = replVars( val, &cl, NULL );
171 }
172}
173
174void Build::setAdd( const std::string &cont, const std::string &var, const std::string &val )
175{
176 if( cont == "" )
177 {
178 mVars[var] = getVar( NULL, var, NULL ) + " " + replVars( val, NULL, NULL );
179 }
180 else
181 {
182 StringList cl;
183 cl.push_front( cont );
184 mContVars[cont][var] = getVar( &cl, var, NULL ) + " " + replVars( val, &cl, NULL );
185 }
186}
187
188void Build::copyContext( const std::string &src, const std::string &dest )
189{
190 if( mContVars.find(src) == mContVars.end() )
191 return;
192
193 VarMap &d = mContVars[dest];
194 VarMap &s = mContVars[src];
195 for( VarMap::iterator i = s.begin(); i != s.end(); i++ )
196 d[(*i).first] = (*i).second;
197}
198
199std::string Build::getVar( const StringList *cont, const std::string &var, VarMap *mExtra )
200{
201 if( mExtra != NULL )
202 {
203 if( mExtra->find(var) == mExtra->end() )
204 {
205 return getVar( cont, var, NULL );
206 }
207 return (*mExtra)[var];
208 }
209
210 if( cont == NULL )
211 {
212 if( mVars.find(var) == mVars.end() )
213 {
214 if( getenv( var.c_str() ) == NULL )
215 {
216 mVars[var] = "";
217 }
218 else
219 {
220 mVars[var] = getenv( var.c_str() );
221 }
222 }
223 return mVars[var];
224 }
225 else
226 {
227 if( cont->empty() )
228 {
229 return getVar( NULL, var, NULL );
230 }
231 std::string sTop = cont->front();
232 if( mContVars[sTop].find(var) == mContVars[sTop].end() )
233 {
234 ((StringList *)cont)->pop_front();
235 mContVars[sTop][var] = getVar( cont, var, NULL );
236 ((StringList *)cont)->push_front( sTop );
237 }
238 return mContVars[sTop][var];
239 }
240}
241
242void Build::debugDump()
243{
244 printf("Requires:\n");
245 for( ReqMap::iterator i = mRequires.begin(); i != mRequires.end(); i++ )
246 {
247 printf(" %s: ", (*i).first.c_str() );
248
249 for( StringList::iterator j = (*i).second.begin();
250 j != (*i).second.end(); j++ )
251 {
252 if( j != (*i).second.begin() )
253 printf(", ");
254 printf("%s", (*j).c_str() );
255 }
256 printf("\n");
257 }
258
259 printf("Targets:\n");
260 for( TargetMap::iterator i = mTarget.begin(); i != mTarget.end(); i++ )
261 {
262 printf(" %s:\n", (*i).first.c_str() );
263 printf(" Rule: %s\n", (*i).second->getRule().c_str() );
264 printf(" Input: ");
265 for( StringList::iterator j = (*i).second->getInput().begin();
266 j != (*i).second->getInput().end(); j++ )
267 {
268 if( j != (*i).second->getInput().begin() )
269 printf(", ");
270 printf("%s", (*j).c_str() );
271 }
272 printf("\n");
273 }
274
275 printf("Global Variables:\n");
276 for( VarMap::iterator i = mVars.begin(); i != mVars.end(); i++ )
277 {
278 printf(" \"%s\" = \"%s\"\n", (*i).first.c_str(), (*i).second.c_str() );
279 }
280
281 printf("Context Variables:\n");
282 for( ContextMap::iterator i = mContVars.begin(); i != mContVars.end(); i++ )
283 {
284 printf(" %s:\n", (*i).first.c_str() );
285
286 for( VarMap::iterator j = (*i).second.begin();
287 j != (*i).second.end(); j++ )
288 {
289 printf(" \"%s\" = \"%s\"\n",
290 (*j).first.c_str(),
291 (*j).second.c_str()
292 );
293 }
294 }
295
296 printf("Rules:\n");
297 for( RuleMap::iterator i = mRule.begin(); i != mRule.end(); i++ )
298 {
299 printf(" %s:\n", (*i).first.c_str() );
300 printf(" Matches: func\n");
301 printf(" Filters: %d\n", (*i).second->getFilterList().size() );
302 printf(" Performs: %d\n", (*i).second->getPerformList().size() );
303 printf(" Produces:\n");
304 printf(" Requires:\n");
305 }
306
307 printf("Actions:\n");
308 for( ActionMap::iterator i = mAction.begin(); i != mAction.end(); i++ )
309 {
310 printf(" %s: ", (*i).first.c_str() );
311 for( (*i).second->begin(); !(*i).second->isEnded(); (*i).second->next() )
312 {
313 printf("%d:%s ", (*i).second->getAct(), (*i).second->getWhat().c_str() );
314 }
315 printf("\n");
316 }
317
318 printf("Groups:\n");
319 for( GroupMap::iterator i = mGroup.begin(); i != mGroup.end(); i++ )
320 {
321 printf(" %s: ", (*i).first.c_str() );
322 for( TargetList::iterator j = (*i).second.begin();
323 j != (*i).second.end(); j++ )
324 {
325 if( j != (*i).second.begin() ) printf(", ");
326 printf("%s", (*j)->getName().c_str() );
327 }
328 printf("\n");
329 }
330}
331
332RuleList Build::findChainRules( Rule *pHead )
333{
334 RuleList lOut;
335 FunctionList &lMatches = pHead->getMatchesList();
336
337 for( RuleMap::iterator i = mRule.begin(); i != mRule.end(); i++ )
338 {
339 if( (*i).second == pHead )
340 continue;
341
342 for( FunctionList::iterator j = lMatches.begin();
343 j != lMatches.end(); j++ )
344 {
345 StringList lTmp;
346 (*j)->execute( NULL, (*i).second->getProducesList(), lTmp );
347 if( !lTmp.empty() )
348 {
349 lOut.push_back( (*i).second );
350 break;
351 }
352 }
353 }
354
355 return lOut;
356}
357
358StringList &Build::getRequires( std::string sName )
359{
360 return mRequires[sName];
361}
362
363bool Build::getCached( const std::string &sID, int nTime, StringList &lOut )
364{
365 Cache::Entry *pEnt = cRequires.get( sID );
366 if( pEnt == NULL )
367 return false;
368 if( pEnt->tCreated < nTime )
369 return false;
370
371 lOut.insert( lOut.end(), pEnt->lData.begin(), pEnt->lData.end() );
372
373 return true;
374}
375
376void Build::updateCache( const std::string &sID, FunctionList &lFunc, StringList &lOut )
377{
378 Cache::Entry *pEnt = new Cache::Entry;
379 getView()->beginRequiresCheck( false, sID );
380 for( FunctionList::iterator f = lFunc.begin(); f != lFunc.end(); f++ )
381 {
382 StringList lTmpIn;
383 lTmpIn.push_back( sID );
384 (*f)->execute( this, lTmpIn, pEnt->lData );
385 }
386 getView()->endRequiresCheck();
387
388 lOut.insert( lOut.end(), pEnt->lData.begin(), pEnt->lData.end() );
389 cRequires.put( sID, pEnt );
390
391 pEnt->tCreated = time( NULL );
392
393 bCacheUpdated = true;
394}
395
396void Build::chainTarget( const std::string &sName )
397{
398 TargetMap::iterator i = mTarget.find(sName);
399 if( i == mTarget.end() ) return;
400
401 if( !(*i).second->wasRun() )
402 (*i).second->run( Action::actCheck, *this );
403}
404
405void Build::printInfo()
406{
407 printf("---- Build Info ----\n");
408 printf("Valid actions: ");
409 for( ActionMap::iterator i = mAction.begin(); i != mAction.end(); i++ )
410 {
411 if( i != mAction.begin() ) printf(", ");
412 if( (*i).first == "" )
413 printf("*default*");
414 else
415 printf("%s", (*i).first.c_str() );
416 }
417 printf("\n\n");
418}
419
420void Build::setMode( Action::eAction nAct )
421{
422 for( ActionMap::iterator i = mAction.begin(); i != mAction.end(); i++ )
423 {
424 (*i).second->setMode( nAct );
425 }
426}
427
428void Build::addToGroup( const std::string &sGroup, Target *pTarget )
429{
430 if( mGroup.find( sGroup ) == mGroup.end() )
431 {
432 mGroup[sGroup] = TargetList();
433 }
434
435 mGroup[sGroup].push_back( pTarget );
436}
437
438bool Build::hasAction( const std::string &str )
439{
440 return mAction.find( str ) != mAction.end();
441}
442