diff options
Diffstat (limited to '')
| -rw-r--r-- | src/context.cpp | 808 |
1 files changed, 404 insertions, 404 deletions
diff --git a/src/context.cpp b/src/context.cpp index 22bea57..7f0c56f 100644 --- a/src/context.cpp +++ b/src/context.cpp | |||
| @@ -14,9 +14,9 @@ | |||
| 14 | using namespace Bu; | 14 | using namespace Bu; |
| 15 | 15 | ||
| 16 | Context::Context() : | 16 | Context::Context() : |
| 17 | pView( NULL ) | 17 | pView( NULL ) |
| 18 | { | 18 | { |
| 19 | pushScope(); | 19 | pushScope(); |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | Context::~Context() | 22 | Context::~Context() |
| @@ -25,522 +25,522 @@ Context::~Context() | |||
| 25 | 25 | ||
| 26 | void Context::addTarget( Target *pTarget ) | 26 | void Context::addTarget( Target *pTarget ) |
| 27 | { | 27 | { |
| 28 | for( StrList::const_iterator i = pTarget->getOutputList().begin(); i; i++ ) | 28 | for( StrList::const_iterator i = pTarget->getOutputList().begin(); i; i++ ) |
| 29 | { | 29 | { |
| 30 | hTarget.insert( (*i).getStr(), pTarget ); | 30 | hTarget.insert( (*i).getStr(), pTarget ); |
| 31 | } | 31 | } |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | void Context::addRule( Rule *pRule ) | 34 | void Context::addRule( Rule *pRule ) |
| 35 | { | 35 | { |
| 36 | hRule.insert( pRule->getName(), pRule ); | 36 | hRule.insert( pRule->getName(), pRule ); |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | void Context::addFunction( Function *pFunction ) | 39 | void Context::addFunction( Function *pFunction ) |
| 40 | { | 40 | { |
| 41 | pFunction->setContext( this ); | 41 | pFunction->setContext( this ); |
| 42 | hFunction.insert( pFunction->getName(), pFunction ); | 42 | hFunction.insert( pFunction->getName(), pFunction ); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | void Context::addVariable( const Bu::String &sName, const Variable &vValue ) | 45 | void Context::addVariable( const Bu::String &sName, const Variable &vValue ) |
| 46 | { | 46 | { |
| 47 | for( ScopeStack::iterator i = sVars.begin(); i; i++ ) | 47 | for( ScopeStack::iterator i = sVars.begin(); i; i++ ) |
| 48 | { | 48 | { |
| 49 | if( (*i).has( sName ) ) | 49 | if( (*i).has( sName ) ) |
| 50 | { | 50 | { |
| 51 | // sio << "Replacing higher scope variable \"" << sName << "\" with value \"" << (*i).get( sName ) << "\" with new value \"" << vValue << "\"" << sio.nl; | 51 | // sio << "Replacing higher scope variable \"" << sName << "\" with value \"" << (*i).get( sName ) << "\" with new value \"" << vValue << "\"" << sio.nl; |
| 52 | (*i).insert( sName, vValue ); | 52 | (*i).insert( sName, vValue ); |
| 53 | return; | 53 | return; |
| 54 | } | 54 | } |
| 55 | } | 55 | } |
| 56 | sVars.first().insert( sName, vValue ); | 56 | sVars.first().insert( sName, vValue ); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | void Context::addAction( Action *pAction ) | 59 | void Context::addAction( Action *pAction ) |
| 60 | { | 60 | { |
| 61 | hAction.insert( pAction->getName(), pAction ); | 61 | hAction.insert( pAction->getName(), pAction ); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | Action *Context::getAction( const Bu::String &sName ) | 64 | Action *Context::getAction( const Bu::String &sName ) |
| 65 | { | 65 | { |
| 66 | return hAction.get( sName ); | 66 | return hAction.get( sName ); |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | void Context::addTargetToTag( Target *pTarget, const Bu::String &sTag ) | 69 | void Context::addTargetToTag( Target *pTarget, const Bu::String &sTag ) |
| 70 | { | 70 | { |
| 71 | if( !hTag.has( sTag ) ) | 71 | if( !hTag.has( sTag ) ) |
| 72 | { | 72 | { |
| 73 | hTag.insert( sTag, TargetList() ); | 73 | hTag.insert( sTag, TargetList() ); |
| 74 | } | 74 | } |
| 75 | hTag.get( sTag ).append( pTarget ); | 75 | hTag.get( sTag ).append( pTarget ); |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | void Context::addTargetToTags( Target *pTarget, const StrList &sTags ) | 78 | void Context::addTargetToTags( Target *pTarget, const StrList &sTags ) |
| 79 | { | 79 | { |
| 80 | for( StrList::const_iterator i = sTags.begin(); i; i++ ) | 80 | for( StrList::const_iterator i = sTags.begin(); i; i++ ) |
| 81 | { | 81 | { |
| 82 | addTargetToTag( pTarget, *i ); | 82 | addTargetToTag( pTarget, *i ); |
| 83 | } | 83 | } |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | TargetList &Context::getTag( const Bu::String &sTag ) | 86 | TargetList &Context::getTag( const Bu::String &sTag ) |
| 87 | { | 87 | { |
| 88 | return hTag.get( sTag ); | 88 | return hTag.get( sTag ); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | Variable &Context::getVariable( const Bu::String &sName ) | 91 | Variable &Context::getVariable( const Bu::String &sName ) |
| 92 | { | 92 | { |
| 93 | for( ScopeStack::iterator i = sVars.begin(); i; i++ ) | 93 | for( ScopeStack::iterator i = sVars.begin(); i; i++ ) |
| 94 | { | 94 | { |
| 95 | if( (*i).has( sName ) ) | 95 | if( (*i).has( sName ) ) |
| 96 | { | 96 | { |
| 97 | return (*i).get( sName ); | 97 | return (*i).get( sName ); |
| 98 | } | 98 | } |
| 99 | } | 99 | } |
| 100 | throw Bu::ExceptionBase("No such variable."); | 100 | throw Bu::ExceptionBase("No such variable."); |
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | void Context::delVariable( const Bu::String &sName ) | 103 | void Context::delVariable( const Bu::String &sName ) |
| 104 | { | 104 | { |
| 105 | for( ScopeStack::iterator i = sVars.begin(); i; i++ ) | 105 | for( ScopeStack::iterator i = sVars.begin(); i; i++ ) |
| 106 | { | 106 | { |
| 107 | if( (*i).has( sName ) ) | 107 | if( (*i).has( sName ) ) |
| 108 | { | 108 | { |
| 109 | (*i).erase( sName ); | 109 | (*i).erase( sName ); |
| 110 | } | 110 | } |
| 111 | } | 111 | } |
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | void Context::pushScope() | 114 | void Context::pushScope() |
| 115 | { | 115 | { |
| 116 | VarHash h; | 116 | VarHash h; |
| 117 | if( !sVars.isEmpty() ) | 117 | if( !sVars.isEmpty() ) |
| 118 | h = sVars.peek(); | 118 | h = sVars.peek(); |
| 119 | sVars.push( h ); | 119 | sVars.push( h ); |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | void Context::pushScope( const VarHash &hNewVars ) | 122 | void Context::pushScope( const VarHash &hNewVars ) |
| 123 | { | 123 | { |
| 124 | // sio << "Pushing scope, merging contexts." << sio.nl << sio.nl; | 124 | // sio << "Pushing scope, merging contexts." << sio.nl << sio.nl; |
| 125 | VarHash h = hNewVars; | 125 | VarHash h = hNewVars; |
| 126 | if( !sVars.isEmpty() ) | 126 | if( !sVars.isEmpty() ) |
| 127 | { | 127 | { |
| 128 | // sio << "hNewVars = " << h << sio.nl << sio.nl | 128 | // sio << "hNewVars = " << h << sio.nl << sio.nl |
| 129 | // << "sVars = " << sVars.peek() << sio.nl; | 129 | // << "sVars = " << sVars.peek() << sio.nl; |
| 130 | for( VarHash::iterator i = sVars.peek().begin(); i; i++ ) | 130 | for( VarHash::iterator i = sVars.peek().begin(); i; i++ ) |
| 131 | { | 131 | { |
| 132 | // sio << "Checking '" << i.getKey() << "' (" << i.getValue() << ")." << sio.nl; | 132 | // sio << "Checking '" << i.getKey() << "' (" << i.getValue() << ")." << sio.nl; |
| 133 | if( !h.has( i.getKey() ) ) | 133 | if( !h.has( i.getKey() ) ) |
| 134 | { | 134 | { |
| 135 | // sio << " Context doesn't have '" << i.getKey() << "' adding... '" << i.getValue() << "'." << sio.nl; | 135 | // sio << " Context doesn't have '" << i.getKey() << "' adding... '" << i.getValue() << "'." << sio.nl; |
| 136 | h.insert( i.getKey(), i.getValue() ); | 136 | h.insert( i.getKey(), i.getValue() ); |
| 137 | } | 137 | } |
| 138 | } | 138 | } |
| 139 | } | 139 | } |
| 140 | sVars.push( h ); | 140 | sVars.push( h ); |
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | VarHash &Context::getScope() | 143 | VarHash &Context::getScope() |
| 144 | { | 144 | { |
| 145 | return sVars.peek(); | 145 | return sVars.peek(); |
| 146 | } | 146 | } |
| 147 | 147 | ||
| 148 | void Context::popScope() | 148 | void Context::popScope() |
| 149 | { | 149 | { |
| 150 | sVars.pop(); | 150 | sVars.pop(); |
| 151 | } | 151 | } |
| 152 | 152 | ||
| 153 | Variable Context::call( const Bu::String &sName, Variable &input, | 153 | Variable Context::call( const Bu::String &sName, Variable &input, |
| 154 | VarList lParams ) | 154 | VarList lParams ) |
| 155 | { | 155 | { |
| 156 | if( !hFunction.has( sName ) ) | 156 | if( !hFunction.has( sName ) ) |
| 157 | { | 157 | { |
| 158 | // Try to load the function... | 158 | // Try to load the function... |
| 159 | try | 159 | try |
| 160 | { | 160 | { |
| 161 | addFunction( FunctionPlugger::getInstance().instantiate( sName ) ); | 161 | addFunction( FunctionPlugger::getInstance().instantiate( sName ) ); |
| 162 | } | 162 | } |
| 163 | catch(...) | 163 | catch(...) |
| 164 | { | 164 | { |
| 165 | throw Bu::ExceptionBase("Unknown function called: %s", | 165 | throw Bu::ExceptionBase("Unknown function called: %s", |
| 166 | sName.getStr() ); | 166 | sName.getStr() ); |
| 167 | } | 167 | } |
| 168 | } | 168 | } |
| 169 | return hFunction.get( sName )->call( input, lParams ); | 169 | return hFunction.get( sName )->call( input, lParams ); |
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | #include <bu/sio.h> | 172 | #include <bu/sio.h> |
| 173 | using namespace Bu; | 173 | using namespace Bu; |
| 174 | Bu::String Context::expand( const Bu::String &sInS ) | 174 | Bu::String Context::expand( const Bu::String &sInS ) |
| 175 | { | 175 | { |
| 176 | Bu::String sRet; | 176 | Bu::String sRet; |
| 177 | Bu::String sIn = sInS; | 177 | Bu::String sIn = sInS; |
| 178 | 178 | ||
| 179 | for( int iPass = 0; iPass < 2; iPass++ ) | 179 | for( int iPass = 0; iPass < 2; iPass++ ) |
| 180 | { | 180 | { |
| 181 | Bu::String::const_iterator b = sIn.begin(); | 181 | Bu::String::const_iterator b = sIn.begin(); |
| 182 | sRet.clear(); | 182 | sRet.clear(); |
| 183 | for(;;) | 183 | for(;;) |
| 184 | { | 184 | { |
| 185 | Bu::String::const_iterator e = b.find('$'); | 185 | Bu::String::const_iterator e = b.find('$'); |
| 186 | if( !e ) | 186 | if( !e ) |
| 187 | { | 187 | { |
| 188 | sRet.append( b ); | 188 | sRet.append( b ); |
| 189 | break; | 189 | break; |
| 190 | } | 190 | } |
| 191 | sRet.append( b, e ); | 191 | sRet.append( b, e ); |
| 192 | b = e+1; | 192 | b = e+1; |
| 193 | if( !b ) | 193 | if( !b ) |
| 194 | { | 194 | { |
| 195 | sRet.append('$'); | 195 | sRet.append('$'); |
| 196 | } | 196 | } |
| 197 | else if( *b == '{' ) | 197 | else if( *b == '{' ) |
| 198 | { | 198 | { |
| 199 | b++; | 199 | b++; |
| 200 | e = b.find('}'); | 200 | e = b.find('}'); |
| 201 | Bu::String sVar( b, e ); | 201 | Bu::String sVar( b, e ); |
| 202 | try | 202 | try |
| 203 | { | 203 | { |
| 204 | sRet.append( getVariable( sVar ).toString() ); | 204 | sRet.append( getVariable( sVar ).toString() ); |
| 205 | } catch(...) | 205 | } catch(...) |
| 206 | { | 206 | { |
| 207 | // TODO: This may be handy debugging later... | 207 | // TODO: This may be handy debugging later... |
| 208 | //sio << "No variable named " << sVar << sio.nl; | 208 | //sio << "No variable named " << sVar << sio.nl; |
| 209 | //sio << "Vars: " << sVars << sio.nl << sio.nl; | 209 | //sio << "Vars: " << sVars << sio.nl << sio.nl; |
| 210 | } | 210 | } |
| 211 | b = e+1; | 211 | b = e+1; |
| 212 | } | 212 | } |
| 213 | else if( *b == '(' && iPass == 1 ) | 213 | else if( *b == '(' && iPass == 1 ) |
| 214 | { | 214 | { |
| 215 | Bu::String sCmd; | 215 | Bu::String sCmd; |
| 216 | b++; | 216 | b++; |
| 217 | for( e = b; e != ')'; e++ ) | 217 | for( e = b; e != ')'; e++ ) |
| 218 | { | 218 | { |
| 219 | if( *e == '\\' && *(e+1) == ')' ) | 219 | if( *e == '\\' && *(e+1) == ')' ) |
| 220 | { | 220 | { |
| 221 | sCmd += ')'; | 221 | sCmd += ')'; |
| 222 | e++; | 222 | e++; |
| 223 | } | 223 | } |
| 224 | else | 224 | else |
| 225 | sCmd += *e; | 225 | sCmd += *e; |
| 226 | } | 226 | } |
| 227 | //e = b.find(')'); | 227 | //e = b.find(')'); |
| 228 | // Bu::String sCmd( b, e ); | 228 | // Bu::String sCmd( b, e ); |
| 229 | Bu::String sBuf; | 229 | Bu::String sBuf; |
| 230 | try | 230 | try |
| 231 | { | 231 | { |
| 232 | //sio << "Executing command: >>>" << sCmd << "<<<" << sio.nl; | 232 | //sio << "Executing command: >>>" << sCmd << "<<<" << sio.nl; |
| 233 | Process p( Process::StdOut, | 233 | Process p( Process::StdOut, |
| 234 | "/bin/bash", "/bin/bash", "-c", sCmd.getStr(), NULL | 234 | "/bin/bash", "/bin/bash", "-c", sCmd.getStr(), NULL |
| 235 | ); | 235 | ); |
| 236 | char buf[4096]; | 236 | char buf[4096]; |
| 237 | do | 237 | do |
| 238 | { | 238 | { |
| 239 | sBuf.append( buf, p.read( buf, 4096 ) ); | 239 | sBuf.append( buf, p.read( buf, 4096 ) ); |
| 240 | } | 240 | } |
| 241 | while( p.isRunning() ); | 241 | while( p.isRunning() ); |
| 242 | sBuf.append( buf, p.read( buf, 4096 ) ); | 242 | sBuf.append( buf, p.read( buf, 4096 ) ); |
| 243 | sBuf = sBuf.replace("\n", " ").replace("\r", " "). | 243 | sBuf = sBuf.replace("\n", " ").replace("\r", " "). |
| 244 | trimWhitespace(); | 244 | trimWhitespace(); |
| 245 | sRet.append( sBuf ); | 245 | sRet.append( sBuf ); |
| 246 | } catch(...) | 246 | } catch(...) |
| 247 | { | 247 | { |
| 248 | // TODO: This may be handy debugging later... | 248 | // TODO: This may be handy debugging later... |
| 249 | //sio << "No variable named " << sVar << sio.nl; | 249 | //sio << "No variable named " << sVar << sio.nl; |
| 250 | //sio << "Vars: " << sVars << sio.nl << sio.nl; | 250 | //sio << "Vars: " << sVars << sio.nl << sio.nl; |
| 251 | } | 251 | } |
| 252 | b = e+1; | 252 | b = e+1; |
| 253 | } | 253 | } |
| 254 | else | 254 | else |
| 255 | { | 255 | { |
| 256 | // Not a match, uh, just output the $ for now... | 256 | // Not a match, uh, just output the $ for now... |
| 257 | sRet.append('$'); | 257 | sRet.append('$'); |
| 258 | } | 258 | } |
| 259 | } | 259 | } |
| 260 | 260 | ||
| 261 | sIn = sRet; | 261 | sIn = sRet; |
| 262 | } | 262 | } |
| 263 | return sRet; | 263 | return sRet; |
| 264 | } | 264 | } |
| 265 | 265 | ||
| 266 | Target *Context::getTarget( const Bu::String &sOutput ) | 266 | Target *Context::getTarget( const Bu::String &sOutput ) |
| 267 | { | 267 | { |
| 268 | return hTarget.get( sOutput ); | 268 | return hTarget.get( sOutput ); |
| 269 | } | 269 | } |
| 270 | 270 | ||
| 271 | TargetList Context::getExplicitTargets() | 271 | TargetList Context::getExplicitTargets() |
| 272 | { | 272 | { |
| 273 | TargetList lRet; | 273 | TargetList lRet; |
| 274 | for( TargetHash::iterator i = hTarget.begin(); i; i++ ) | 274 | for( TargetHash::iterator i = hTarget.begin(); i; i++ ) |
| 275 | { | 275 | { |
| 276 | if( (*i)->isExplicit() ) | 276 | if( (*i)->isExplicit() ) |
| 277 | lRet.append( *i ); | 277 | lRet.append( *i ); |
| 278 | } | 278 | } |
| 279 | return lRet; | 279 | return lRet; |
| 280 | } | 280 | } |
| 281 | 281 | ||
| 282 | void Context::buildTargetTree( Runner &r ) | 282 | void Context::buildTargetTree( Runner &r ) |
| 283 | { | 283 | { |
| 284 | TargetList lTargets = hTarget.getValues(); | 284 | TargetList lTargets = hTarget.getValues(); |
| 285 | 285 | ||
| 286 | for( TargetList::iterator i = lTargets.begin(); i; i++ ) | 286 | for( TargetList::iterator i = lTargets.begin(); i; i++ ) |
| 287 | { | 287 | { |
| 288 | // I believe we only want to autogenerate targets for explicit targets | 288 | // I believe we only want to autogenerate targets for explicit targets |
| 289 | // that have rules defined. | 289 | // that have rules defined. |
| 290 | if( !(*i)->isExplicit() || !(*i)->hasRule() ) | 290 | if( !(*i)->isExplicit() || !(*i)->hasRule() ) |
| 291 | continue; | 291 | continue; |
| 292 | 292 | ||
| 293 | StrList lNewIns; // The new "changed" inputs for this target | 293 | StrList lNewIns; // The new "changed" inputs for this target |
| 294 | 294 | ||
| 295 | Rule *pMaster; | 295 | Rule *pMaster; |
| 296 | try | 296 | try |
| 297 | { | 297 | { |
| 298 | pMaster = hRule.get( (*i)->getRule() ); | 298 | pMaster = hRule.get( (*i)->getRule() ); |
| 299 | } | 299 | } |
| 300 | catch( Bu::HashException &e ) | 300 | catch( Bu::HashException &e ) |
| 301 | { | 301 | { |
| 302 | throw Bu::ExceptionBase("Unknown rule: %s", (*i)->getRule().getStr() ); | 302 | throw Bu::ExceptionBase("Unknown rule: %s", (*i)->getRule().getStr() ); |
| 303 | } | 303 | } |
| 304 | 304 | ||
| 305 | for( StrList::const_iterator j = (*i)->getInputList().begin(); j; j++ ) | 305 | for( StrList::const_iterator j = (*i)->getInputList().begin(); j; j++ ) |
| 306 | { | 306 | { |
| 307 | if( pMaster->ruleMatches( r, *j ) ) | 307 | if( pMaster->ruleMatches( r, *j ) ) |
| 308 | { | 308 | { |
| 309 | lNewIns.append( *j ); | 309 | lNewIns.append( *j ); |
| 310 | } | 310 | } |
| 311 | 311 | ||
| 312 | if( hTarget.has( *j ) ) | 312 | if( hTarget.has( *j ) ) |
| 313 | { | 313 | { |
| 314 | // Find the existing dependancy | 314 | // Find the existing dependancy |
| 315 | lNewIns.append( *j ); | 315 | lNewIns.append( *j ); |
| 316 | } | 316 | } |
| 317 | //else | 317 | //else |
| 318 | //{ | 318 | //{ |
| 319 | buildTargetTree( r, *i, *j, pMaster, lNewIns ); | 319 | buildTargetTree( r, *i, *j, pMaster, lNewIns ); |
| 320 | //} | 320 | //} |
| 321 | } | 321 | } |
| 322 | 322 | ||
| 323 | pMaster->prepTarget( *i ); | 323 | pMaster->prepTarget( *i ); |
| 324 | (*i)->resetInputList( lNewIns ); | 324 | (*i)->resetInputList( lNewIns ); |
| 325 | } | 325 | } |
| 326 | //sio << "Building dependancies: " << Fmt(3) << 0 << "%\r" << sio.flush; | 326 | //sio << "Building dependancies: " << Fmt(3) << 0 << "%\r" << sio.flush; |
| 327 | //int iSize = hTarget.getSize(), iCur = 0; | 327 | //int iSize = hTarget.getSize(), iCur = 0; |
| 328 | for( TargetHash::iterator i = hTarget.begin(); i; i++ ) | 328 | for( TargetHash::iterator i = hTarget.begin(); i; i++ ) |
| 329 | { | 329 | { |
| 330 | // Before we can take a look at the requirements, we need to build | 330 | // Before we can take a look at the requirements, we need to build |
| 331 | // them... | 331 | // them... |
| 332 | // (*i)->buildRequires( r ); | 332 | // (*i)->buildRequires( r ); |
| 333 | 333 | ||
| 334 | // For every target we have to examine both it's inputs and it's | 334 | // For every target we have to examine both it's inputs and it's |
| 335 | // additional requirements. Inputs first | 335 | // additional requirements. Inputs first |
| 336 | StrList lDeps( (*i)->getInputList() ); | 336 | StrList lDeps( (*i)->getInputList() ); |
| 337 | lDeps += (*i)->getRequiresList(); | 337 | lDeps += (*i)->getRequiresList(); |
| 338 | for( StrList::const_iterator j = lDeps.begin(); j; j++ ) | 338 | for( StrList::const_iterator j = lDeps.begin(); j; j++ ) |
| 339 | { | 339 | { |
| 340 | try | 340 | try |
| 341 | { | 341 | { |
| 342 | (*i)->addDep( hTarget.get( *j ) ); | 342 | (*i)->addDep( hTarget.get( *j ) ); |
| 343 | } | 343 | } |
| 344 | catch(...) | 344 | catch(...) |
| 345 | { | 345 | { |
| 346 | } | 346 | } |
| 347 | } | 347 | } |
| 348 | //iCur++; | 348 | //iCur++; |
| 349 | // sio << "Building dependancies: " << Fmt(3) << (iCur*100/iSize) << "%\r" << sio.flush; | 349 | // sio << "Building dependancies: " << Fmt(3) << (iCur*100/iSize) << "%\r" << sio.flush; |
| 350 | (*i)->collapseDeps(); | 350 | (*i)->collapseDeps(); |
| 351 | } | 351 | } |
| 352 | // sio << sio.nl; | 352 | // sio << sio.nl; |
| 353 | 353 | ||
| 354 | for( TargetHash::iterator i = hTarget.begin(); i; i++ ) | 354 | for( TargetHash::iterator i = hTarget.begin(); i; i++ ) |
| 355 | { | 355 | { |
| 356 | if( !(*i)->isExplicit() ) | 356 | if( !(*i)->isExplicit() ) |
| 357 | continue; | 357 | continue; |
| 358 | (*i)->setDepCount(); | 358 | (*i)->setDepCount(); |
| 359 | (*i)->resetRun( false ); | 359 | (*i)->resetRun( false ); |
| 360 | } | 360 | } |
| 361 | } | 361 | } |
| 362 | 362 | ||
| 363 | void Context::buildTargetTree( class Runner &r, class Target *pTarget, const Bu::String &sInput, Rule *pMaster, StrList &lNewIns ) | 363 | void Context::buildTargetTree( class Runner &r, class Target *pTarget, const Bu::String &sInput, Rule *pMaster, StrList &lNewIns ) |
| 364 | { | 364 | { |
| 365 | Target *pNewTarget = NULL; | 365 | Target *pNewTarget = NULL; |
| 366 | for( RuleHash::iterator i = hRule.begin(); i; i++ ) | 366 | for( RuleHash::iterator i = hRule.begin(); i; i++ ) |
| 367 | { | 367 | { |
| 368 | if( (*i)->hasOutputs() && (*i)->ruleMatches( r, sInput ) ) | 368 | if( (*i)->hasOutputs() && (*i)->ruleMatches( r, sInput ) ) |
| 369 | { | 369 | { |
| 370 | pNewTarget = (*i)->createTarget( r, sInput, pTarget ); | 370 | pNewTarget = (*i)->createTarget( r, sInput, pTarget ); |
| 371 | 371 | ||
| 372 | Bu::Hash<ptrdiff_t, bool> hDone; | 372 | Bu::Hash<ptrdiff_t, bool> hDone; |
| 373 | for( StrList::const_iterator oi = | 373 | for( StrList::const_iterator oi = |
| 374 | pNewTarget->getOutputList().begin(); oi; oi++ ) | 374 | pNewTarget->getOutputList().begin(); oi; oi++ ) |
| 375 | { | 375 | { |
| 376 | try | 376 | try |
| 377 | { | 377 | { |
| 378 | Target *pOver = hTarget.get( *oi ); | 378 | Target *pOver = hTarget.get( *oi ); |
| 379 | if( hDone.has( (ptrdiff_t)pOver ) ) | 379 | if( hDone.has( (ptrdiff_t)pOver ) ) |
| 380 | continue; | 380 | continue; |
| 381 | hDone.insert( (ptrdiff_t)pOver, true ); | 381 | hDone.insert( (ptrdiff_t)pOver, true ); |
| 382 | if( !pOver->isExplicit() ) | 382 | if( !pOver->isExplicit() ) |
| 383 | { | 383 | { |
| 384 | delete pNewTarget; | 384 | delete pNewTarget; |
| 385 | pNewTarget = pOver; | 385 | pNewTarget = pOver; |
| 386 | break; | 386 | break; |
| 387 | } | 387 | } |
| 388 | pOver->mergeUnder( pNewTarget ); | 388 | pOver->mergeUnder( pNewTarget ); |
| 389 | delete pNewTarget; | 389 | delete pNewTarget; |
| 390 | // sio << "Delete: " << Fmt::ptr() << (ptrdiff_t)pNewTarget << sio.nl; | 390 | // sio << "Delete: " << Fmt::ptr() << (ptrdiff_t)pNewTarget << sio.nl; |
| 391 | pNewTarget = pOver; | 391 | pNewTarget = pOver; |
| 392 | break; | 392 | break; |
| 393 | } | 393 | } |
| 394 | catch(...) | 394 | catch(...) |
| 395 | { | 395 | { |
| 396 | } | 396 | } |
| 397 | } | 397 | } |
| 398 | 398 | ||
| 399 | // We actually want to add this either way, if the merge added new | 399 | // We actually want to add this either way, if the merge added new |
| 400 | // outputs, then we need to take them into account. | 400 | // outputs, then we need to take them into account. |
| 401 | addTarget( pNewTarget ); | 401 | addTarget( pNewTarget ); |
| 402 | addTargetToTags( pNewTarget, (*i)->getTagList() ); | 402 | addTargetToTags( pNewTarget, (*i)->getTagList() ); |
| 403 | 403 | ||
| 404 | // We have created a new target (or not, either way, we need to | 404 | // We have created a new target (or not, either way, we need to |
| 405 | // check if it matches.) | 405 | // check if it matches.) |
| 406 | for( StrList::const_iterator m = | 406 | for( StrList::const_iterator m = |
| 407 | pNewTarget->getOutputList().begin(); m; m++ ) | 407 | pNewTarget->getOutputList().begin(); m; m++ ) |
| 408 | { | 408 | { |
| 409 | // Does the new output match the master rule? | 409 | // Does the new output match the master rule? |
| 410 | if( pMaster->ruleMatches( r, (*m) ) ) | 410 | if( pMaster->ruleMatches( r, (*m) ) ) |
| 411 | { | 411 | { |
| 412 | lNewIns.append( (*m) ); | 412 | lNewIns.append( (*m) ); |
| 413 | 413 | ||
| 414 | // sio << "What?" << sio.nl; | 414 | // sio << "What?" << sio.nl; |
| 415 | // These relationships are difficult to pick up on except | 415 | // These relationships are difficult to pick up on except |
| 416 | // that one target was created by the other, I suppose. | 416 | // that one target was created by the other, I suppose. |
| 417 | // Anyway, that means that we need to add this while we | 417 | // Anyway, that means that we need to add this while we |
| 418 | // can. | 418 | // can. |
| 419 | // pTarget->addDep( pNewTarget ); | 419 | // pTarget->addDep( pNewTarget ); |
| 420 | } | 420 | } |
| 421 | // else | 421 | // else |
| 422 | // { | 422 | // { |
| 423 | buildTargetTree( r, pNewTarget, *m, pMaster, lNewIns ); | 423 | buildTargetTree( r, pNewTarget, *m, pMaster, lNewIns ); |
| 424 | // } | 424 | // } |
| 425 | } | 425 | } |
| 426 | 426 | ||
| 427 | return; | 427 | return; |
| 428 | } | 428 | } |
| 429 | } | 429 | } |
| 430 | if( !pNewTarget ) | 430 | if( !pNewTarget ) |
| 431 | { | 431 | { |
| 432 | //sio << "Incomplete tree created, trying to find purpose for \"" | 432 | //sio << "Incomplete tree created, trying to find purpose for \"" |
| 433 | // << sInput << "\"." << sio.nl; | 433 | // << sInput << "\"." << sio.nl; |
| 434 | return; | 434 | return; |
| 435 | } | 435 | } |
| 436 | } | 436 | } |
| 437 | 437 | ||
| 438 | void Context::attachDefaults() | 438 | void Context::attachDefaults() |
| 439 | { | 439 | { |
| 440 | for( TargetHash::iterator i = hTarget.begin(); i; i++ ) | 440 | for( TargetHash::iterator i = hTarget.begin(); i; i++ ) |
| 441 | { | 441 | { |
| 442 | if( !(*i)->hasProfile("clean") ) | 442 | if( !(*i)->hasProfile("clean") ) |
| 443 | { | 443 | { |
| 444 | (*i)->addProfile( Profile::genDefaultClean() ); | 444 | (*i)->addProfile( Profile::genDefaultClean() ); |
| 445 | } | 445 | } |
| 446 | } | 446 | } |
| 447 | } | 447 | } |
| 448 | 448 | ||
| 449 | void Context::genDefaultActions() | 449 | void Context::genDefaultActions() |
| 450 | { | 450 | { |
| 451 | if( !hAction.has("all") ) | 451 | if( !hAction.has("all") ) |
| 452 | { | 452 | { |
| 453 | addAction( Action::genDefaultAll() ); | 453 | addAction( Action::genDefaultAll() ); |
| 454 | } | 454 | } |
| 455 | if( !hAction.has("clean") ) | 455 | if( !hAction.has("clean") ) |
| 456 | { | 456 | { |
| 457 | addAction( Action::genDefaultClean() ); | 457 | addAction( Action::genDefaultClean() ); |
| 458 | } | 458 | } |
| 459 | if( !hAction.has("clean-all") ) | 459 | if( !hAction.has("clean-all") ) |
| 460 | { | 460 | { |
| 461 | addAction( Action::genDefaultCleanAll() ); | 461 | addAction( Action::genDefaultCleanAll() ); |
| 462 | } | 462 | } |
| 463 | if( !hAction.has("default") ) | 463 | if( !hAction.has("default") ) |
| 464 | { | 464 | { |
| 465 | addAction( Action::genDefaultDefault() ); | 465 | addAction( Action::genDefaultDefault() ); |
| 466 | } | 466 | } |
| 467 | } | 467 | } |
| 468 | 468 | ||
| 469 | void Context::writeTargetDot() | 469 | void Context::writeTargetDot() |
| 470 | { | 470 | { |
| 471 | Bu::Hash<ptrdiff_t, bool> hDone; | 471 | Bu::Hash<ptrdiff_t, bool> hDone; |
| 472 | sio << "digraph {" << sio.nl | 472 | sio << "digraph {" << sio.nl |
| 473 | << "\trankdir=LR;" << sio.nl; | 473 | << "\trankdir=LR;" << sio.nl; |
| 474 | for( TargetHash::iterator i = hTarget.begin(); i; i++ ) | 474 | for( TargetHash::iterator i = hTarget.begin(); i; i++ ) |
| 475 | { | 475 | { |
| 476 | if( hDone.has( (ptrdiff_t)*i ) ) | 476 | if( hDone.has( (ptrdiff_t)*i ) ) |
| 477 | continue; | 477 | continue; |
| 478 | hDone.insert( (ptrdiff_t)*i, true ); | 478 | hDone.insert( (ptrdiff_t)*i, true ); |
| 479 | for( StrList::const_iterator l = (*i)->getOutputList().begin(); | 479 | for( StrList::const_iterator l = (*i)->getOutputList().begin(); |
| 480 | l; l++ ) | 480 | l; l++ ) |
| 481 | { | 481 | { |
| 482 | for( StrList::const_iterator k = (*i)->getInputList().begin(); | 482 | for( StrList::const_iterator k = (*i)->getInputList().begin(); |
| 483 | k; k++ ) | 483 | k; k++ ) |
| 484 | { | 484 | { |
| 485 | sio << "\t\"" << *k << "\" -> \"" | 485 | sio << "\t\"" << *k << "\" -> \"" |
| 486 | << *l << "\";" << sio.nl; | 486 | << *l << "\";" << sio.nl; |
| 487 | } | 487 | } |
| 488 | for( StrList::const_iterator k = (*i)->getRequiresList().begin(); | 488 | for( StrList::const_iterator k = (*i)->getRequiresList().begin(); |
| 489 | k; k++ ) | 489 | k; k++ ) |
| 490 | { | 490 | { |
| 491 | sio << "\t\"" << *k << "\" -> \"" | 491 | sio << "\t\"" << *k << "\" -> \"" |
| 492 | << *l << "\" [color=red];" << sio.nl; | 492 | << *l << "\" [color=red];" << sio.nl; |
| 493 | } | 493 | } |
| 494 | } | 494 | } |
| 495 | 495 | ||
| 496 | } | 496 | } |
| 497 | sio << "}" << sio.nl; | 497 | sio << "}" << sio.nl; |
| 498 | } | 498 | } |
| 499 | 499 | ||
| 500 | void Context::setView( View *pNewView ) | 500 | void Context::setView( View *pNewView ) |
| 501 | { | 501 | { |
| 502 | delete pView; | 502 | delete pView; |
| 503 | pView = pNewView; | 503 | pView = pNewView; |
| 504 | } | 504 | } |
| 505 | 505 | ||
| 506 | View *Context::getView() | 506 | View *Context::getView() |
| 507 | { | 507 | { |
| 508 | return pView; | 508 | return pView; |
| 509 | } | 509 | } |
| 510 | 510 | ||
| 511 | Bu::Formatter &operator<<( Bu::Formatter &f, const Context &c ) | 511 | Bu::Formatter &operator<<( Bu::Formatter &f, const Context &c ) |
| 512 | { | 512 | { |
| 513 | f << "Variables: " << c.sVars << f.nl; | 513 | f << "Variables: " << c.sVars << f.nl; |
| 514 | f << "Targets: " << c.hTarget << f.nl; | 514 | f << "Targets: " << c.hTarget << f.nl; |
| 515 | f << "Rules: " << c.hRule << f.nl; | 515 | f << "Rules: " << c.hRule << f.nl; |
| 516 | 516 | ||
| 517 | return f; | 517 | return f; |
| 518 | } | 518 | } |
| 519 | 519 | ||
| 520 | void Context::printBasicInfo() | 520 | void Context::printBasicInfo() |
| 521 | { | 521 | { |
| 522 | sio << "Available actions:" << sio.nl << "\t"; | 522 | sio << "Available actions:" << sio.nl << "\t"; |
| 523 | for( ActionHash::iterator i = hAction.begin(); i; i++ ) | 523 | for( ActionHash::iterator i = hAction.begin(); i; i++ ) |
| 524 | { | 524 | { |
| 525 | if( i != hAction.begin() ) | 525 | if( i != hAction.begin() ) |
| 526 | sio << ", "; | 526 | sio << ", "; |
| 527 | sio << i.getKey(); | 527 | sio << i.getKey(); |
| 528 | } | 528 | } |
| 529 | 529 | ||
| 530 | TargetList lTargets = getExplicitTargets(); | 530 | TargetList lTargets = getExplicitTargets(); |
| 531 | sio << sio.nl << sio.nl << "Available targets:" << sio.nl << "\t"; | 531 | sio << sio.nl << sio.nl << "Available targets:" << sio.nl << "\t"; |
| 532 | for( TargetList::iterator i = lTargets.begin(); i; i++ ) | 532 | for( TargetList::iterator i = lTargets.begin(); i; i++ ) |
| 533 | { | 533 | { |
| 534 | if( i != lTargets.begin() ) | 534 | if( i != lTargets.begin() ) |
| 535 | sio << ", "; | 535 | sio << ", "; |
| 536 | for( StrList::const_iterator j = (*i)->getOutputList().begin(); j; j++ ) | 536 | for( StrList::const_iterator j = (*i)->getOutputList().begin(); j; j++ ) |
| 537 | { | 537 | { |
| 538 | if( j != (*i)->getOutputList().begin() ) | 538 | if( j != (*i)->getOutputList().begin() ) |
| 539 | sio << ", "; | 539 | sio << ", "; |
| 540 | sio << (*j); | 540 | sio << (*j); |
| 541 | } | 541 | } |
| 542 | } | 542 | } |
| 543 | 543 | ||
| 544 | sio << sio.nl << sio.nl; | 544 | sio << sio.nl << sio.nl; |
| 545 | } | 545 | } |
| 546 | 546 | ||
