File src/GcovImporter.cpp changed (mode: 100644) (index 1581526..7eb03e3) |
... |
... |
GcovImporter::parseGcov(const std::string &path) |
274 |
274 |
std::string type, value; |
std::string type, value; |
275 |
275 |
std::tie(type, value) = splitAt(line, ':'); |
std::tie(type, value) = splitAt(line, ':'); |
276 |
276 |
if (type == "file") { |
if (type == "file") { |
277 |
|
coverage = nullptr; |
|
278 |
|
|
|
279 |
|
fs::path filePath = value; |
|
280 |
|
if (!filePath.is_absolute()) { |
|
281 |
|
filePath = prefix / filePath; |
|
282 |
|
} |
|
283 |
|
|
|
284 |
|
fs::path sourcePath = normalizePath(fs::absolute(filePath, |
|
285 |
|
rootDir)); |
|
286 |
|
if (!pathIsInSubtree(rootDir, sourcePath) || |
|
287 |
|
isExcluded(sourcePath)) { |
|
288 |
|
continue; |
|
289 |
|
} |
|
290 |
|
|
|
291 |
|
sourcePath = makeRelativePath(rootDir, sourcePath); |
|
292 |
|
coverage = &mapping[sourcePath.string()]; |
|
|
277 |
|
const std::string sourcePath = resolveSourcePath(value); |
|
278 |
|
coverage = (sourcePath.empty() ? nullptr : &mapping[sourcePath]); |
293 |
279 |
} else if (coverage != nullptr && type == "lcount") { |
} else if (coverage != nullptr && type == "lcount") { |
294 |
280 |
std::vector<std::string> fields = split(value, ','); |
std::vector<std::string> fields = split(value, ','); |
295 |
281 |
if (fields.size() < 2U) { |
if (fields.size() < 2U) { |
|
... |
... |
GcovImporter::parseGcov(const std::string &path) |
299 |
285 |
|
|
300 |
286 |
unsigned int lineNo = std::stoi(fields[0]); |
unsigned int lineNo = std::stoi(fields[0]); |
301 |
287 |
int count = std::stoi(fields[1]); |
int count = std::stoi(fields[1]); |
|
288 |
|
updateCoverage(*coverage, lineNo, count); |
|
289 |
|
} |
|
290 |
|
} |
|
291 |
|
} |
302 |
292 |
|
|
303 |
|
if (coverage->size() < lineNo) { |
|
304 |
|
coverage->resize(lineNo, -1); |
|
305 |
|
} |
|
|
293 |
|
std::string |
|
294 |
|
GcovImporter::resolveSourcePath(fs::path unresolved) |
|
295 |
|
{ |
|
296 |
|
if (!unresolved.is_absolute()) { |
|
297 |
|
unresolved = prefix / unresolved; |
|
298 |
|
} |
306 |
299 |
|
|
307 |
|
int &entry = (*coverage)[lineNo - 1U]; |
|
308 |
|
entry = (entry == -1 ? count : entry + count); |
|
309 |
|
} |
|
|
300 |
|
fs::path sourcePath = normalizePath(fs::absolute(unresolved, |
|
301 |
|
rootDir)); |
|
302 |
|
if (!pathIsInSubtree(rootDir, sourcePath) || isExcluded(sourcePath)) { |
|
303 |
|
return std::string(); |
|
304 |
|
} |
|
305 |
|
|
|
306 |
|
return makeRelativePath(rootDir, sourcePath).string(); |
|
307 |
|
} |
|
308 |
|
|
|
309 |
|
void |
|
310 |
|
GcovImporter::updateCoverage(std::vector<int> &coverage, unsigned int lineNo, |
|
311 |
|
int count) |
|
312 |
|
{ |
|
313 |
|
if (coverage.size() < lineNo) { |
|
314 |
|
coverage.resize(lineNo, -1); |
310 |
315 |
} |
} |
|
316 |
|
|
|
317 |
|
int &entry = coverage[lineNo - 1U]; |
|
318 |
|
entry = (entry == -1 ? count : entry + count); |
311 |
319 |
} |
} |
312 |
320 |
|
|
313 |
321 |
bool |
bool |
File src/GcovImporter.hpp changed (mode: 100644) (index 13a22e7..26b5bdf) |
... |
... |
private: |
104 |
104 |
* @param path Path of the file. |
* @param path Path of the file. |
105 |
105 |
*/ |
*/ |
106 |
106 |
void parseGcov(const std::string &path); |
void parseGcov(const std::string &path); |
|
107 |
|
/** |
|
108 |
|
* @brief Converts path from coverage data into relative form. |
|
109 |
|
* |
|
110 |
|
* @param unresolved Possibly absolute path. |
|
111 |
|
* |
|
112 |
|
* @returns Relative path or empty string if it's not in the tree or |
|
113 |
|
* excluded. |
|
114 |
|
*/ |
|
115 |
|
std::string resolveSourcePath(boost::filesystem::path unresolved); |
|
116 |
|
/** |
|
117 |
|
* @brief Updates coverage information of single line. |
|
118 |
|
* |
|
119 |
|
* @param coverage Coverage data. |
|
120 |
|
* @param lineNo Line number. |
|
121 |
|
* @param count Number of times the line was executed. |
|
122 |
|
*/ |
|
123 |
|
void updateCoverage(std::vector<int> &coverage, unsigned int lineNo, |
|
124 |
|
int count); |
107 |
125 |
/** |
/** |
108 |
126 |
* @brief Checks whether specified path is excluded. |
* @brief Checks whether specified path is excluded. |
109 |
127 |
* |
* |