| 159 | } |
| 160 | |
| 161 | bool AnalyzerInformation::analyzeFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, std::size_t fsFileId, std::size_t hash, std::list<ErrorMessage> &errors, bool debug) |
| 162 | { |
| 163 | if (mOutputStream.is_open()) |
| 164 | throw std::runtime_error("analyzer information file is already open"); |
| 165 | |
| 166 | if (buildDir.empty() || sourcefile.empty()) |
| 167 | return true; |
| 168 | |
| 169 | const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile(buildDir,sourcefile,cfg,fsFileId); |
| 170 | |
| 171 | { |
| 172 | tinyxml2::XMLDocument analyzerInfoDoc; |
| 173 | const tinyxml2::XMLError xmlError = analyzerInfoDoc.LoadFile(analyzerInfoFile.c_str()); |
| 174 | if (xmlError == tinyxml2::XML_SUCCESS) { |
| 175 | const std::string err = skipAnalysis(analyzerInfoDoc, hash, errors); |
| 176 | if (err.empty()) { |
| 177 | if (debug) |
| 178 | std::cout << "skipping analysis - loaded " << errors.size() << " cached finding(s) from '" << analyzerInfoFile << "' for '" << sourcefile << "'" << std::endl; |
| 179 | return false; |
| 180 | } |
| 181 | if (debug) { |
| 182 | std::cout << "discarding cached result from '" << analyzerInfoFile << "' for '" << sourcefile << "' - " << err << std::endl; |
| 183 | } |
| 184 | } |
| 185 | else if (xmlError != tinyxml2::XML_ERROR_FILE_NOT_FOUND) { |
| 186 | if (debug) |
| 187 | std::cout << "discarding cached result - failed to load '" << analyzerInfoFile << "' for '" << sourcefile << "' (" << tinyxml2::XMLDocument::ErrorIDToName(xmlError) << ")" << std::endl; |
| 188 | } |
| 189 | else if (debug) |
| 190 | std::cout << "no cached result '" << analyzerInfoFile << "' for '" << sourcefile << "' found" << std::endl; |
| 191 | } |
| 192 | |
| 193 | mOutputStream.open(analyzerInfoFile); |
| 194 | if (!mOutputStream.is_open()) |
| 195 | throw std::runtime_error("failed to open '" + analyzerInfoFile + "'"); |
| 196 | mOutputStream << "<?xml version=\"1.0\"?>\n"; |
| 197 | mOutputStream << "<analyzerinfo hash=\"" << hash << "\">\n"; |
| 198 | |
| 199 | return true; |
| 200 | } |
| 201 | |
| 202 | void AnalyzerInformation::reportErr(const ErrorMessage &msg) |
| 203 | { |
no test coverage detected