void CoverageHeader::write(SharedFile &outDefFile, OovStringRef const /*srcFn*/, int numInstrLines) { std::string fnDef = getFileDefine(); mInstrDefineMap[fnDef] = numInstrLines; int totalCount = 0; for(auto const &defItem : mInstrDefineMap) { totalCount += defItem.second; } if(outDefFile.isOpen()) { OovString buf; static char const *lines[] = { "// Automatically generated file by OovCovInstr\n", "// This file should not normally be edited manually.\n", "#define COV_IN(fileIndex, instrIndex) gCoverage[fileIndex+instrIndex]++;\n", }; for(size_t i=0; i<sizeof(lines)/sizeof(lines[0]); i++) { buf += lines[i]; } buf += "#define COV_TOTAL_INSTRS "; buf.appendInt(totalCount); buf += "\n"; buf += "extern unsigned short gCoverage[COV_TOTAL_INSTRS];\n"; int coverageCount = 0; for(auto const &defItem : mInstrDefineMap) { OovString def = "#define "; def += defItem.first; def += " "; def.appendInt(coverageCount); coverageCount += defItem.second; def += " // "; def.appendInt(defItem.second); def += "\n"; buf += def; } outDefFile.truncate(); OovStatus status = outDefFile.seekBegin(); if(status.ok()) { status = outDefFile.write(&buf[0], static_cast<int>(buf.size())); } if(status.needReport()) { status.report(ET_Error, "Unable to write coverage source"); } } }
bool FileIsFileOnDisk(OovStringRef const path, bool &success) { OovString tempPath = path; FilePathRemovePathSep(tempPath, tempPath.size()-1); struct OovStat32 statval; int statRet = OovStat32(tempPath.getStr(), &statval); // Indicate there is an error only if the error is not ENOENT. success = ((statRet == 0) || (errno == ENOENT)); // Only indicate the file exists if there was no error, and it is a file. return((statRet == 0) && !S_ISDIR(statval.st_mode)); }
void ComponentsFile::parseProjRefs(OovStringRef const arg, OovString &rootDir, OovStringVec &excludes) { excludes.clear(); OovStringVec tokens = StringSplit(arg, '!'); if(rootDir.size() == 0) rootDir = tokens[0]; if(tokens.size() > 1) { excludes.resize(tokens.size()-1); std::copy(tokens.begin()+1, tokens.end(), excludes.begin()); } }
bool IncDirDependencyMap::includedPathsChanged(OovStringRef includerFn, std::set<std::string> const &includedInfoStr) const { bool changed = false; // First check if the includer filename exists in the dependency file. OovString origIncludedInfoStr = getValue(includerFn); if(origIncludedInfoStr.size() > 0) { CompoundValue origIncludedInfoCompVal; // get the changed time, which is the first value and discard // everything else. origIncludedInfoCompVal.parseString(origIncludedInfoStr); // Check that counts of the number of includes is the same in // the new and original map. This will detect deleted includes. if(origIncludedInfoCompVal.size()-IncDirMapNumTimeVals != (includedInfoStr.size() * IncDirMapNumIncPathParts)) { changed = true; } else { // Every included file in the new map must exist in the // original map. for(const auto &included : includedInfoStr) { CompoundValue incPathParts; incPathParts.parseString(included); if(incPathParts.size() == 2) { if(std::find(origIncludedInfoCompVal.begin(), origIncludedInfoCompVal.end(), incPathParts[1]) == origIncludedInfoCompVal.end()) { changed = true; } } else { changed = true; } } } } else { changed = true; } return changed; }
OovStatusReturn NameValueFile::writeFileExclusive(class SharedFile &file) { OovStatus status(true, SC_File); bool success = file.isOpen(); if(success) { OovString buf; readMapToBuf(buf); file.truncate(); status = file.seekBegin(); if(status.ok()) { status = file.write(&buf[0], static_cast<int>(buf.size())); } } else { status.set(false, SC_File); } return status; }