bool FileStat::isOutputOld(OovStringRef const outputFn, OovStringRef const inputFn, OovStatus &status) { time_t outTime = 0; time_t inTime = 0; status = FileGetFileTime(outputFn, outTime); bool old = !status.ok(); if(status.ok()) { status = FileGetFileTime(inputFn, inTime); if(status.ok()) { old = inTime > outTime; } else { old = true; } } else { status.clearError(); } return old; }
bool makeCoverageBuildProject() { std::string origProjFilePath = Project::getProjectFilePath(); std::string origCompTypesFilePath = Project::getComponentTypesFilePath(); std::string origPackagesFilePath = Project::getPackagesFilePath(); std::string covSrcDir = Project::getCoverageSourceDirectory(); std::string covProjDir = Project::getCoverageProjectDirectory(); bool success = true; OovStatus status = FileEnsurePathExists(covProjDir); if(status.ok()) { Project::setProjectDirectory(covProjDir); std::string newProjFilePath = Project::getProjectFilePath(); success = makeCoverageProjectFile(origProjFilePath, newProjFilePath, covSrcDir); if(success) { success = makeCoverageComponentTypesFile(origCompTypesFilePath, Project::getComponentTypesFilePath()); } if(success) { success = copyPackageFileIfNeeded(origPackagesFilePath, Project::getPackagesFilePath()); } } return status.ok() && success; }
void CoverageCountsReader::read(OovStringRef const fn) { File file; OovStatus status = file.open(fn, "r"); mInstrCounts.clear(); if(status.ok()) { char buf[100]; int lineCounter = 0; while(file.getString(buf, sizeof(buf), status)) { lineCounter++; int val; if(sscanf(buf, "%d", &val) == 1) { if(lineCounter == 1) { mNumInstrumentedLines = val; } else { mInstrCounts.push_back(val); } } } } if(status.needReport()) { status.report(ET_Error, "Unable to read coverage counts"); } }
static bool makeCoverageComponentTypesFile(OovStringRef const srcFn, OovStringRef const dstFn) { ComponentTypesFile file; OovStatus status = file.readTypesOnly(srcFn); if(status.ok()) { // Define a static library that contains the code that stores // the coverage counts that is compiled into exectuables. static OovStringRef const covLibName = Project::getCovLibName(); CompoundValue names = file.getComponentNames(); if(names.find(covLibName) == CompoundValue::npos) { names.push_back(covLibName); file.setComponentNames(names.getAsString()); file.setComponentType(covLibName, ComponentTypesFile::getShortComponentTypeName( ComponentTypesFile::CT_StaticLib)); } status = file.writeTypesOnly(dstFn); } if(status.needReport()) { OovString err = "Unable to make component types file "; err += srcFn; status.report(ET_Error, err); } return status.ok(); }
void ComponentGraph::updateGraph(const ComponentDrawOptions &options) { ComponentTypesFile compFile; OovStatus status = compFile.read(); if(status.ok()) { mNodes.clear(); for(auto const &name : compFile.getComponentNames()) { ComponentTypesFile::eCompTypes ct = compFile.getComponentType(name); if(ct != ComponentTypesFile::CT_Unknown) { mNodes.push_back(ComponentNode(name, ComponentNode::CNT_Component, ct)); } } BuildPackages buildPkgs(true); std::vector<Package> packages = buildPkgs.getPackages(); for(auto const &pkg : packages) { mNodes.push_back(ComponentNode(pkg.getPkgName(), ComponentNode::CNT_ExternalPackage)); } updateConnections(compFile, options); } if(status.needReport()) { status.report(ET_Error, "Unable to update component graph"); } }
void BuildSettingsDialog::saveScreen() { saveFromScreen(mLastCompName); OovStatus status = mComponentFile.writeFile(); if(status.needReport()) { status.report(ET_Error, "Unable to save build settings"); } }
OovStatusReturn GuiOptions::read() { setFilename(Project::getGuiOptionsFilePath()); OovStatus status = NameValueFile::readFile(); if(status.ok()) { setDefaultOptions(); } return status; }
OovStatusReturn NameValueFile::writeFile() { File file; OovStatus status = file.open(mFilename.getStr(), "w"); if(status.ok()) { status = writeFile(file); } return status; }
OovStatusReturn EditFiles::saveAsTextFileWithDialog() { FileEditView *editView = getEditView(); OovStatus status = editView->saveAsTextFileWithDialog(); if(status.ok()) { setTabText(editView, editView->getFileName()); } return status; }
bool EditFiles::checkDebugger() { bool ok = false; NameValueFile projFile(Project::getProjectFilePath()); OovStatus status = projFile.readFile(); if(!status.ok()) { OovString str = "Unable to get project file to get debugger: "; str += Project::getProjectFilePath(); status.report(ET_Error, str); } getDebugger().setDebuggerFilePath(projFile.getValue(OptToolDebuggerPath)); getDebugger().setDebuggee(mEditOptions.getValue(OptEditDebuggee)); getDebugger().setDebuggeeArgs(mEditOptions.getValue(OptEditDebuggeeArgs)); getDebugger().setWorkingDir(mEditOptions.getValue(OptEditDebuggerWorkingDir)); //Gui::messageBox("Debugging is not recommended. It is very unstable."); std::string debugger = getDebugger().getDebuggerFilePath(); std::string debuggee = getDebugger().getDebuggeeFilePath(); if(debugger.length() > 0) { if(debuggee.length() > 0) { // The debugger could be on the path. // if(fileExists(debugger)) { if(FileIsFileOnDisk(debuggee, status)) { ok = true; } else { Gui::messageBox("Component to debug in Edit/Preferences does not exist"); } if(status.needReport()) { status.report(ET_Error, "Unable to check debuggee status"); } } // else // { // Gui::messageBox("Debugger in Oovaide Analysis/Settings does not exist"); // } } else { Gui::messageBox("Component to debug must be set in Edit/Preferences"); } } else { Gui::messageBox("Debugger tool path must be set in Oovaide Analysis/Settings"); } return ok; }
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"); } } }
OovStatusReturn NameValueFile::readFile() { File file; OovStatus status = file.open(mFilename.getStr(), "r"); if(status.ok()) { clear(); status = readFile(file); } return status; }
OovStatusReturn ComponentTypesFile::writeTypesOnly(OovStringRef const fn) { mCompTypesFile.setFilename(fn); OovStatus status = mCompTypesFile.writeFile(); if(status.needReport()) { OovString str = "Unable to write source list file: "; str += mCompTypesFile.getFilename(); OovError::report(ET_Error, str); } return status; }
OovStatusReturn ProjectReader::readProject(OovStringRef const oovProjectDir) { Project::setProjectDirectory(oovProjectDir); setFilename(Project::getProjectFilePath()); OovStatus status = readFile(); if(status.ok()) { checkProjectVersion(); Project::setSourceRootDirectory(getValue(OptSourceRootDir)); } return status; }
FilePath Project::getOutputDir() { FilePath fp(Project::getProjectDirectory(), FP_Dir); fp.appendDir("output"); OovStatus status = FileEnsurePathExists(fp); if(status.needReport()) { OovString err = "Unable to create directory "; err += fp; status.report(ET_Error, fp); } return fp; }
void EditOptions::saveScreenSize(int width, int height) { if(getFilename().length() > 0) { setScreenCoord("ScreenWidth", width); setScreenCoord("ScreenHeight", height); OovStatus status = writeFile(); if(status.needReport()) { status.report(ET_Error, "Unable to write edit options"); } } }
OovStatusReturn NameValueFile::readOpenedFile(SharedFile &file) { clear(); std::string buf(file.getSize(), 0); int actualSize; OovStatus status = file.read(&buf[0], static_cast<int>(buf.size()), actualSize); if(status.ok()) { buf.resize(static_cast<size_t>(actualSize)); insertBufToMap(buf); } return status; }
void ComponentsFile::read(OovStringRef const fn) { setFilename(fn); OovStatus status = readFile(); if(status.needReport()) { // The components file is normally optional. status.reported(); /* OovString err = "Unable to read components file "; err += fn; status.report(ET_Error, err); */ } }
bool makeCoverageStats() { bool success = false; SharedFile covHeaderFile; OovString covHeaderFn = CoverageHeaderReader::getFn( Project::getCoverageSourceDirectory()); eOpenStatus stat = covHeaderFile.open(covHeaderFn, M_ReadShared, OE_Binary); if(stat == OS_Opened) { CoverageHeaderReader covHeaderReader; OovStatus status = covHeaderReader.read(covHeaderFile); if(status.needReport()) { status.report(ET_Error, "Unable to read coverage header"); } int headerInstrLines = covHeaderReader.getNumInstrumentedLines(); if(headerInstrLines > 0) { success = true; FilePath covCountsFn(Project::getCoverageProjectDirectory(), FP_Dir); covCountsFn.appendDir("out-Debug"); static char const covCountsFnStr[] = "OovCoverageCounts.txt"; covCountsFn.appendFile(covCountsFnStr); CoverageCountsReader covCounts; covCounts.read(covCountsFn); int covInstrLines = covCounts.getNumInstrumentedLines(); if(headerInstrLines == covInstrLines) { makeCoverageStats(covHeaderReader, covCounts); updateCovSourceCounts(covHeaderReader, covCounts); } else { fprintf(stderr, "Number of OovCoverage.h lines %d don't match %s lines %d\n", headerInstrLines, covCountsFnStr, covInstrLines); } } else { fprintf(stderr, "No lines are instrumented in %s\n", covHeaderFn.getStr()); } } else { fprintf(stderr, "Unable to open file %s\n", covHeaderFn.getStr()); } return success; }
void Editor::findInFiles(char const * const srchStr, char const * const path, bool caseSensitive, bool sourceOnly, GtkTextView *view) { FindFiles findFiles(srchStr, caseSensitive, sourceOnly, view); OovStatus status = findFiles.recurseDirs(path); if(status.needReport()) { OovString err = "Unable to search path "; err += path; status.report(ET_Error, err); } OovString matchStr = "Found "; matchStr.appendInt(findFiles.getNumMatches()); matchStr += " matches"; Gui::appendText(view, matchStr); }
OovStringRef const Project::getSrcRootDirectory() { if(sSourceRootDirectory.length() == 0) { NameValueFile file(getProjectFilePath()); OovStatus status = file.readFile(); if(status.needReport()) { OovString str = "Unable to read project file to get source: "; str += getProjectFilePath(); status.report(ET_Error, str); } sSourceRootDirectory = file.getValue(OptSourceRootDir); } return sSourceRootDirectory; }
eDupReturn createDuplicatesFile(/*OovStringRef const projDir,*/ std::string &outFn) { eDupReturn ret = DR_NoDupFilesFound; DuplicateOptions options; std::vector<DuplicateLineInfo> dupLineInfo; if(getDuplicateLineInfo(options, dupLineInfo)) { FilePath outPath(Project::getProjectDirectory(), FP_Dir); outPath.appendDir(DupsDir); outPath.appendFile("Dups.txt"); File outFile; OovStatus status = outFile.open(outPath, "w"); if(status.ok()) { outFn = outPath; for(auto const &lineInfo : dupLineInfo) { OovString str = "lines "; str.appendInt(lineInfo.mTotalDupLines); str += " : "; str += lineInfo.mFile1; str += " "; str.appendInt(lineInfo.mFile1StartLine); str += " : "; str += lineInfo.mFile2; str += " "; str.appendInt(lineInfo.mFile2StartLine); str += "\n"; status = outFile.putString(str); if(!status.ok()) { break; } } ret = DR_Success; } else { ret = DR_UnableToCreateDirectory; } if(status.needReport()) { status.report(ET_Error, "Unable to write to duplicates file"); } } return ret; }
/// Make a stats file that contains the percentage of instrumented /// lines that have been executed for each source file. static void makeCoverageStats(CoverageHeaderReader const &covHeader, CoverageCountsReader const &covCounts) { FilePath statFn(Project::getCoverageProjectDirectory(), FP_Dir); statFn.appendFile("oovCovStats.txt"); File statFile; OovStatus status = statFile.open(statFn, "w"); if(status.ok()) { size_t countIndex = 0; std::vector<int> const &counts = covCounts.getCounts(); for(auto const &mapItem : covHeader.getMap()) { int count = mapItem.second; int hits = 0; for(int i=0; i<count; i++) { if(countIndex < counts.size()) { if(counts[countIndex++]) { hits++; } } } int percent = 0; if(count > 0) { percent = (hits * 100) / count; } else { percent = 100; } OovString covFn = makeOrigCovFn(mapItem.first); fprintf(statFile.getFp(), "%s %d\n", covFn.getStr(), percent); } } if(status.needReport()) { OovString err = "Unable to open file "; err += statFn; status.report(ET_Error, err); } }
bool FileIsDirOnDisk(OovStringRef const path, OovStatus &status) { struct OovStat32 statval; int statRet = OovStat32(path, &statval); // Indicate there is an error only if the error is not ENOENT. status.set((statRet == 0) || (errno == ENOENT), SC_File); // Only indicate the directory exists if there was no error, and it is a directory. return((statRet == 0) && S_ISDIR(statval.st_mode)); }
void CoverageHeader::update(OovStringRef const outDefFn, OovStringRef const srcFn, int numInstrLines) { SharedFile outDefFile; eOpenStatus stat = outDefFile.open(outDefFn, M_ReadWriteExclusive, OE_Binary); if(stat == OS_Opened) { OovStatus status = read(outDefFile); if(status.ok()) { write(outDefFile, srcFn, numInstrLines); } if(status.needReport()) { status.report(ET_Error, "Unable to update coverage file"); } } }
OovStatusReturn ComponentTypesFile::read() { mCompTypesFile.setFilename(Project::getComponentTypesFilePath()); mCompSourceListFile.setFilename(Project::getComponentSourceListFilePath()); OovStatus status = mCompSourceListFile.readFile(); // For new projects, the files are optional. /// @todo - should detect the difference between missing files and disk errors. if(status.needReport()) { status.clearError(); } status = mCompTypesFile.readFile(); if(status.needReport()) { status.clearError(); } return status; }
void ProjectBuildArgs::setBuildConfig(OovStringRef buildMode, OovStringRef const buildConfig) { mBuildEnv.addCurrentFilterValue(OptFilterNameBuildMode, buildMode); mBuildEnv.addCurrentFilterValue(OptFilterNameBuildConfig, buildConfig); mBuildEnv.addCurrentFilterValue(OptFilterNamePlatform, OptionsDefaults::getPlatform()); OovStatus status = mProjectPackages.read(); if(status.needReport()) { // These packages are optional. status.clearError(); } status = mBuildPackages.read(); if(status.needReport()) { // These packages are optional. status.clearError(); } }
static bool makeCoverageProjectFile(OovStringRef const srcFn, OovStringRef const dstFn, OovStringRef const covSrcDir) { NameValueFile file(srcFn); OovStatus status = file.readFile(); if(status.ok()) { file.setFilename(dstFn); file.setNameValue(OptSourceRootDir, covSrcDir); status = file.writeFile(); } if(status.needReport()) { OovString err = "Unable to make project file "; err += srcFn; status.report(ET_Error, err); } return status.ok(); }
void BuildSettingsDialog::enterScreen() { ScannedComponentInfo scannedCompInfo; OovStatus status = scannedCompInfo.readScannedInfo(); if(status.ok()) { GtkComboBoxText *typeBox = GTK_COMBO_BOX_TEXT(Builder::getBuilder()->getWidget( "ComponentTypeComboboxtext")); Gui::clear(typeBox); Gui::setSelected(GTK_COMBO_BOX(typeBox), -1); Gui::appendText(typeBox, ComponentTypesFile::getLongComponentTypeName( CT_Unknown)); Gui::appendText(typeBox, ComponentTypesFile::getLongComponentTypeName( CT_StaticLib)); Gui::appendText(typeBox, ComponentTypesFile::getLongComponentTypeName( CT_SharedLib)); Gui::appendText(typeBox, ComponentTypesFile::getLongComponentTypeName( CT_Program)); Gui::appendText(typeBox, ComponentTypesFile::getLongComponentTypeName( CT_JavaJarLib)); Gui::appendText(typeBox, ComponentTypesFile::getLongComponentTypeName( CT_JavaJarProg)); mComponentTree.clear(); for(auto const &name : scannedCompInfo.getComponentNames()) { if(mLastCompName.length() == 0) { mLastCompName = name; } mComponentTree.appendText(getParent(name), ComponentTypesFile::getComponentChildName(name)); } } if(status.needReport()) { status.report(ET_Error, "Unable to read component settings file"); } GuiTreePath path("0"); gtk_tree_view_set_cursor(mComponentTree.getTreeView(), path.getPath(), nullptr, false); }
bool FileIsFileOnDisk(OovStringRef const path, OovStatus &status) { 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. status.set((statRet == 0) || (errno == ENOENT), SC_File); // Only indicate the file exists if there was no error, and it is a file. return((statRet == 0) && !S_ISDIR(statval.st_mode)); }