author | Michael Krelin <hacker@klever.net> | 2005-03-31 20:07:16 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2005-03-31 20:07:16 (UTC) |
commit | 185d182cd6d3e0593a3627837f3bb400b654e602 (patch) (unidiff) | |
tree | bf848291cf5fb161df0a028ca9f3a3095f862d0b | |
parent | c9a601eeae3457d28fb1dfd7592ce29d2b06f411 (diff) | |
download | sitecing-185d182cd6d3e0593a3627837f3bb400b654e602.zip sitecing-185d182cd6d3e0593a3627837f3bb400b654e602.tar.gz sitecing-185d182cd6d3e0593a3627837f3bb400b654e602.tar.bz2 |
Yes, I did break dependency handling a bit.
-rw-r--r-- | lib/component_factory.cc | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/component_factory.cc b/lib/component_factory.cc index 2a2eefe..5c18bb7 100644 --- a/lib/component_factory.cc +++ b/lib/component_factory.cc | |||
@@ -1,321 +1,327 @@ | |||
1 | #ifdef USE_PCH | 1 | #ifdef USE_PCH |
2 | #include "pch.h" | 2 | #include "pch.h" |
3 | #else | 3 | #else |
4 | #include <sys/types.h> | 4 | #include <sys/types.h> |
5 | #include <sys/stat.h> | 5 | #include <sys/stat.h> |
6 | #include <unistd.h> | 6 | #include <unistd.h> |
7 | #include <sys/wait.h> | 7 | #include <sys/wait.h> |
8 | #include <fcntl.h> | 8 | #include <fcntl.h> |
9 | #include <iostream> | 9 | #include <iostream> |
10 | #include <fstream> | 10 | #include <fstream> |
11 | #include <stdexcept> | 11 | #include <stdexcept> |
12 | #include <vector> | 12 | #include <vector> |
13 | using namespace std; | 13 | using namespace std; |
14 | #include "sitecing/component_factory.h" | 14 | #include "sitecing/component_factory.h" |
15 | #include "sitecing/sitecing_util.h" | 15 | #include "sitecing/sitecing_util.h" |
16 | #include "sitecing/sitecing_parser.h" | 16 | #include "sitecing/sitecing_parser.h" |
17 | #include "sitecing/sitecing_exception.h" | 17 | #include "sitecing/sitecing_exception.h" |
18 | #endif | 18 | #endif |
19 | 19 | ||
20 | namespace sitecing { | 20 | namespace sitecing { |
21 | 21 | ||
22 | static const char *pp_targets[] = { ".cc", ".h", ".imports", ".classname", ".baseclassname", ".ancestors", ".pp_stamp" }; | 22 | static const char *pp_targets[] = { ".cc", ".h", ".imports", ".classname", ".baseclassname", ".ancestors", ".pp_stamp" }; |
23 | static const char *cc_targets[] = { ".o", ".d" }; | 23 | static const char *cc_targets[] = { ".o", ".d" }; |
24 | 24 | ||
25 | component_factory::component_factory(configuration& c) | 25 | component_factory::component_factory(configuration& c) |
26 | : config(c), | 26 | : config(c), |
27 | root_source(normalize_path(c.root_source,strip_trailing_slash)+'/'), | 27 | root_source(normalize_path(c.root_source,strip_trailing_slash)+'/'), |
28 | root_intermediate(normalize_path(c.root_intermediate,strip_trailing_slash)+'/'), | 28 | root_intermediate(normalize_path(c.root_intermediate,strip_trailing_slash)+'/'), |
29 | root_so(normalize_path(c.root_so,strip_trailing_slash)+'/') { | 29 | root_so(normalize_path(c.root_so,strip_trailing_slash)+'/') { |
30 | } | 30 | } |
31 | 31 | ||
32 | void component_factory::get_dependencies(const string& dst,file_list_t& deps) { | 32 | void component_factory::get_dependencies(const string& dst,file_list_t& deps) { |
33 | deps.clear(); | 33 | deps.clear(); |
34 | string dp = normalize_path(dst,strip_trailing_slash); | 34 | string dp = normalize_path(dst,strip_trailing_slash); |
35 | // source documents | 35 | // source documents |
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 | // .so binaries | 40 | // .so binaries |
41 | try { | 41 | try { |
42 | string noso = strip_suffix(dp,".so"); | 42 | string noso = strip_suffix(dp,".so"); |
43 | string noro = strip_prefix(noso,root_so); | 43 | string noro = strip_prefix(noso,root_so); |
44 | deps.push_back(root_intermediate+noro+".o"); | 44 | deps.push_back(root_intermediate+noro+".o"); |
45 | config_options *co_so_deps = config.lookup_config(noro,config_options::flag_so_deps); | 45 | config_options *co_so_deps = config.lookup_config(noro,config_options::flag_so_deps); |
46 | if(co_so_deps) { | 46 | if(co_so_deps) { |
47 | for(list<string>::const_iterator i=co_so_deps->so_deps.begin();i!=co_so_deps->so_deps.end();++i) | 47 | for(list<string>::const_iterator i=co_so_deps->so_deps.begin();i!=co_so_deps->so_deps.end();++i) |
48 | deps.push_back(*i); | 48 | deps.push_back(*i); |
49 | } | 49 | } |
50 | return; | 50 | return; |
51 | }catch(utility_no_prefix& unp) { | 51 | }catch(utility_no_prefix& unp) { |
52 | throw konforka::exception(CODEPOINT,"component is outside of component root"); | 52 | throw konforka::exception(CODEPOINT,"component is outside of component root"); |
53 | }catch(utility_no_suffix& uns) { } | 53 | }catch(utility_no_suffix& uns) { } |
54 | try { | 54 | try { |
55 | // preprocessor targets | 55 | // preprocessor targets |
56 | string noro = strip_prefix(dp,root_intermediate); | 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(noro,pp_targets[ppt]); | 59 | string nos = strip_suffix(noro,pp_targets[ppt]); |
60 | deps.push_back(root_source+nos); // depends on the source | 60 | deps.push_back(root_source+nos); // depends on the source |
61 | ifstream imports((root_intermediate+nos+".imports").c_str(),ios::in); | 61 | ifstream imports((root_intermediate+nos+".imports").c_str(),ios::in); |
62 | if(imports.good()) { | 62 | if(imports.good()) { |
63 | string str; | 63 | string str; |
64 | while(!imports.eof()) { | 64 | while(!imports.eof()) { |
65 | imports >> str; | 65 | imports >> str; |
66 | if(!str.empty()) | 66 | if(!str.empty()) |
67 | deps.push_back(root_intermediate+str+".classname"); | 67 | deps.push_back(root_intermediate+str+".classname"); |
68 | } | 68 | } |
69 | } | 69 | } |
70 | ifstream ancestors((root_intermediate+nos+".ancestors").c_str(),ios::in); | 70 | ifstream ancestors((root_intermediate+nos+".ancestors").c_str(),ios::in); |
71 | if(ancestors.good()) { | 71 | if(ancestors.good()) { |
72 | string str; | 72 | string str; |
73 | while(!ancestors.eof()) { | 73 | while(!ancestors.eof()) { |
74 | ancestors >> str; | 74 | ancestors >> str; |
75 | if(!str.empty()) | 75 | if(!str.empty()) |
76 | deps.push_back(root_intermediate+str+".classname"); | 76 | deps.push_back(root_intermediate+str+".classname"); |
77 | } | 77 | } |
78 | } | 78 | } |
79 | // XXX: intermediate_deps should be broken down | ||
79 | config_options *co_intermediate_deps = config.lookup_config(nos,config_options::flag_intermediate_deps); | 80 | config_options *co_intermediate_deps = config.lookup_config(nos,config_options::flag_intermediate_deps); |
80 | if(co_intermediate_deps) { | 81 | if(co_intermediate_deps) { |
81 | for(list<string>::const_iterator i=co_intermediate_deps->intermediate_deps.begin();i!=co_intermediate_deps->intermediate_deps.end();++i) | 82 | for(list<string>::const_iterator i=co_intermediate_deps->intermediate_deps.begin();i!=co_intermediate_deps->intermediate_deps.end();++i) |
82 | deps.push_back(*i); | 83 | deps.push_back(*i); |
83 | } | 84 | } |
84 | return; | 85 | return; |
85 | }catch(utility_no_suffix& uns) { } | 86 | }catch(utility_no_suffix& uns) { } |
86 | } | 87 | } |
87 | // compiler targets | 88 | // compiler targets |
88 | for(int cct=0;cct<sizeof(cc_targets)/sizeof(*cc_targets);cct++) { | 89 | for(int cct=0;cct<sizeof(cc_targets)/sizeof(*cc_targets);cct++) { |
89 | try { | 90 | try { |
90 | string nos = strip_suffix(noro,cc_targets[cct]); | 91 | string nos = strip_suffix(noro,cc_targets[cct]); |
91 | deps.push_back(root_intermediate+nos+".cc"); | 92 | deps.push_back(root_intermediate+nos+".cc"); |
92 | config_options *co_cpp_deps = config.lookup_config(noro,config_options::flag_cpp_deps); | 93 | config_options *co_cpp_deps = config.lookup_config(noro,config_options::flag_cpp_deps); |
93 | if( (!co_cpp_deps) || co_cpp_deps->cpp_deps) { | 94 | if( (!co_cpp_deps) || co_cpp_deps->cpp_deps) { |
94 | ifstream df((root_intermediate+noro+".d").c_str(),ios::in); | 95 | ifstream df((root_intermediate+noro+".d").c_str(),ios::in); |
95 | if(df.good()) { | 96 | if(df.good()) { |
96 | string str; | 97 | string str; |
97 | while(!df.eof()) { | 98 | while(!df.eof()) { |
98 | df >> str; | 99 | df >> str; |
99 | if(str.find_first_of("\\:")==string::npos) | 100 | if(str.find_first_of("\\:")==string::npos) |
100 | deps.push_back(combine_path(config.root_source+nos,str)); | 101 | deps.push_back(combine_path(config.root_source+nos,str)); |
101 | } | 102 | } |
102 | } | 103 | } |
103 | } | 104 | } |
104 | // XXX: extra deps like IntermediateDeps? | 105 | // XXX: intermediate_deps should be broken down |
106 | config_options *co_intermediate_deps = config.lookup_config(nos,config_options::flag_intermediate_deps); | ||
107 | if(co_intermediate_deps) { | ||
108 | for(list<string>::const_iterator i=co_intermediate_deps->intermediate_deps.begin();i!=co_intermediate_deps->intermediate_deps.end();++i) | ||
109 | deps.push_back(*i); | ||
110 | } | ||
105 | }catch(utility_no_suffix& uns) { } | 111 | }catch(utility_no_suffix& uns) { } |
106 | } | 112 | } |
107 | }catch(utility_no_prefix& unp) { } | 113 | }catch(utility_no_prefix& unp) { } |
108 | } | 114 | } |
109 | 115 | ||
110 | bool component_factory::is_uptodate(const string& dst,file_list_t *deps) { | 116 | bool component_factory::is_uptodate(const string& dst,file_list_t *deps) { |
111 | string dp = normalize_path(dst,strip_trailing_slash); | 117 | string dp = normalize_path(dst,strip_trailing_slash); |
112 | // XXX: or just compare it off, instead of throwing things around. | 118 | // XXX: or just compare it off, instead of throwing things around. |
113 | try { | 119 | try { |
114 | string noro = strip_prefix(dp,root_intermediate); | 120 | string noro = strip_prefix(dp,root_intermediate); |
115 | for(int ppt=0;(ppt+1)<sizeof(pp_targets)/sizeof(*pp_targets);ppt++) { | 121 | for(int ppt=0;(ppt+1)<sizeof(pp_targets)/sizeof(*pp_targets);ppt++) { |
116 | try { | 122 | try { |
117 | string nos = strip_suffix(noro,pp_targets[ppt]); | 123 | string nos = strip_suffix(noro,pp_targets[ppt]); |
118 | return file_factory::is_uptodate(root_intermediate+nos+".pp_stamp",deps); | 124 | return file_factory::is_uptodate(root_intermediate+nos+".pp_stamp",deps); |
119 | }catch(utility_no_suffix& uns) { } | 125 | }catch(utility_no_suffix& uns) { } |
120 | } | 126 | } |
121 | bool rv = file_factory::is_uptodate(dst,deps); | 127 | bool rv = file_factory::is_uptodate(dst,deps); |
122 | return rv; | 128 | return rv; |
123 | }catch(utility_no_prefix& unp) { } | 129 | }catch(utility_no_prefix& unp) { } |
124 | try { | 130 | try { |
125 | strip_prefix(dp,root_so); | 131 | strip_prefix(dp,root_so); |
126 | return file_factory::is_uptodate(dst,deps); | 132 | return file_factory::is_uptodate(dst,deps); |
127 | }catch(utility_no_prefix& unp) { } | 133 | }catch(utility_no_prefix& unp) { } |
128 | return true; | 134 | return true; |
129 | } | 135 | } |
130 | 136 | ||
131 | void component_factory::build(const string& dst) { | 137 | void component_factory::build(const string& dst) { |
132 | string dp = normalize_path(dst,strip_trailing_slash); | 138 | string dp = normalize_path(dst,strip_trailing_slash); |
133 | // sources | 139 | // sources |
134 | try { | 140 | try { |
135 | string noro = strip_prefix(dp,root_source); | 141 | string noro = strip_prefix(dp,root_source); |
136 | // building the sources is left up to developer | 142 | // building the sources is left up to developer |
137 | return; | 143 | return; |
138 | }catch(utility_no_prefix& unp) { } | 144 | }catch(utility_no_prefix& unp) { } |
139 | // .so files | 145 | // .so files |
140 | try { | 146 | try { |
141 | string noso = strip_suffix(dp,".so"); | 147 | string noso = strip_suffix(dp,".so"); |
142 | string noro = strip_prefix(noso,root_so); | 148 | string noro = strip_prefix(noso,root_so); |
143 | string o = root_intermediate+noro+".o"; | 149 | string o = root_intermediate+noro+".o"; |
144 | if(access(o.c_str(),R_OK)) | 150 | if(access(o.c_str(),R_OK)) |
145 | throw konforka::exception(CODEPOINT,string("can't access compiled component code (")+o+")"); | 151 | throw konforka::exception(CODEPOINT,string("can't access compiled component code (")+o+")"); |
146 | make_path(dir_name(root_so+noro),0755); | 152 | make_path(dir_name(root_so+noro),0755); |
147 | file_lock lock_cc(root_intermediate+noro+".o.lock"); | 153 | file_lock lock_cc(root_intermediate+noro+".o.lock"); |
148 | file_lock lock_so(root_so+noro+".so.lock"); | 154 | file_lock lock_so(root_so+noro+".so.lock"); |
149 | int stdO = open((root_intermediate+noro+".ld.stdout").c_str(),O_CREAT|O_TRUNC|O_WRONLY,0664); | 155 | int stdO = open((root_intermediate+noro+".ld.stdout").c_str(),O_CREAT|O_TRUNC|O_WRONLY,0664); |
150 | if(stdO<0) | 156 | if(stdO<0) |
151 | throw konforka::exception(CODEPOINT,"failed to open/create linker stdout"); | 157 | throw konforka::exception(CODEPOINT,"failed to open/create linker stdout"); |
152 | int stdE = open((root_intermediate+noro+".ld.stderr").c_str(),O_CREAT|O_TRUNC|O_WRONLY,0664); | 158 | int stdE = open((root_intermediate+noro+".ld.stderr").c_str(),O_CREAT|O_TRUNC|O_WRONLY,0664); |
153 | if(stdE<0) { | 159 | if(stdE<0) { |
154 | close(stdO); | 160 | close(stdO); |
155 | throw konforka::exception(CODEPOINT,"failed to open/create linker stderr"); | 161 | throw konforka::exception(CODEPOINT,"failed to open/create linker stderr"); |
156 | } | 162 | } |
157 | list<string> args; | 163 | list<string> args; |
158 | config_options *co_ld_flags = config.lookup_config(noro,config_options::flag_ld_flags); | 164 | config_options *co_ld_flags = config.lookup_config(noro,config_options::flag_ld_flags); |
159 | if(co_ld_flags) { | 165 | if(co_ld_flags) { |
160 | args.insert(args.end(),co_ld_flags->ld_flags.begin(),co_ld_flags->ld_flags.end()); | 166 | args.insert(args.end(),co_ld_flags->ld_flags.begin(),co_ld_flags->ld_flags.end()); |
161 | } | 167 | } |
162 | args.push_back("-shared"); | 168 | args.push_back("-shared"); |
163 | args.push_back(o); | 169 | args.push_back(o); |
164 | file_list_t ancestors; | 170 | file_list_t ancestors; |
165 | get_ancestors(noro,ancestors); | 171 | get_ancestors(noro,ancestors); |
166 | for(file_list_t::const_iterator i=ancestors.begin();i!=ancestors.end();++i) { | 172 | for(file_list_t::const_iterator i=ancestors.begin();i!=ancestors.end();++i) { |
167 | string aso=root_so+*i+".so"; | 173 | string aso=root_so+*i+".so"; |
168 | make(aso); | 174 | make(aso); |
169 | args.push_back(aso); | 175 | args.push_back(aso); |
170 | } | 176 | } |
171 | args.push_back("-o"); args.push_back(dp); | 177 | args.push_back("-o"); args.push_back(dp); |
172 | // TODO: "g++" configurable | 178 | // TODO: "g++" configurable |
173 | int rv = execute("g++",args,stdO,stdE); | 179 | int rv = execute("g++",args,stdO,stdE); |
174 | if(! (WIFEXITED(rv) && !WEXITSTATUS(rv)) ) | 180 | if(! (WIFEXITED(rv) && !WEXITSTATUS(rv)) ) |
175 | throw link_error(CODEPOINT,"failed to link component",noro); | 181 | throw link_error(CODEPOINT,"failed to link component",noro); |
176 | return; | 182 | return; |
177 | }catch(utility_no_prefix& unp) { | 183 | }catch(utility_no_prefix& unp) { |
178 | throw konforka::exception(CODEPOINT,"component is outside of component root"); | 184 | throw konforka::exception(CODEPOINT,"component is outside of component root"); |
179 | }catch(utility_no_suffix& uns) { } | 185 | }catch(utility_no_suffix& uns) { } |
180 | try { | 186 | try { |
181 | string noro = strip_prefix(dp,root_intermediate); | 187 | string noro = strip_prefix(dp,root_intermediate); |
182 | // compiler targets | 188 | // compiler targets |
183 | for(int cct=0;cct<sizeof(cc_targets)/sizeof(*cc_targets);cct++) { | 189 | for(int cct=0;cct<sizeof(cc_targets)/sizeof(*cc_targets);cct++) { |
184 | try { | 190 | try { |
185 | string nos = strip_suffix(noro,cc_targets[cct]); | 191 | string nos = strip_suffix(noro,cc_targets[cct]); |
186 | string cc = root_intermediate+nos+".cc"; | 192 | string cc = root_intermediate+nos+".cc"; |
187 | string o = root_intermediate+nos+".o"; | 193 | string o = root_intermediate+nos+".o"; |
188 | if(access(cc.c_str(),R_OK)) | 194 | if(access(cc.c_str(),R_OK)) |
189 | throw konforka::exception(CODEPOINT,string("can't access preprocessed component code (")+cc+")"); | 195 | throw konforka::exception(CODEPOINT,string("can't access preprocessed component code (")+cc+")"); |
190 | make_path(dir_name(cc),0755); | 196 | make_path(dir_name(cc),0755); |
191 | string pwd = dir_name(root_source+nos); | 197 | string pwd = dir_name(root_source+nos); |
192 | auto_chdir dir_changer(pwd); | 198 | auto_chdir dir_changer(pwd); |
193 | file_lock lock_source(root_intermediate+nos+".lock"); | 199 | file_lock lock_source(root_intermediate+nos+".lock"); |
194 | file_lock lock_cc(root_intermediate+nos+".o.lock"); | 200 | file_lock lock_cc(root_intermediate+nos+".o.lock"); |
195 | int stdO = open((root_intermediate+nos+".stdout").c_str(),O_CREAT|O_TRUNC|O_WRONLY,0664); | 201 | int stdO = open((root_intermediate+nos+".stdout").c_str(),O_CREAT|O_TRUNC|O_WRONLY,0664); |
196 | if(stdO<0) | 202 | if(stdO<0) |
197 | throw konforka::exception(CODEPOINT,"failed to open/create compiler stdout"); | 203 | throw konforka::exception(CODEPOINT,"failed to open/create compiler stdout"); |
198 | int stdE = open((root_intermediate+nos+".stderr").c_str(),O_CREAT|O_TRUNC|O_WRONLY,0664); | 204 | int stdE = open((root_intermediate+nos+".stderr").c_str(),O_CREAT|O_TRUNC|O_WRONLY,0664); |
199 | if(stdE<0) { | 205 | if(stdE<0) { |
200 | close(stdO); | 206 | close(stdO); |
201 | throw konforka::exception(CODEPOINT,"failed to open/create compiler's stderr"); | 207 | throw konforka::exception(CODEPOINT,"failed to open/create compiler's stderr"); |
202 | } | 208 | } |
203 | list<string> args; | 209 | list<string> args; |
204 | config_options *co_cpp_flags = config.lookup_config(nos,config_options::flag_cpp_flags); | 210 | config_options *co_cpp_flags = config.lookup_config(nos,config_options::flag_cpp_flags); |
205 | if(co_cpp_flags) { | 211 | if(co_cpp_flags) { |
206 | args.insert(args.end(),co_cpp_flags->cpp_flags.begin(),co_cpp_flags->cpp_flags.end()); | 212 | args.insert(args.end(),co_cpp_flags->cpp_flags.begin(),co_cpp_flags->cpp_flags.end()); |
207 | } | 213 | } |
208 | // TODO: maybe move it to separare config option like CoreCPPFLags? | 214 | // TODO: maybe move it to separare config option like CoreCPPFLags? |
209 | args.push_back("-I"+root_intermediate); | 215 | args.push_back("-I"+root_intermediate); |
210 | args.push_back("-I"+root_source); | 216 | args.push_back("-I"+root_source); |
211 | args.push_back("-MD"); args.push_back("-MF"); args.push_back(root_intermediate+nos+".d"); | 217 | args.push_back("-MD"); args.push_back("-MF"); args.push_back(root_intermediate+nos+".d"); |
212 | args.push_back("-c"); | 218 | args.push_back("-c"); |
213 | args.push_back(cc); | 219 | args.push_back(cc); |
214 | args.push_back("-o"); args.push_back(o); | 220 | args.push_back("-o"); args.push_back(o); |
215 | // TODO: "g++" configurable | 221 | // TODO: "g++" configurable |
216 | int rv = execute("g++",args,stdO,stdE); | 222 | int rv = execute("g++",args,stdO,stdE); |
217 | if(! (WIFEXITED(rv) && !WEXITSTATUS(rv)) ) | 223 | if(! (WIFEXITED(rv) && !WEXITSTATUS(rv)) ) |
218 | throw compile_error(CODEPOINT,"failed to compile component",nos); | 224 | throw compile_error(CODEPOINT,"failed to compile component",nos); |
219 | return; | 225 | return; |
220 | }catch(utility_no_suffix& uns) { } | 226 | }catch(utility_no_suffix& uns) { } |
221 | } | 227 | } |
222 | // preprocessor targets | 228 | // preprocessor targets |
223 | for(int ppt=0;ppt<sizeof(pp_targets)/sizeof(*pp_targets);ppt++) { | 229 | for(int ppt=0;ppt<sizeof(pp_targets)/sizeof(*pp_targets);ppt++) { |
224 | try { | 230 | try { |
225 | string nos = strip_suffix(noro,pp_targets[ppt]); | 231 | string nos = strip_suffix(noro,pp_targets[ppt]); |
226 | string src = root_source+nos; | 232 | string src = root_source+nos; |
227 | if(access(src.c_str(),R_OK)) | 233 | if(access(src.c_str(),R_OK)) |
228 | throw konforka::exception(CODEPOINT,string("can't access component source (")+src+")"); | 234 | throw konforka::exception(CODEPOINT,string("can't access component source (")+src+")"); |
229 | make_path(dir_name(root_intermediate+nos),0755); | 235 | make_path(dir_name(root_intermediate+nos),0755); |
230 | file_lock lock(root_intermediate+nos+".lock"); | 236 | file_lock lock(root_intermediate+nos+".lock"); |
231 | sitecing_parser parser(*this); | 237 | sitecing_parser parser(*this); |
232 | config_options *co_skeleton = config.lookup_config(nos,config_options::flag_skeleton); | 238 | config_options *co_skeleton = config.lookup_config(nos,config_options::flag_skeleton); |
233 | if(co_skeleton) | 239 | if(co_skeleton) |
234 | parser.skeleton = co_skeleton->skeleton; | 240 | parser.skeleton = co_skeleton->skeleton; |
235 | static const char *id_chars = "abcdefghijklmnopqrstuvwxyz0123456789_ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | 241 | static const char *id_chars = "abcdefghijklmnopqrstuvwxyz0123456789_ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
236 | parser.class_name = normalize_path(nos,strip_leading_slash|strip_trailing_slash); | 242 | parser.class_name = normalize_path(nos,strip_leading_slash|strip_trailing_slash); |
237 | 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)) { | 243 | 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 | string::size_type lc = parser.class_name.find_first_of(id_chars,illc); | 244 | string::size_type lc = parser.class_name.find_first_of(id_chars,illc); |
239 | int n = ((lc==string::npos)?parser.class_name.length():lc)-illc; | 245 | int n = ((lc==string::npos)?parser.class_name.length():lc)-illc; |
240 | parser.class_name.replace(illc,n,n,'_'); | 246 | parser.class_name.replace(illc,n,n,'_'); |
241 | } | 247 | } |
242 | parser.class_name = "_SCC_"+parser.class_name; | 248 | parser.class_name = "_SCC_"+parser.class_name; |
243 | parser.output_basename = root_intermediate+nos; | 249 | parser.output_basename = root_intermediate+nos; |
244 | parser.component_basename = nos; | 250 | parser.component_basename = nos; |
245 | try { | 251 | try { |
246 | parser.preprocess(src); | 252 | parser.preprocess(src); |
247 | string sf = root_intermediate+nos+".pp_stamp"; | 253 | string sf = root_intermediate+nos+".pp_stamp"; |
248 | ofstream sfs(sf.c_str(),ios::trunc|ios::out); // touch .pp_stamp | 254 | ofstream sfs(sf.c_str(),ios::trunc|ios::out); // touch .pp_stamp |
249 | }catch(preprocessor_error& pe) { | 255 | }catch(preprocessor_error& pe) { |
250 | pe.component_name = nos; | 256 | pe.component_name = nos; |
251 | pe.see(CODEPOINT); | 257 | pe.see(CODEPOINT); |
252 | throw; | 258 | throw; |
253 | } | 259 | } |
254 | return; | 260 | return; |
255 | }catch(utility_no_suffix& uns) { } | 261 | }catch(utility_no_suffix& uns) { } |
256 | } | 262 | } |
257 | }catch(utility_no_prefix& unp) { } | 263 | }catch(utility_no_prefix& unp) { } |
258 | cerr << "ignoring build request for " << dp << endl; | 264 | cerr << "ignoring build request for " << dp << endl; |
259 | } | 265 | } |
260 | 266 | ||
261 | int component_factory::execute(const string& cmd, const list<string>& args,int stdo,int stde) { | 267 | int component_factory::execute(const string& cmd, const list<string>& args,int stdo,int stde) { |
262 | // XXX: is it right that we do stdio/stderr tricks outside of the function? | 268 | // XXX: is it right that we do stdio/stderr tricks outside of the function? |
263 | cerr << "executing: " << cmd; | 269 | cerr << "executing: " << cmd; |
264 | vector<const char*> argv(args.size()+2); | 270 | vector<const char*> argv(args.size()+2); |
265 | argv[0]=cmd.c_str(); | 271 | argv[0]=cmd.c_str(); |
266 | int an = 1; | 272 | int an = 1; |
267 | for(list<string>::const_iterator i=args.begin();i!=args.end();i++) { | 273 | for(list<string>::const_iterator i=args.begin();i!=args.end();i++) { |
268 | cerr << " " << *i ; | 274 | cerr << " " << *i ; |
269 | argv[an++] = i->c_str(); | 275 | argv[an++] = i->c_str(); |
270 | } | 276 | } |
271 | cerr << endl; | 277 | cerr << endl; |
272 | argv[an++]=NULL; | 278 | argv[an++]=NULL; |
273 | pid_t pid = vfork(); | 279 | pid_t pid = vfork(); |
274 | if(pid==-1) { | 280 | if(pid==-1) { |
275 | close(stdo); close(stde); | 281 | close(stdo); close(stde); |
276 | throw konforka::exception(CODEPOINT,"failed to vfork()"); | 282 | throw konforka::exception(CODEPOINT,"failed to vfork()"); |
277 | } | 283 | } |
278 | if(!pid) { | 284 | if(!pid) { |
279 | // child | 285 | // child |
280 | if(dup2(stdo,1)!=1) | 286 | if(dup2(stdo,1)!=1) |
281 | _exit(-1); | 287 | _exit(-1); |
282 | if(dup2(stde,2)!=2) | 288 | if(dup2(stde,2)!=2) |
283 | _exit(-1); | 289 | _exit(-1); |
284 | close(0); | 290 | close(0); |
285 | execvp(cmd.c_str(),(char**)&argv.front()); | 291 | execvp(cmd.c_str(),(char**)&argv.front()); |
286 | _exit(-1); | 292 | _exit(-1); |
287 | } | 293 | } |
288 | // parent | 294 | // parent |
289 | close(stdo); close(stde); | 295 | close(stdo); close(stde); |
290 | int rv; | 296 | int rv; |
291 | if(waitpid(pid,&rv,0)<0) | 297 | if(waitpid(pid,&rv,0)<0) |
292 | throw konforka::exception(CODEPOINT,"failed to waitpid()"); | 298 | throw konforka::exception(CODEPOINT,"failed to waitpid()"); |
293 | return rv; | 299 | return rv; |
294 | } | 300 | } |
295 | 301 | ||
296 | string component_factory::get_classname(const string& component) { | 302 | string component_factory::get_classname(const string& component) { |
297 | string cn = root_intermediate+normalize_path(component,strip_trailing_slash|strip_leading_slash)+".classname"; | 303 | string cn = root_intermediate+normalize_path(component,strip_trailing_slash|strip_leading_slash)+".classname"; |
298 | make(cn); | 304 | make(cn); |
299 | ifstream ifs(cn.c_str()); | 305 | ifstream ifs(cn.c_str()); |
300 | if(!ifs.good()) | 306 | if(!ifs.good()) |
301 | throw konforka::exception(CODEPOINT,"failed to access component .classname"); | 307 | throw konforka::exception(CODEPOINT,"failed to access component .classname"); |
302 | ifs >> cn; | 308 | ifs >> cn; |
303 | return cn; | 309 | return cn; |
304 | } | 310 | } |
305 | 311 | ||
306 | void component_factory::get_ancestors(const string& component,file_list_t& rv) { | 312 | void component_factory::get_ancestors(const string& component,file_list_t& rv) { |
307 | string cn = root_intermediate+normalize_path(component,strip_trailing_slash|strip_leading_slash)+".ancestors"; | 313 | string cn = root_intermediate+normalize_path(component,strip_trailing_slash|strip_leading_slash)+".ancestors"; |
308 | make(cn); | 314 | make(cn); |
309 | ifstream ifs(cn.c_str()); | 315 | ifstream ifs(cn.c_str()); |
310 | if(!ifs.good()) | 316 | if(!ifs.good()) |
311 | throw konforka::exception(CODEPOINT,string("failed to access component '")+component+"' .ancestors"); | 317 | throw konforka::exception(CODEPOINT,string("failed to access component '")+component+"' .ancestors"); |
312 | rv.clear(); | 318 | rv.clear(); |
313 | while(!ifs.eof()) { | 319 | while(!ifs.eof()) { |
314 | string a; | 320 | string a; |
315 | ifs >> a; | 321 | ifs >> a; |
316 | if(!a.empty()) | 322 | if(!a.empty()) |
317 | rv.push_back(a); | 323 | rv.push_back(a); |
318 | } | 324 | } |
319 | } | 325 | } |
320 | 326 | ||
321 | } | 327 | } |