aboutsummaryrefslogtreecommitdiff
path: root/src/target.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/target.cpp')
-rw-r--r--src/target.cpp466
1 files changed, 233 insertions, 233 deletions
diff --git a/src/target.cpp b/src/target.cpp
index 3a90c01..175030c 100644
--- a/src/target.cpp
+++ b/src/target.cpp
@@ -17,16 +17,16 @@
17using namespace Bu; 17using namespace Bu;
18 18
19Target::Target( bool bExplicit ) : 19Target::Target( bool bExplicit ) :
20 bExplicit( bExplicit ), 20 bExplicit( bExplicit ),
21 bRun( false ), 21 bRun( false ),
22 iDepCount( 0 ) 22 iDepCount( 0 )
23{ 23{
24} 24}
25 25
26Target::Target( const Bu::String &sOutput, bool bExplicit ) : 26Target::Target( const Bu::String &sOutput, bool bExplicit ) :
27 bExplicit( bExplicit ), 27 bExplicit( bExplicit ),
28 lsOutput( sOutput ), 28 lsOutput( sOutput ),
29 iDepCount( 0 ) 29 iDepCount( 0 )
30{ 30{
31} 31}
32 32
@@ -36,385 +36,385 @@ Target::~Target()
36 36
37void Target::addInput( const Bu::String &sInput ) 37void Target::addInput( const Bu::String &sInput )
38{ 38{
39 lsInput.append( sInput ); 39 lsInput.append( sInput );
40} 40}
41 41
42const StrList &Target::getInputList() const 42const StrList &Target::getInputList() const
43{ 43{
44 return lsInput; 44 return lsInput;
45} 45}
46 46
47void Target::resetInputList( const StrList &lInputs ) 47void Target::resetInputList( const StrList &lInputs )
48{ 48{
49 lsInput = lInputs; 49 lsInput = lInputs;
50 if( lsInput.getSize() == 1 ) 50 if( lsInput.getSize() == 1 )
51 { 51 {
52 hVars.insert("INPUT", lsInput.first() ); 52 hVars.insert("INPUT", lsInput.first() );
53 } 53 }
54 else 54 else
55 { 55 {
56 Variable vInput( Variable::typeList ); 56 Variable vInput( Variable::typeList );
57 for( StrList::iterator i = lsInput.begin(); i; i++ ) 57 for( StrList::iterator i = lsInput.begin(); i; i++ )
58 { 58 {
59 vInput.append( Variable( *i ) ); 59 vInput.append( Variable( *i ) );
60 } 60 }
61 hVars.insert("INPUT", vInput ); 61 hVars.insert("INPUT", vInput );
62 } 62 }
63} 63}
64 64
65void Target::addRequires( const Bu::String &sReq ) 65void Target::addRequires( const Bu::String &sReq )
66{ 66{
67 lsRequires.append( sReq ); 67 lsRequires.append( sReq );
68} 68}
69 69
70void Target::addRequires( const AstBranch *pBr ) 70void Target::addRequires( const AstBranch *pBr )
71{ 71{
72 lbRequires.append( pBr ); 72 lbRequires.append( pBr );
73} 73}
74 74
75const StrList &Target::getRequiresList() const 75const StrList &Target::getRequiresList() const
76{ 76{
77 return lsRequires; 77 return lsRequires;
78} 78}
79 79
80void Target::gatherRequires( Runner &r ) 80void Target::gatherRequires( Runner &r )
81{ 81{
82 Cache &c = Cache::getInstance(); 82 Cache &c = Cache::getInstance();
83 try 83 try
84 { 84 {
85 lsRequires = c.getRequires( lsOutput.first() ); 85 lsRequires = c.getRequires( lsOutput.first() );
86 } 86 }
87 catch( Bu::HashException &e ) 87 catch( Bu::HashException &e )
88 { 88 {
89 buildRequires( r ); 89 buildRequires( r );
90 } 90 }
91} 91}
92 92
93void Target::buildRequires( Runner &r ) 93void Target::buildRequires( Runner &r )
94{ 94{
95 r.getContext().getView()->buildRequires( *this ); 95 r.getContext().getView()->buildRequires( *this );
96 r.getContext().pushScope( hVars ); 96 r.getContext().pushScope( hVars );
97 for( AstBranchList::iterator i = lbRequires.begin(); i; i++ ) 97 for( AstBranchList::iterator i = lbRequires.begin(); i; i++ )
98 { 98 {
99 Variable v = r.execExpr( (*(*i)->getBranchBegin()).begin() ); 99 Variable v = r.execExpr( (*(*i)->getBranchBegin()).begin() );
100 if( v.getType() == Variable::typeList ) 100 if( v.getType() == Variable::typeList )
101 { 101 {
102 for( VarList::iterator j = v.begin(); j; j++ ) 102 for( VarList::iterator j = v.begin(); j; j++ )
103 { 103 {
104 Bu::String sReq = (*j).toString(); 104 Bu::String sReq = (*j).toString();
105 addRequires( sReq ); 105 addRequires( sReq );
106 /* try 106 /* try
107 { 107 {
108 addDep( r.getContext().getTarget( sReq ) ); 108 addDep( r.getContext().getTarget( sReq ) );
109 } 109 }
110 catch(...) { }*/ 110 catch(...) { }*/
111 } 111 }
112 } 112 }
113 else 113 else
114 { 114 {
115 Bu::String sReq = v.toString(); 115 Bu::String sReq = v.toString();
116 addRequires( sReq ); 116 addRequires( sReq );
117 /* try 117 /* try
118 { 118 {
119 addDep( r.getContext().getTarget( sReq ) ); 119 addDep( r.getContext().getTarget( sReq ) );
120 } 120 }
121 catch(...) { }*/ 121 catch(...) { }*/
122 } 122 }
123 } 123 }
124 r.getContext().popScope(); 124 r.getContext().popScope();
125 125
126 Cache &c = Cache::getInstance(); 126 Cache &c = Cache::getInstance();
127 c.setRequires( lsOutput.first(), lsRequires ); 127 c.setRequires( lsOutput.first(), lsRequires );
128} 128}
129 129
130void Target::addOutput( const Bu::String &sOutput ) 130void Target::addOutput( const Bu::String &sOutput )
131{ 131{
132 lsOutput.append( sOutput ); 132 lsOutput.append( sOutput );
133} 133}
134 134
135const StrList &Target::getOutputList() const 135const StrList &Target::getOutputList() const
136{ 136{
137 return lsOutput; 137 return lsOutput;
138} 138}
139 139
140void Target::setPrefix( const Bu::String &sPrefix ) 140void Target::setPrefix( const Bu::String &sPrefix )
141{ 141{
142 this->sPrefix = sPrefix; 142 this->sPrefix = sPrefix;
143} 143}
144 144
145const Bu::String &Target::getPrefix() const 145const Bu::String &Target::getPrefix() const
146{ 146{
147 return sPrefix; 147 return sPrefix;
148} 148}
149 149
150void Target::setRule( const Bu::String &sRule ) 150void Target::setRule( const Bu::String &sRule )
151{ 151{
152 this->sRule = sRule; 152 this->sRule = sRule;
153} 153}
154 154
155const Bu::String &Target::getRule() const 155const Bu::String &Target::getRule() const
156{ 156{
157 return sRule; 157 return sRule;
158} 158}
159 159
160bool Target::hasRule() const 160bool Target::hasRule() const
161{ 161{
162 return !sRule.isEmpty(); 162 return !sRule.isEmpty();
163} 163}
164 164
165bool Target::isExplicit() const 165bool Target::isExplicit() const
166{ 166{
167 return bExplicit; 167 return bExplicit;
168} 168}
169 169
170void Target::addDep( Target *pDep ) 170void Target::addDep( Target *pDep )
171{ 171{
172 lDeps.append( pDep ); 172 lDeps.append( pDep );
173} 173}
174 174
175const TargetList &Target::getDepList() const 175const TargetList &Target::getDepList() const
176{ 176{
177 return lDeps; 177 return lDeps;
178} 178}
179 179
180void Target::addProfile( const class AstBranch *pProfRoot ) 180void Target::addProfile( const class AstBranch *pProfRoot )
181{ 181{
182 Profile *pProf = new Profile( pProfRoot ); 182 Profile *pProf = new Profile( pProfRoot );
183 hProfiles.insert( pProf->getName(), pProf ); 183 hProfiles.insert( pProf->getName(), pProf );
184 /* 184 /*
185 hProfiles.insert( 185 hProfiles.insert(
186 dynamic_cast<const AstLeaf *>( 186 dynamic_cast<const AstLeaf *>(
187 (*pProfRoot->getBranchBegin()).first() 187 (*pProfRoot->getBranchBegin()).first()
188 )->getStrValue(), 188 )->getStrValue(),
189 pProfRoot 189 pProfRoot
190 ); 190 );
191 */ 191 */
192} 192}
193 193
194void Target::addProfile( const class Profile *pSrc ) 194void Target::addProfile( const class Profile *pSrc )
195{ 195{
196 hProfiles.insert( pSrc->getName(), new Profile( *pSrc ) ); 196 hProfiles.insert( pSrc->getName(), new Profile( *pSrc ) );
197} 197}
198 198
199bool Target::hasProfile( const Bu::String &sName ) const 199bool Target::hasProfile( const Bu::String &sName ) const
200{ 200{
201 return hProfiles.has( sName ); 201 return hProfiles.has( sName );
202} 202}
203 203
204const Profile *Target::getProfile( const Bu::String &sName ) const 204const Profile *Target::getProfile( const Bu::String &sName ) const
205{ 205{
206 return hProfiles.get( sName ); 206 return hProfiles.get( sName );
207} 207}
208 208
209void Target::setVars( const VarHash &hNewVars ) 209void Target::setVars( const VarHash &hNewVars )
210{ 210{
211 211
212 hVars = hNewVars; 212 hVars = hNewVars;
213} 213}
214 214
215const VarHash &Target::getVars() const 215const VarHash &Target::getVars() const
216{ 216{
217 return hVars; 217 return hVars;
218} 218}
219 219
220void Target::setDisplay( const Bu::String &sNewDisplay ) 220void Target::setDisplay( const Bu::String &sNewDisplay )
221{ 221{
222 if( !sDisplay.isSet() ) 222 if( !sDisplay.isSet() )
223 sDisplay = sNewDisplay; 223 sDisplay = sNewDisplay;
224} 224}
225 225
226const Bu::String &Target::getDisplay() const 226const Bu::String &Target::getDisplay() const
227{ 227{
228 return sDisplay; 228 return sDisplay;
229} 229}
230 230
231void Target::process( class Runner &r, const Bu::String &sProfile ) 231void Target::process( class Runner &r, const Bu::String &sProfile )
232{ 232{
233 r.getContext().getView()->beginTarget( sProfile, *this ); 233 r.getContext().getView()->beginTarget( sProfile, *this );
234 bRun = true; 234 bRun = true;
235 bool bShouldExec = false; 235 bool bShouldExec = false;
236 236
237 for( TargetList::iterator i = lDeps.begin(); i; i++ ) 237 for( TargetList::iterator i = lDeps.begin(); i; i++ )
238 { 238 {
239 if( (*i)->bRun ) 239 if( (*i)->bRun )
240 continue; 240 continue;
241 241
242 // TODO: This is important, in the future, it may be possible for a 242 // TODO: This is important, in the future, it may be possible for a
243 // target to be triggered by multiple dependant targets, to cover for 243 // target to be triggered by multiple dependant targets, to cover for
244 // this the below mergeUnder should be *TEMPORARY* and the target 244 // this the below mergeUnder should be *TEMPORARY* and the target
245 // that was marged to be reset post processing. 245 // that was marged to be reset post processing.
246 (*i)->mergeUnder( hVars ); 246 (*i)->mergeUnder( hVars );
247 (*i)->process( r, sProfile ); 247 (*i)->process( r, sProfile );
248 } 248 }
249 try 249 try
250 { 250 {
251 bShouldExec = hProfiles.get( sProfile )->shouldExec( r, *this ); 251 bShouldExec = hProfiles.get( sProfile )->shouldExec( r, *this );
252 } 252 }
253 catch( Bu::HashException &e ) 253 catch( Bu::HashException &e )
254 { 254 {
255 } 255 }
256 256
257 if( !bShouldExec ) 257 if( !bShouldExec )
258 { 258 {
259 r.getContext().getView()->skipTarget( sProfile, *this ); 259 r.getContext().getView()->skipTarget( sProfile, *this );
260 } 260 }
261 else 261 else
262 { 262 {
263 r.getContext().getView()->processTarget( sProfile, *this ); 263 r.getContext().getView()->processTarget( sProfile, *this );
264 r.execProfile( this, sProfile ); 264 r.execProfile( this, sProfile );
265 } 265 }
266 266
267 r.getContext().getView()->endTarget(); 267 r.getContext().getView()->endTarget();
268} 268}
269 269
270void Target::mergeUnder( const VarHash &hNewVars ) 270void Target::mergeUnder( const VarHash &hNewVars )
271{ 271{
272 for( VarHash::const_iterator i = hNewVars.begin(); i; i++ ) 272 for( VarHash::const_iterator i = hNewVars.begin(); i; i++ )
273 { 273 {
274 if( !hVars.has( i.getKey() ) ) 274 if( !hVars.has( i.getKey() ) )
275 { 275 {
276 hVars.insert( i.getKey(), i.getValue() ); 276 hVars.insert( i.getKey(), i.getValue() );
277 } 277 }
278 } 278 }
279} 279}
280 280
281bool Target::hasRun() 281bool Target::hasRun()
282{ 282{
283 return bRun; 283 return bRun;
284} 284}
285 285
286void Target::mergeUnder( const Target *pSrc ) 286void Target::mergeUnder( const Target *pSrc )
287{ 287{
288 // If either are explicit, then it's explicit 288 // If either are explicit, then it's explicit
289 bExplicit = bExplicit || pSrc->bExplicit; 289 bExplicit = bExplicit || pSrc->bExplicit;
290 290
291 merge( lsInput, pSrc->lsInput ); 291 merge( lsInput, pSrc->lsInput );
292 merge( lsRequires, pSrc->lsRequires ); 292 merge( lsRequires, pSrc->lsRequires );
293 merge( lsOutput, pSrc->lsOutput ); 293 merge( lsOutput, pSrc->lsOutput );
294 294
295 if( !sPrefix.isSet() ) 295 if( !sPrefix.isSet() )
296 sPrefix = pSrc->sPrefix; 296 sPrefix = pSrc->sPrefix;
297 297
298 sRule = pSrc->sRule; 298 sRule = pSrc->sRule;
299 299
300 mergeUnder( pSrc->hVars ); 300 mergeUnder( pSrc->hVars );
301 301
302 // Deps? They should be computed much after merging anyway, peh! 302 // Deps? They should be computed much after merging anyway, peh!
303 303
304 for( ProfileHash::const_iterator i = pSrc->hProfiles.begin(); i; i++ ) 304 for( ProfileHash::const_iterator i = pSrc->hProfiles.begin(); i; i++ )
305 { 305 {
306 if( !hProfiles.has( i.getKey() ) ) 306 if( !hProfiles.has( i.getKey() ) )
307 { 307 {
308 hProfiles.insert( i.getKey(), i.getValue() ); 308 hProfiles.insert( i.getKey(), i.getValue() );
309 } 309 }
310 } 310 }
311 311
312 if( !sDisplay.isSet() ) 312 if( !sDisplay.isSet() )
313 sDisplay = pSrc->sDisplay; 313 sDisplay = pSrc->sDisplay;
314 314
315 // Now we need to reset our vars. 315 // Now we need to reset our vars.
316 hVars.insert("INPUT", lsInput ); 316 hVars.insert("INPUT", lsInput );
317 hVars.insert("REQUIRES", lsRequires ); 317 hVars.insert("REQUIRES", lsRequires );
318 hVars.insert("OUTPUT", lsOutput ); 318 hVars.insert("OUTPUT", lsOutput );
319} 319}
320 320
321void Target::merge( StrList &lOut, const StrList &lIn ) 321void Target::merge( StrList &lOut, const StrList &lIn )
322{ 322{
323 Bu::Heap<Bu::String> hStr; 323 Bu::Heap<Bu::String> hStr;
324 for( StrList::const_iterator i = lOut.begin(); i; i++ ) 324 for( StrList::const_iterator i = lOut.begin(); i; i++ )
325 { 325 {
326 hStr.enqueue( *i ); 326 hStr.enqueue( *i );
327 } 327 }
328 for( StrList::const_iterator i = lIn.begin(); i; i++ ) 328 for( StrList::const_iterator i = lIn.begin(); i; i++ )
329 { 329 {
330 hStr.enqueue( *i ); 330 hStr.enqueue( *i );
331 } 331 }
332 332
333 lOut.clear(); 333 lOut.clear();
334 334
335 if( hStr.isEmpty() ) 335 if( hStr.isEmpty() )
336 return; 336 return;
337 337
338 lOut.append( hStr.dequeue() ); 338 lOut.append( hStr.dequeue() );
339 while( !hStr.isEmpty() ) 339 while( !hStr.isEmpty() )
340 { 340 {
341 if( hStr.peek() == lOut.last() ) 341 if( hStr.peek() == lOut.last() )
342 { 342 {
343 hStr.dequeue(); 343 hStr.dequeue();
344 } 344 }
345 else 345 else
346 { 346 {
347 lOut.append( hStr.dequeue() ); 347 lOut.append( hStr.dequeue() );
348 } 348 }
349 } 349 }
350} 350}
351 351
352void Target::resetRun( bool bHasRun ) 352void Target::resetRun( bool bHasRun )
353{ 353{
354 bRun = bHasRun; 354 bRun = bHasRun;
355 355
356 for( TargetList::iterator i = lDeps.begin(); i; i++ ) 356 for( TargetList::iterator i = lDeps.begin(); i; i++ )
357 { 357 {
358 (*i)->resetRun( bHasRun ); 358 (*i)->resetRun( bHasRun );
359 } 359 }
360} 360}
361 361
362void Target::setDepCount() 362void Target::setDepCount()
363{ 363{
364 bRun = true; 364 bRun = true;
365 iDepCount = 1; 365 iDepCount = 1;
366 for( TargetList::iterator i = lDeps.begin(); i; i++ ) 366 for( TargetList::iterator i = lDeps.begin(); i; i++ )
367 { 367 {
368 if( (*i)->bRun ) 368 if( (*i)->bRun )
369 { 369 {
370 continue; 370 continue;
371 } 371 }
372 (*i)->setDepCount(); 372 (*i)->setDepCount();
373 iDepCount += (*i)->getDepCount(); 373 iDepCount += (*i)->getDepCount();
374 } 374 }
375} 375}
376 376
377int Target::getDepCount() const 377int Target::getDepCount() const
378{ 378{
379 return iDepCount; 379 return iDepCount;
380} 380}
381 381
382void Target::collapseDeps() 382void Target::collapseDeps()
383{ 383{
384 if( lDeps.getSize() <= 1 ) 384 if( lDeps.getSize() <= 1 )
385 return; 385 return;
386 Bu::Hash<ptrdiff_t, bool> hDep; 386 Bu::Hash<ptrdiff_t, bool> hDep;
387 for( TargetList::iterator i = lDeps.begin(); i; i++ ) 387 for( TargetList::iterator i = lDeps.begin(); i; i++ )
388 { 388 {
389 if( hDep.has( (ptrdiff_t)*i ) ) 389 if( hDep.has( (ptrdiff_t)*i ) )
390 { 390 {
391 lDeps.erase( i ); 391 lDeps.erase( i );
392 i--; 392 i--;
393 } 393 }
394 else 394 else
395 { 395 {
396 hDep.insert( (ptrdiff_t)*i, true ); 396 hDep.insert( (ptrdiff_t)*i, true );
397 } 397 }
398 } 398 }
399} 399}
400 400
401Bu::Formatter &operator<<( Bu::Formatter &f, const Target &t ) 401Bu::Formatter &operator<<( Bu::Formatter &f, const Target &t )
402{ 402{
403 f.incIndent(); 403 f.incIndent();
404 f << f.nl << "Input = " << t.lsInput << "," << f.nl 404 f << f.nl << "Input = " << t.lsInput << "," << f.nl
405 << "Requires = " << t.lsRequires << "," << f.nl 405 << "Requires = " << t.lsRequires << "," << f.nl
406 << "Output = \"" << t.lsOutput << "\"," << f.nl 406 << "Output = \"" << t.lsOutput << "\"," << f.nl
407 << "Prefix = \"" << t.sPrefix << "\"," << f.nl 407 << "Prefix = \"" << t.sPrefix << "\"," << f.nl
408 << "Rule = \"" << t.sRule << "\"," << f.nl 408 << "Rule = \"" << t.sRule << "\"," << f.nl
409 << "Explicit = " << t.bExplicit << "," << f.nl 409 << "Explicit = " << t.bExplicit << "," << f.nl
410 << "Vars = " << t.hVars 410 << "Vars = " << t.hVars
411 << f.nl; 411 << f.nl;
412 f.decIndent(); 412 f.decIndent();
413 return f; 413 return f;
414} 414}
415 415
416template<> Bu::Formatter &Bu::operator<< <Target>( Bu::Formatter &f, const Target *t ) 416template<> Bu::Formatter &Bu::operator<< <Target>( Bu::Formatter &f, const Target *t )
417{ 417{
418 return f << (*t); 418 return f << (*t);
419} 419}
420 420