Ejemplo n.º 1
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");
        }
    }
Ejemplo n.º 2
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();
    }
Ejemplo n.º 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");
        }
    }
Ejemplo n.º 4
0
void BuildSettingsDialog::saveScreen()
    {
    saveFromScreen(mLastCompName);
    OovStatus status = mComponentFile.writeFile();
    if(status.needReport())
        {
        status.report(ET_Error, "Unable to save build settings");
        }
    }
Ejemplo n.º 5
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;
    }
Ejemplo n.º 6
0
/// Copy a single source file and make a comment that contains the hit count
/// for each instrumented line.
static void updateCovSourceCounts(OovStringRef const relSrcFn,
        std::vector<int> &counts)
    {
    FilePath srcFn(Project::getCoverageSourceDirectory(), FP_Dir);
    srcFn.appendFile(relSrcFn);
    FilePath dstFn(Project::getCoverageProjectDirectory(), FP_Dir);
    dstFn.appendFile(relSrcFn);
    File srcFile;
    OovStatus status = srcFile.open(srcFn, "r");
    if(status.ok())
        {
        status = FileEnsurePathExists(dstFn);
        if(status.ok())
            {
            File dstFile;
            status = dstFile.open(dstFn, "w");
            if(status.ok())
                {
                char buf[1000];
                size_t instrCount = 0;
                while(srcFile.getString(buf, sizeof(buf), status))
                    {
                    if(strstr(buf, "COV_IN("))
                        {
                        if(instrCount < counts.size())
                            {
                            OovString countStr = "    // ";
                            countStr.appendInt(counts[instrCount]);
                            OovString newStr = buf;
                            size_t pos = newStr.find('\n');
                            newStr.insert(pos, countStr);
                            if(newStr.length() < sizeof(buf)-1)
                                {
                                strcpy(buf, newStr.getStr());
                                }
                            }
                        instrCount++;
                        }
                    status = dstFile.putString(buf);
                    if(!status.ok())
                        {
                        break;
                        }
                    }
                }
            }
        }
    if(status.needReport())
        {
        OovString err = "Unable to transfer coverage ";
        err += srcFn;
        err += " ";
        err += dstFn;
        status.report(ET_Error, err);
        }
    }
Ejemplo n.º 7
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();
        }
    }
Ejemplo n.º 8
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;
    }
Ejemplo n.º 9
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");
            }
        }
    }
Ejemplo n.º 10
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;
    }
Ejemplo n.º 11
0
OovStatusReturn ComponentTypesFile::writeFile()
    {
    OovStatus status = mCompTypesFile.writeFile();
    if(status.needReport())
        {
        OovString str = "Unable to write component types file: ";
        str += mCompTypesFile.getFilename();
        status.report(ET_Error, str);
        }
    if(status.ok())
        {
        status = mCompSourceListFile.writeFile();
        if(status.needReport())
            {
            OovString str = "Unable to write source list file: ";
            str += mCompSourceListFile.getFilename();
            status.report(ET_Error, str);
            }
        }
    return status;
    }
Ejemplo n.º 12
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;
    }
Ejemplo n.º 13
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");
            }
        }
    }
Ejemplo n.º 14
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);
*/
        }
    }
Ejemplo n.º 15
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;
    }
Ejemplo n.º 16
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;
    }
Ejemplo n.º 17
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);
    }
Ejemplo n.º 18
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;
    }
Ejemplo n.º 19
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);
        }
    }
Ejemplo n.º 20
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");
            }
        }
    }
Ejemplo n.º 21
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();
    }
Ejemplo n.º 22
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);
}
Ejemplo n.º 23
0
void ComponentGraph::removeNode(const ComponentNode &node,
        const ComponentDrawOptions &options)
    {
    for(size_t i=0; i<mNodes.size(); i++)
        {
        if(&node == &mNodes[i])
            {
            mNodes.erase(mNodes.begin() + i);
            break;
            }
        }
    ComponentTypesFile compFile;
    OovStatus status = compFile.read();
    if(status.needReport())
        {
        status.report(ET_Error, "Unable to read components file to update connections");
        }
    if(status.ok())
        {
        updateConnections(compFile, options);
        }
    mModified = true;
    }
Ejemplo n.º 24
0
void EditFiles::viewFile(OovStringRef const fn, int lineNum)
    {
    FilePath fp;

    fp.getAbsolutePath(fn, FP_File);
    auto iter = std::find_if(mFileViews.begin(), mFileViews.end(),
        [fp](std::unique_ptr<ScrolledFileView> const &fv) -> bool
        { return fv->mFilename.comparePaths(fp) == 0; });
    if(iter == mFileViews.end())
        {
        GtkNotebook *book = nullptr;
        if(putInMainWindow(fn))
            book = mSourceBook;
        else
            book = mHeaderBook;
        if(book)
            {
            GtkWidget *scrolled = gtk_scrolled_window_new(nullptr, nullptr);
            GtkWidget *editView = gtk_text_view_new();

            /// @todo - use make_unique when supported.
            ScrolledFileView *scrolledView = new ScrolledFileView(mDebugger);
            scrolledView->mFileView.init(GTK_TEXT_VIEW(editView), this);
            OovStatus status = scrolledView->mFileView.openTextFile(fp);
            if(status.needReport())
                {
                OovString err = "Unable to open file ";
                err += fp;
                status.report(ET_Error, err);
                }
            scrolledView->mScrolled = GTK_SCROLLED_WINDOW(scrolled);
            scrolledView->mFilename = fp;

            gtk_container_add(GTK_CONTAINER(scrolled), editView);
            Gui::appendPage(book, scrolled,
                    newTabLabel(fp.getName(), scrolledView->getViewTopParent()));
            gtk_widget_show_all(scrolled);
            scrolledView->mLeftMargin.setupMargin(GTK_TEXT_VIEW(editView));

            // Set up the windows to draw the line numbers in the left margin.
            // GTK has changed, and different setups are required for different
            // versions of GTK.
            // This is not allowed for a text view
            //          gtk_widget_set_app_paintable(editView, true);
#if(USE_DRAW_LAYER)
            overrideDrawLayer(editView);
            // If the left window is not created, errors display, "Attempt to
            // convert text buffer coordinates to coordinates for a nonexistent
            // buffer or private child window of GtkTextView". So create a
            // window that is only one pixel wide, and draw the line numbers
            // on the main text view window.
            gtk_text_view_set_border_window_size(GTK_TEXT_VIEW(editView),
                    GTK_TEXT_WINDOW_LEFT, 1);
            gtk_text_view_set_left_margin(GTK_TEXT_VIEW(editView),
                    scrolledView->mLeftMargin.getMarginWidth());
#else
            // The margin is drawn on the border window.
            gtk_text_view_set_border_window_size(GTK_TEXT_VIEW(editView),
                    GTK_TEXT_WINDOW_LEFT, scrolledView->mLeftMargin.getMarginWidth());
            g_signal_connect(editView, "draw", G_CALLBACK(onTextViewDraw), scrolledView);
#endif

            g_signal_connect(editView, "focus_in_event",
                    G_CALLBACK(on_EditFiles_focus_in_event), NULL);
            g_signal_connect(editView, "key_press_event",
                    G_CALLBACK(on_EditFiles_key_press_event), NULL);
            g_signal_connect(editView, "button_press_event",
                    G_CALLBACK(on_EditFiles_button_press_event), NULL);
            mFileViews.push_back(std::unique_ptr<ScrolledFileView>(scrolledView));
#if(DBG_EDITF)
        sDbgFile.printflush("viewFile count %d, line %d\n", mFileViews.size(), lineNum);
#endif
            iter = mFileViews.end()-1;
            }
        }
    GtkNotebook *notebook = (*iter)->getBook();
    if(notebook)
        {
        int pageIndex = getPageNumber(notebook, (*iter)->getTextView());
        Gui::setCurrentPage(notebook, pageIndex);
        // focus is set after the screen is displayed by onIdle
//      gtk_widget_grab_focus(GTK_WIDGET((*iter).getTextView()));
#if(DBG_EDITF)
        sDbgFile.printflush("viewFile %d\n", pageIndex);
#endif
        if(lineNum > 1)
            {
            (*iter)->mDesiredLine = lineNum;
            }
        }
    }