示例#1
0
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;
    }
示例#2
0
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;
    }
示例#3
0
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");
        }
    }
示例#4
0
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();
    }
示例#5
0
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");
        }
    }
示例#7
0
OovStatusReturn GuiOptions::read()
{
    setFilename(Project::getGuiOptionsFilePath());
    OovStatus status = NameValueFile::readFile();
    if(status.ok())
    {
        setDefaultOptions();
    }
    return status;
}
示例#8
0
OovStatusReturn NameValueFile::writeFile()
    {
    File file;
    OovStatus status = file.open(mFilename.getStr(), "w");
    if(status.ok())
        {
        status = writeFile(file);
        }
    return status;
    }
示例#9
0
OovStatusReturn EditFiles::saveAsTextFileWithDialog()
    {
    FileEditView *editView = getEditView();
    OovStatus status = editView->saveAsTextFileWithDialog();
    if(status.ok())
        {
        setTabText(editView, editView->getFileName());
        }
    return status;
    }
示例#10
0
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;
    }
示例#11
0
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");
            }
        }
    }
示例#12
0
OovStatusReturn NameValueFile::readFile()
    {
    File file;
    OovStatus status = file.open(mFilename.getStr(), "r");
    if(status.ok())
        {
        clear();
        status = readFile(file);
        }
    return status;
    }
示例#13
0
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;
    }
示例#14
0
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;
    }
示例#15
0
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;
    }
示例#16
0
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");
            }
        }
    }
示例#17
0
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;
    }
示例#18
0
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);
*/
        }
    }
示例#19
0
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;
    }
示例#20
0
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);
    }
示例#21
0
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;
    }
示例#22
0
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;
    }
示例#23
0
/// 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);
        }
    }
示例#24
0
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));
    }
示例#25
0
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");
            }
        }
    }
示例#26
0
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;
    }
示例#27
0
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();
        }
    }
示例#28
0
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();
    }
示例#29
0
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);
}
示例#30
0
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));
    }