summaryrefslogtreecommitdiffabout
path: root/lib
authorMichael Krelin <hacker@klever.net>2005-03-31 12:39:41 (UTC)
committer Michael Krelin <hacker@klever.net>2005-03-31 12:39:41 (UTC)
commit9c755a29c43bcf4a3a1bbd55ae7e590fc6ff2e21 (patch) (unidiff)
tree63c9962ece5d759d3a752b3bf338786b8a6d0993 /lib
parent5c757590c7561f6d85b3f9011aa0695c4111b379 (diff)
downloadsitecing-9c755a29c43bcf4a3a1bbd55ae7e590fc6ff2e21.zip
sitecing-9c755a29c43bcf4a3a1bbd55ae7e590fc6ff2e21.tar.gz
sitecing-9c755a29c43bcf4a3a1bbd55ae7e590fc6ff2e21.tar.bz2
saving ticks on dependencies processing
Diffstat (limited to 'lib') (more/less context) (show whitespace changes)
-rw-r--r--lib/component_factory.cc96
1 files changed, 43 insertions, 53 deletions
diff --git a/lib/component_factory.cc b/lib/component_factory.cc
index 1253111..a5ced6b 100644
--- a/lib/component_factory.cc
+++ b/lib/component_factory.cc
@@ -36,8 +36,7 @@ namespace sitecing {
36 try { // XXX: or just compare it off? 36 try { // XXX: or just compare it off?
37 string noro = strip_prefix(dp,root_source); 37 string noro = strip_prefix(dp,root_source);
38 return; 38 return;
39 }catch(utility_no_affix& una) { 39 }catch(utility_no_affix& una) { }
40 }
41 // .so binaries 40 // .so binaries
42 try { 41 try {
43 string noso = strip_suffix(dp,".so"); 42 string noso = strip_suffix(dp,".so");
@@ -51,15 +50,15 @@ namespace sitecing {
51 return; 50 return;
52 }catch(utility_no_prefix& unp) { 51 }catch(utility_no_prefix& unp) {
53 throw konforka::exception(CODEPOINT,"component is outside of component root"); 52 throw konforka::exception(CODEPOINT,"component is outside of component root");
54 }catch(utility_no_suffix& uns) { 53 }catch(utility_no_suffix& uns) { }
55 } 54 try {
56 // preprocessor targets 55 // preprocessor targets
56 string noro = strip_prefix(dp,root_intermediate);
57 for(int ppt=0;ppt<sizeof(pp_targets)/sizeof(*pp_targets);ppt++) { 57 for(int ppt=0;ppt<sizeof(pp_targets)/sizeof(*pp_targets);ppt++) {
58 try { 58 try {
59 string nos = strip_suffix(dp,pp_targets[ppt]); 59 string nos = strip_suffix(noro,pp_targets[ppt]);
60 string noro = strip_prefix(nos,root_intermediate); 60 deps.push_back(root_source+nos); // depends on the source
61 deps.push_back(root_source+noro); 61 ifstream imports((root_intermediate+nos+".imports").c_str(),ios::in);
62 ifstream imports((root_intermediate+noro+".imports").c_str(),ios::in);
63 if(imports.good()) { 62 if(imports.good()) {
64 string str; 63 string str;
65 while(!imports.eof()) { 64 while(!imports.eof()) {
@@ -68,7 +67,7 @@ namespace sitecing {
68 deps.push_back(root_intermediate+str+".classname"); 67 deps.push_back(root_intermediate+str+".classname");
69 } 68 }
70 } 69 }
71 ifstream ancestors((root_intermediate+noro+".ancestors").c_str(),ios::in); 70 ifstream ancestors((root_intermediate+nos+".ancestors").c_str(),ios::in);
72 if(ancestors.good()) { 71 if(ancestors.good()) {
73 string str; 72 string str;
74 while(!ancestors.eof()) { 73 while(!ancestors.eof()) {
@@ -77,22 +76,19 @@ namespace sitecing {
77 deps.push_back(root_intermediate+str+".classname"); 76 deps.push_back(root_intermediate+str+".classname");
78 } 77 }
79 } 78 }
80 config_options *co_intermediate_deps = config.lookup_config(noro,config_options::flag_intermediate_deps); 79 config_options *co_intermediate_deps = config.lookup_config(nos,config_options::flag_intermediate_deps);
81 if(co_intermediate_deps) { 80 if(co_intermediate_deps) {
82 for(list<string>::const_iterator i=co_intermediate_deps->intermediate_deps.begin();i!=co_intermediate_deps->intermediate_deps.end();++i) 81 for(list<string>::const_iterator i=co_intermediate_deps->intermediate_deps.begin();i!=co_intermediate_deps->intermediate_deps.end();++i)
83 deps.push_back(*i); 82 deps.push_back(*i);
84 } 83 }
85 return; 84 return;
86 }catch(utility_no_affix& una) { 85 }catch(utility_no_suffix& uns) { }
87 // do nothing. must be a cpp dependency.
88 }
89 } 86 }
90 // compiler targets 87 // compiler targets
91 for(int cct=0;cct<sizeof(cc_targets)/sizeof(*cc_targets);cct++) { 88 for(int cct=0;cct<sizeof(cc_targets)/sizeof(*cc_targets);cct++) {
92 try { 89 try {
93 string nos = strip_suffix(dp,cc_targets[cct]); 90 string nos = strip_suffix(noro,cc_targets[cct]);
94 string noro = strip_prefix(nos,root_intermediate); 91 deps.push_back(root_intermediate+nos+".cc");
95 deps.push_back(root_intermediate+noro+".cc");
96 config_options *co_cpp_deps = config.lookup_config(noro,config_options::flag_cpp_deps); 92 config_options *co_cpp_deps = config.lookup_config(noro,config_options::flag_cpp_deps);
97 if( (!co_cpp_deps) || co_cpp_deps->cpp_deps) { 93 if( (!co_cpp_deps) || co_cpp_deps->cpp_deps) {
98 ifstream df((root_intermediate+noro+".d").c_str(),ios::in); 94 ifstream df((root_intermediate+noro+".d").c_str(),ios::in);
@@ -101,15 +97,14 @@ namespace sitecing {
101 while(!df.eof()) { 97 while(!df.eof()) {
102 df >> str; 98 df >> str;
103 if(str.find_first_of("\\:")==string::npos) 99 if(str.find_first_of("\\:")==string::npos)
104 deps.push_back(combine_path(config.root_source+noro,str)); 100 deps.push_back(combine_path(config.root_source+nos,str));
105 } 101 }
106 } 102 }
107 } 103 }
108 // XXX: extra deps like IntermediateDeps? 104 // XXX: extra deps like IntermediateDeps?
109 }catch(utility_no_affix& una) { 105 }catch(utility_no_suffix& uns) { }
110 // do nothing.
111 }
112 } 106 }
107 }catch(utility_no_prefix& unp) { }
113 } 108 }
114 109
115 bool component_factory::is_uptodate(const string& dst,file_list_t *deps) { 110 bool component_factory::is_uptodate(const string& dst,file_list_t *deps) {
@@ -140,8 +135,7 @@ namespace sitecing {
140 string noro = strip_prefix(dp,root_source); 135 string noro = strip_prefix(dp,root_source);
141 // building the sources is left up to developer 136 // building the sources is left up to developer
142 return; 137 return;
143 }catch(utility_no_prefix& unp) { 138 }catch(utility_no_prefix& unp) { }
144 }
145 // .so files 139 // .so files
146 try { 140 try {
147 string noso = strip_suffix(dp,".so"); 141 string noso = strip_suffix(dp,".so");
@@ -183,89 +177,85 @@ namespace sitecing {
183 return; 177 return;
184 }catch(utility_no_prefix& unp) { 178 }catch(utility_no_prefix& unp) {
185 throw konforka::exception(CODEPOINT,"component is outside of component root"); 179 throw konforka::exception(CODEPOINT,"component is outside of component root");
186 }catch(utility_no_suffix& uns) { 180 }catch(utility_no_suffix& uns) { }
187 } 181 try {
182 string noro = strip_prefix(dp,root_intermediate);
188 // compiler targets 183 // compiler targets
189 for(int cct=0;cct<sizeof(cc_targets)/sizeof(*cc_targets);cct++) { 184 for(int cct=0;cct<sizeof(cc_targets)/sizeof(*cc_targets);cct++) {
190 try { 185 try {
191 string nos = strip_suffix(dp,cc_targets[cct]); 186 string nos = strip_suffix(noro,cc_targets[cct]);
192 string noro = strip_prefix(nos,root_intermediate); 187 string cc = root_intermediate+nos+".cc";
193 string cc = root_intermediate+noro+".cc"; 188 string o = root_intermediate+nos+".o";
194 string o = root_intermediate+noro+".o";
195 if(access(cc.c_str(),R_OK)) 189 if(access(cc.c_str(),R_OK))
196 throw konforka::exception(CODEPOINT,string("can't access preprocessed component code (")+cc+")"); 190 throw konforka::exception(CODEPOINT,string("can't access preprocessed component code (")+cc+")");
197 make_path(dir_name(cc),0755); 191 make_path(dir_name(cc),0755);
198 string pwd = dir_name(root_source+noro); 192 string pwd = dir_name(root_source+nos);
199 auto_chdir dir_changer(pwd); 193 auto_chdir dir_changer(pwd);
200 file_lock lock_source(root_intermediate+noro+".lock"); 194 file_lock lock_source(root_intermediate+nos+".lock");
201 file_lock lock_cc(root_intermediate+noro+".o.lock"); 195 file_lock lock_cc(root_intermediate+nos+".o.lock");
202 int stdO = open((root_intermediate+noro+".stdout").c_str(),O_CREAT|O_TRUNC|O_WRONLY,0664); 196 int stdO = open((root_intermediate+nos+".stdout").c_str(),O_CREAT|O_TRUNC|O_WRONLY,0664);
203 if(stdO<0) 197 if(stdO<0)
204 throw konforka::exception(CODEPOINT,"failed to open/create compiler stdout"); 198 throw konforka::exception(CODEPOINT,"failed to open/create compiler stdout");
205 int stdE = open((root_intermediate+noro+".stderr").c_str(),O_CREAT|O_TRUNC|O_WRONLY,0664); 199 int stdE = open((root_intermediate+nos+".stderr").c_str(),O_CREAT|O_TRUNC|O_WRONLY,0664);
206 if(stdE<0) { 200 if(stdE<0) {
207 close(stdO); 201 close(stdO);
208 throw konforka::exception(CODEPOINT,"failed to open/create compiler's stderr"); 202 throw konforka::exception(CODEPOINT,"failed to open/create compiler's stderr");
209 } 203 }
210 list<string> args; 204 list<string> args;
211 config_options *co_cpp_flags = config.lookup_config(noro,config_options::flag_cpp_flags); 205 config_options *co_cpp_flags = config.lookup_config(nos,config_options::flag_cpp_flags);
212 if(co_cpp_flags) { 206 if(co_cpp_flags) {
213 args.insert(args.end(),co_cpp_flags->cpp_flags.begin(),co_cpp_flags->cpp_flags.end()); 207 args.insert(args.end(),co_cpp_flags->cpp_flags.begin(),co_cpp_flags->cpp_flags.end());
214 } 208 }
215 // TODO: maybe move it to separare config option like CoreCPPFLags? 209 // TODO: maybe move it to separare config option like CoreCPPFLags?
216 args.push_back("-I"+root_intermediate); 210 args.push_back("-I"+root_intermediate);
217 args.push_back("-I"+root_source); 211 args.push_back("-I"+root_source);
218 args.push_back("-MD"); args.push_back("-MF"); args.push_back(root_intermediate+noro+".d"); 212 args.push_back("-MD"); args.push_back("-MF"); args.push_back(root_intermediate+nos+".d");
219 args.push_back("-c"); 213 args.push_back("-c");
220 args.push_back(cc); 214 args.push_back(cc);
221 args.push_back("-o"); args.push_back(o); 215 args.push_back("-o"); args.push_back(o);
222 // TODO: "g++" configurable 216 // TODO: "g++" configurable
223 int rv = execute("g++",args,stdO,stdE); 217 int rv = execute("g++",args,stdO,stdE);
224 if(! (WIFEXITED(rv) && !WEXITSTATUS(rv)) ) 218 if(! (WIFEXITED(rv) && !WEXITSTATUS(rv)) )
225 throw compile_error(CODEPOINT,"failed to compile component",noro); 219 throw compile_error(CODEPOINT,"failed to compile component",nos);
226 return; 220 return;
227 }catch(utility_no_affix& una) { 221 }catch(utility_no_suffix& uns) { }
228 // do nothing, not a compiler target
229 }
230 } 222 }
231 // preprocessor targets 223 // preprocessor targets
232 for(int ppt=0;ppt<sizeof(pp_targets)/sizeof(*pp_targets);ppt++) { 224 for(int ppt=0;ppt<sizeof(pp_targets)/sizeof(*pp_targets);ppt++) {
233 try { 225 try {
234 string nos = strip_suffix(dp,pp_targets[ppt]); 226 string nos = strip_suffix(noro,pp_targets[ppt]);
235 string noro = strip_prefix(nos,root_intermediate); 227 string src = root_source+nos;
236 string src = root_source+noro;
237 if(access(src.c_str(),R_OK)) 228 if(access(src.c_str(),R_OK))
238 throw konforka::exception(CODEPOINT,string("can't access component source (")+src+")"); 229 throw konforka::exception(CODEPOINT,string("can't access component source (")+src+")");
239 make_path(dir_name(root_intermediate+noro),0755); 230 make_path(dir_name(root_intermediate+nos),0755);
240 file_lock lock(root_intermediate+noro+".lock"); 231 file_lock lock(root_intermediate+nos+".lock");
241 sitecing_parser parser(*this); 232 sitecing_parser parser(*this);
242 config_options *co_skeleton = config.lookup_config(noro,config_options::flag_skeleton); 233 config_options *co_skeleton = config.lookup_config(nos,config_options::flag_skeleton);
243 if(co_skeleton) 234 if(co_skeleton)
244 parser.skeleton = co_skeleton->skeleton; 235 parser.skeleton = co_skeleton->skeleton;
245 static const char *id_chars = "abcdefghijklmnopqrstuvwxyz0123456789_ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 236 static const char *id_chars = "abcdefghijklmnopqrstuvwxyz0123456789_ABCDEFGHIJKLMNOPQRSTUVWXYZ";
246 parser.class_name = normalize_path(noro,strip_leading_slash|strip_trailing_slash); 237 parser.class_name = normalize_path(nos,strip_leading_slash|strip_trailing_slash);
247 for(string::size_type illc = parser.class_name.find_first_not_of(id_chars);illc!=string::npos;illc=parser.class_name.find_first_not_of(id_chars,illc)) { 238 for(string::size_type illc = parser.class_name.find_first_not_of(id_chars);illc!=string::npos;illc=parser.class_name.find_first_not_of(id_chars,illc)) {
248 string::size_type lc = parser.class_name.find_first_of(id_chars,illc); 239 string::size_type lc = parser.class_name.find_first_of(id_chars,illc);
249 int n = ((lc==string::npos)?parser.class_name.length():lc)-illc; 240 int n = ((lc==string::npos)?parser.class_name.length():lc)-illc;
250 parser.class_name.replace(illc,n,n,'_'); 241 parser.class_name.replace(illc,n,n,'_');
251 } 242 }
252 parser.class_name = "_SCC_"+parser.class_name; 243 parser.class_name = "_SCC_"+parser.class_name;
253 parser.output_basename = nos; 244 parser.output_basename = root_intermediate+nos;
254 parser.component_basename = noro; 245 parser.component_basename = nos;
255 try { 246 try {
256 parser.preprocess(src); 247 parser.preprocess(src);
257 string sf = root_intermediate+noro+".pp_stamp"; 248 string sf = root_intermediate+nos+".pp_stamp";
258 ofstream sfs(sf.c_str(),ios::trunc|ios::out); // touch .pp_stamp 249 ofstream sfs(sf.c_str(),ios::trunc|ios::out); // touch .pp_stamp
259 }catch(preprocessor_error& pe) { 250 }catch(preprocessor_error& pe) {
260 pe.component_name = noro; 251 pe.component_name = nos;
261 pe.see(CODEPOINT); 252 pe.see(CODEPOINT);
262 throw; 253 throw;
263 } 254 }
264 return; 255 return;
265 }catch(utility_no_affix& una) { 256 }catch(utility_no_suffix& uns) { }
266 // must be a crap from .d file
267 }
268 } 257 }
258 }catch(utility_no_prefix& unp) { }
269 cerr << "ignoring build request for " << dp << endl; 259 cerr << "ignoring build request for " << dp << endl;
270 } 260 }
271 261