aboutsummaryrefslogtreecommitdiff
path: root/src/rule.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2006-08-01 03:09:58 +0000
committerMike Buland <eichlan@xagasoft.com>2006-08-01 03:09:58 +0000
commit935bc7d5223883d87f58a6798f4a0ade7df95afc (patch)
tree83119cd6b407c6e17c21774f1f0cea940d9c948c /src/rule.cpp
parent73d53b0962cb19a6d2a7686de658a5540ab07017 (diff)
downloadbuild-935bc7d5223883d87f58a6798f4a0ade7df95afc.tar.gz
build-935bc7d5223883d87f58a6798f4a0ade7df95afc.tar.bz2
build-935bc7d5223883d87f58a6798f4a0ade7df95afc.tar.xz
build-935bc7d5223883d87f58a6798f4a0ade7df95afc.zip
It actually builds, now it just needs dependancy tracking, and maybe auto-target
check triggering.
Diffstat (limited to 'src/rule.cpp')
-rw-r--r--src/rule.cpp103
1 files changed, 51 insertions, 52 deletions
diff --git a/src/rule.cpp b/src/rule.cpp
index 4425ea5..979075b 100644
--- a/src/rule.cpp
+++ b/src/rule.cpp
@@ -67,20 +67,48 @@ void Rule::setPerforms( ePerform pwhat, const char *sperfcmd )
67 sPerfCmd = sperfcmd; 67 sPerfCmd = sperfcmd;
68} 68}
69 69
70Perform *Rule::buildCommand( Builder &bld, const char *sCmd, const char *sTarget, const char *sMatches ) 70Perform *Rule::buildCommand( Builder &bld, const char *sCmd, Builder::varmap *vars )
71{ 71{
72 Builder::varmap vars; 72 return new PerformCmd(
73 vars["target"] = sTarget; 73 bld.varRepl( sCmd, (*vars)["target"].c_str(), vars ).c_str(),
74 vars["match"] = sMatches; 74 (*vars)["target"].c_str()
75 return new PerformCmd( bld.varRepl( sCmd, "", &vars ).c_str(), sTarget ); 75 );
76} 76}
77 77
78std::list<std::string> Rule::findTargets( Builder &bld, std::list<std::string> &lIn, std::string &sMatches, const char *sTarget ) 78std::list<std::string> Rule::execute( Builder &bld, std::list<std::string> lInput, std::list<Perform *> &lPerf, const char *sTarget )
79{ 79{
80 std::list<std::string> lTmp; 80 std::list<Rule *> lRule = bld.findRuleChain( this );
81 /*
82 if( !lRule.empty() )
83 {
84 printf("Rule %s chains to: ", sName.getString() );
85 for( std::list<Rule *>::iterator i = lRule.begin();
86 i != lRule.end(); i++ )
87 {
88 if( i != lRule.begin() )
89 printf(", ");
90 printf("%s", (*i)->sName.getString() );
91 }
92 printf("\n");
93 }*/
81 94
82 for( std::list<std::string>::iterator i = lIn.begin(); 95 std::list<std::string> lOutput;
83 i != lIn.end(); i++ ) 96 std::string sMatches;
97
98 for( std::list<Rule *>::iterator i = lRule.begin(); i != lRule.end(); i++ )
99 {
100 std::list<std::string> lTmp = (*i)->execute( bld, lInput, lPerf );
101 lOutput.insert( lOutput.end(), lTmp.begin(), lTmp.end() );
102 }
103
104 std::list<std::string> lTest;
105 lTest.insert( lTest.end(), lInput.begin(), lInput.end() );
106 lTest.insert( lTest.end(), lOutput.begin(), lOutput.end() );
107
108 cleanList( lTest );
109
110 for( std::list<std::string>::iterator i = lTest.begin();
111 i != lTest.end(); i++ )
84 { 112 {
85 if( rWhat.execute( (*i).c_str() ) ) 113 if( rWhat.execute( (*i).c_str() ) )
86 { 114 {
@@ -90,21 +118,22 @@ std::list<std::string> Rule::findTargets( Builder &bld, std::list<std::string> &
90 { 118 {
91 if( mHow == matchOne ) 119 if( mHow == matchOne )
92 { 120 {
93 lTmp.push_back( 121 lOutput.push_back(
94 bld.varRepl( 122 bld.varRepl(
95 (*j).c_str(), 123 (*j).c_str(),
96 "", 124 "",
97 revars 125 revars
98 ) 126 )
99 ); 127 );
128 (*revars)["target"] = (sTarget==NULL)?
129 (lOutput.back().c_str()):(sTarget);
130 (*revars)["match"] = (*i).c_str();
100 Perform *p = buildCommand( 131 Perform *p = buildCommand(
101 bld, 132 bld,
102 sPerfCmd, 133 sPerfCmd,
103 (sTarget==NULL)?(lTmp.back().c_str()):(sTarget), 134 revars
104 (*i).c_str()
105 ); 135 );
106 p->execute( bld ); 136 lPerf.push_back( p );
107 delete p;
108 } 137 }
109 else if( mHow == matchAll ) 138 else if( mHow == matchAll )
110 { 139 {
@@ -115,57 +144,27 @@ std::list<std::string> Rule::findTargets( Builder &bld, std::list<std::string> &
115 delete revars; 144 delete revars;
116 } 145 }
117 } 146 }
118 147 //std::list<std::string> lTmp = findTargets( bld, lTest, sMatches, sTarget );
119 return lTmp; 148 //lOutput.insert( lOutput.end(), lTmp.begin(), lTmp.end() );
120}
121
122std::list<std::string> Rule::execute( Builder &bld, std::list<std::string> lInput, const char *sTarget )
123{
124 std::list<Rule *> lRule = bld.findRuleChain( this );
125
126 if( !lRule.empty() )
127 {
128 printf("Rule %s chains to: ", sName.getString() );
129 for( std::list<Rule *>::iterator i = lRule.begin();
130 i != lRule.end(); i++ )
131 {
132 if( i != lRule.begin() )
133 printf(", ");
134 printf("%s", (*i)->sName.getString() );
135 }
136 printf("\n");
137 }
138
139 std::list<std::string> lOutput;
140 std::string sMatches;
141
142 for( std::list<Rule *>::iterator i = lRule.begin(); i != lRule.end(); i++ )
143 {
144 std::list<std::string> lTmp = (*i)->execute( bld, lInput );
145 lOutput.insert( lOutput.end(), lTmp.begin(), lTmp.end() );
146 }
147
148 std::list<std::string> lTmp = findTargets( bld, lInput, sMatches, sTarget );
149 lOutput.insert( lOutput.end(), lTmp.begin(), lTmp.end() );
150 lTmp = findTargets( bld, lOutput, sMatches, sTarget );
151 lOutput.insert( lOutput.end(), lTmp.begin(), lTmp.end() );
152 149
153 if( mHow == matchAll ) 150 if( mHow == matchAll )
154 { 151 {
155 lOutput.push_back( 152 lOutput.push_back(
156 bld.varRepl( 153 bld.varRepl(
157 sTarget, 154 sTarget,
158 "", 155 sTarget,
159 NULL 156 NULL
160 ) 157 )
161 ); 158 );
159 Builder::varmap vars;
160 vars["target"] = sTarget;
161 vars["match"] = sMatches;
162 Perform *p = buildCommand( 162 Perform *p = buildCommand(
163 bld, 163 bld,
164 sPerfCmd, 164 sPerfCmd,
165 sTarget, 165 &vars
166 sMatches.c_str()
167 ); 166 );
168 p->execute( bld ); 167 lPerf.push_back( p );
169 } 168 }
170 169
171 return lOutput; 170 return lOutput;