comparison src/plugincandidates.cpp @ 24:24b1d94440f5

Debug output improvements, and make the checker actually attempt to call the descriptor function for known plugin types
author Chris Cannam
date Wed, 16 Nov 2016 16:12:42 +0000
parents 386de1be6226
children cf18645ff411
comparison
equal deleted inserted replaced
23:65b6c64992dd 24:24b1d94440f5
74 } 74 }
75 75
76 void 76 void
77 PluginCandidates::log(string message) 77 PluginCandidates::log(string message)
78 { 78 {
79 if (m_logCallback) m_logCallback->log("PluginCandidates: " + message); 79 if (m_logCallback) {
80 m_logCallback->log("PluginCandidates: " + message);
81 } else {
82 cerr << "PluginCandidates: " << message << endl;
83 }
80 } 84 }
81 85
82 vector<string> 86 vector<string>
83 PluginCandidates::getLibrariesInPath(vector<string> path) 87 PluginCandidates::getLibrariesInPath(vector<string> path)
84 { 88 {
85 vector<string> candidates; 89 vector<string> candidates;
86 90
87 for (string dirname: path) { 91 for (string dirname: path) {
88 92
89 log("scanning directory " + dirname + "\n"); 93 log("scanning directory " + dirname);
90 94
91 QDir dir(dirname.c_str(), PLUGIN_GLOB, 95 QDir dir(dirname.c_str(), PLUGIN_GLOB,
92 QDir::Name | QDir::IgnoreCase, 96 QDir::Name | QDir::IgnoreCase,
93 QDir::Files | QDir::Readable); 97 QDir::Files | QDir::Readable);
94 98
124 // Helper bailed out for some reason presumably associated 128 // Helper bailed out for some reason presumably associated
125 // with the plugin following the last one it reported 129 // with the plugin following the last one it reported
126 // on. Add a failure entry for that one and continue with 130 // on. Add a failure entry for that one and continue with
127 // the following ones. 131 // the following ones.
128 string failed = *(remaining.rbegin() + shortfall - 1); 132 string failed = *(remaining.rbegin() + shortfall - 1);
129 log("helper output ended before result for plugin " + failed + "\n"); 133 log("helper output ended before result for plugin " + failed);
130 result.push_back("FAILURE|" + failed + "|Plugin load check failed or timed out"); 134 result.push_back("FAILURE|" + failed + "|Plugin load check failed or timed out");
131 remaining = vector<string> 135 remaining = vector<string>
132 (remaining.rbegin(), remaining.rbegin() + shortfall - 1); 136 (remaining.rbegin(), remaining.rbegin() + shortfall - 1);
133 } 137 }
134 ++runcount; 138 ++runcount;
140 vector<string> 144 vector<string>
141 PluginCandidates::runHelper(vector<string> libraries, string descriptor) 145 PluginCandidates::runHelper(vector<string> libraries, string descriptor)
142 { 146 {
143 vector<string> output; 147 vector<string> output;
144 148
145 log("running helper " + m_helper + " with following library list:\n"); 149 log("running helper " + m_helper + " with following library list:");
146 for (auto &lib: libraries) log(lib + "\n"); 150 for (auto &lib: libraries) log(lib);
147 151
148 QProcess process; 152 QProcess process;
149 process.setReadChannel(QProcess::StandardOutput); 153 process.setReadChannel(QProcess::StandardOutput);
150 process.setProcessChannelMode(QProcess::ForwardedErrorChannel); 154 process.setProcessChannelMode(QProcess::ForwardedErrorChannel);
151 process.start(m_helper.c_str(), { descriptor.c_str() }); 155 process.start(m_helper.c_str(), { descriptor.c_str() });
182 if (linelen > 0) { 186 if (linelen > 0) {
183 output.push_back(buf); 187 output.push_back(buf);
184 done = (output.size() == libraries.size()); 188 done = (output.size() == libraries.size());
185 } else if (linelen < 0) { 189 } else if (linelen < 0) {
186 // error case 190 // error case
187 log("received error code while reading from helper\n"); 191 log("received error code while reading from helper");
188 done = true; 192 done = true;
189 } else { 193 } else {
190 // no error, but no line read (could just be between 194 // no error, but no line read (could just be between
191 // lines, or could be eof) 195 // lines, or could be eof)
192 done = (process.state() == QProcess::NotRunning); 196 done = (process.state() == QProcess::NotRunning);
193 if (!done) { 197 if (!done) {
194 if (t.elapsed() > timeout) { 198 if (t.elapsed() > timeout) {
195 // this is purely an emergency measure 199 // this is purely an emergency measure
196 log("timeout: helper took too long, killing it\n"); 200 log("timeout: helper took too long, killing it");
197 process.kill(); 201 process.kill();
198 done = true; 202 done = true;
199 } else { 203 } else {
200 process.waitForReadyRead(200); 204 process.waitForReadyRead(200);
201 } 205 }
206 if (process.state() != QProcess::NotRunning) { 210 if (process.state() != QProcess::NotRunning) {
207 process.close(); 211 process.close();
208 process.waitForFinished(); 212 process.waitForFinished();
209 } 213 }
210 214
211 log("helper completed\n"); 215 log("helper completed");
212 216
213 return output; 217 return output;
214 } 218 }
215 219
216 void 220 void
219 for (auto &r: result) { 223 for (auto &r: result) {
220 224
221 QString s(r.c_str()); 225 QString s(r.c_str());
222 QStringList bits = s.split("|"); 226 QStringList bits = s.split("|");
223 227
224 log("read output line from helper: " + r); 228 log(("read output line from helper: " + s.trimmed()).toStdString());
225 229
226 if (bits.size() < 2 || bits.size() > 3) { 230 if (bits.size() < 2 || bits.size() > 3) {
227 log("invalid output line (wrong number of |-separated fields)\n"); 231 log("invalid output line (wrong number of |-separated fields)");
228 continue; 232 continue;
229 } 233 }
230 234
231 string status = bits[0].toStdString(); 235 string status = bits[0].toStdString();
232 236
241 245
242 } else if (status == "FAILURE") { 246 } else if (status == "FAILURE") {
243 m_failures[tag].push_back({ library, message }); 247 m_failures[tag].push_back({ library, message });
244 248
245 } else { 249 } else {
246 log("unexpected status \"" + status + "\" in output line\n"); 250 log("unexpected status \"" + status + "\" in output line");
247 } 251 }
248 } 252 }
249 } 253 }
250 254