<commit_before>/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact:  Qt Software Information (<EMAIL>)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file.  Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/

#include "gdbmacrosbuildstep.h"

#include "makestep.h"
#include "qmakestep.h"
#include "qt4project.h"
#include "qt4projectmanagerconstants.h"

#include <utils/qtcassert.h>

using namespace Qt4ProjectManager;
using namespace Qt4ProjectManager::Internal;

GdbMacrosBuildStep::GdbMacrosBuildStep(Qt4Project *project)
    : BuildStep(project), m_project(project)
{
}

GdbMacrosBuildStep::~GdbMacrosBuildStep()
{
}

bool GdbMacrosBuildStep::init(const QString &buildConfiguration)
{
    m_buildDirectory = m_project->buildDirectory(buildConfiguration);
    m_qmake = m_project->qtVersion(buildConfiguration)->qmakeCommand();
    m_buildConfiguration = buildConfiguration;
    qDebug()<<"m_buildDirectory "<<m_buildDirectory;
    qDebug()<<"m_qmake "<<m_qmake;
    return true;
}

void GdbMacrosBuildStep::run(QFutureInterface<bool> & fi)
{
    // TODO CONFIG handling

    QString dumperPath = ExtensionSystem::PluginManager::instance()->getObject<Core::ICore>()
                ->resourcePath() + "/gdbmacros/";
    QStringList files;
    files << "gdbmacros.cpp"
          << "gdbmacros.pro";


    QString destDir = m_buildDirectory + "/qtc-gdbmacros/";
    QDir dir;
    dir.mkpath(destDir);
    foreach (const QString &file, files) {
        QFile destination(destDir + file);
        if (destination.exists())
            destination.remove();
        QFile::copy(dumperPath + file, destDir + file);
        qDebug()<<"copying"<<(dumperPath + file)<<" to "<< (destDir + file);
    }

    Qt4Project *qt4Project = static_cast<Qt4Project *>(project());

    QProcess qmake;
    qmake.setEnvironment(qt4Project->environment(m_buildConfiguration).toStringList());
    qmake.setWorkingDirectory(destDir);
    QStringList configarguments;
    QStringList makeArguments;

    // Find qmake step...
    QMakeStep *qmakeStep = qt4Project->qmakeStep();
    // Find out which configuration is used in this build configuration
    // and what kind of CONFIG we need to pass to qmake for that
    if (qmakeStep->value(m_buildConfiguration, "buildConfiguration").isValid()) {
        QtVersion::QmakeBuildConfig defaultBuildConfiguration = qt4Project->qtVersion(m_buildConfiguration)->defaultBuildConfig();
        QtVersion::QmakeBuildConfig projectBuildConfiguration = QtVersion::QmakeBuildConfig(qmakeStep->value(m_buildConfiguration, "buildConfiguration").toInt());
        if ((defaultBuildConfiguration & QtVersion::BuildAll) && !(projectBuildConfiguration & QtVersion::BuildAll))
            configarguments << "CONFIG-=debug_and_release";
        if (!(defaultBuildConfiguration & QtVersion::BuildAll) && (projectBuildConfiguration & QtVersion::BuildAll))
            configarguments << "CONFIG+=debug_and_release";
        if ((defaultBuildConfiguration & QtVersion::DebugBuild) && !(projectBuildConfiguration & QtVersion::DebugBuild))
            configarguments << "CONFIG+=release";
        if (!(defaultBuildConfiguration & QtVersion::DebugBuild) && (projectBuildConfiguration & QtVersion::DebugBuild))
            configarguments << "CONFIG+=debug";
        if (projectBuildConfiguration & QtVersion::BuildAll)
            makeArguments << (projectBuildConfiguration & QtVersion::DebugBuild ? "debug" : "release");

    } else {
        // Old style with CONFIG+=debug_and_release
        qDebug() << "OLD STYLE CONF";
        configarguments << "CONFIG+=debug_and_release";
        const MakeStep *ms = qt4Project->makeStep();
        QStringList makeargs = ms->value(m_buildConfiguration, "makeargs").toStringList();
        if (makeargs.contains("debug")) {
            makeArguments <<  "debug";
        } else if (makeargs.contains("release")) {
            makeArguments << "release";
        }
    }

    QString mkspec = qt4Project->qtVersion(m_buildConfiguration)->mkspec();
    qmake.start(m_qmake, QStringList()<<"-spec"<<mkspec<<configarguments<<"gdbmacros.pro");
    qmake.waitForFinished();
    qDebug()<<qmake.readAllStandardError()<<qmake.readAllStandardOutput();

    qmake.start(qt4Project->qtVersion(m_buildConfiguration)->makeCommand(), makeArguments);
    qmake.waitForFinished();
    qDebug()<<qmake.readAllStandardError()<<qmake.readAllStandardOutput();

    fi.reportResult(true);
}

QString GdbMacrosBuildStep::name()
{
    return Constants::GDBMACROSBUILDSTEP;
}

QString GdbMacrosBuildStep::displayName()
{
    return "Gdb Macros Build";
}

ProjectExplorer::BuildStepConfigWidget *GdbMacrosBuildStep::createConfigWidget()
{
    return new GdbMacrosBuildStepConfigWidget;
}

bool GdbMacrosBuildStep::immutable() const
{
    return false;
}

bool GdbMacrosBuildStepFactory::canCreate(const QString &name) const
{
    return name == Constants::GDBMACROSBUILDSTEP;
}

ProjectExplorer::BuildStep *GdbMacrosBuildStepFactory::create(ProjectExplorer::Project *pro, const QString &name) const
{
    QTC_ASSERT(name == Constants::GDBMACROSBUILDSTEP, return 0);
    Qt4Project *qt4project = qobject_cast<Qt4Project *>(pro);
    QTC_ASSERT(qt4project, return 0);
    return new GdbMacrosBuildStep(qt4project);
}

QStringList GdbMacrosBuildStepFactory::canCreateForProject(ProjectExplorer::Project *pro) const
{
    QStringList results;
    if (qobject_cast<Qt4Project *>(pro))
        results <<  Constants::GDBMACROSBUILDSTEP;
    return results;
}

QString GdbMacrosBuildStepFactory::displayNameForName(const QString &name) const
{
    if (name == Constants::GDBMACROSBUILDSTEP)
        return "Gdb Macros Build";
    else
        return QString::null;
}

QString GdbMacrosBuildStepConfigWidget::displayName() const
{
    return "Gdb Macros Build";
}

void GdbMacrosBuildStepConfigWidget::init(const QString & /*buildConfiguration*/)
{
    // TODO
}
<commit_msg>Fixes:    Noisy debugt output from gdbmacrosbuildstep.cpp<commit_after>/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact:  Qt Software Information (<EMAIL>)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file.  Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/

#include "gdbmacrosbuildstep.h"

#include "makestep.h"
#include "qmakestep.h"
#include "qt4project.h"
#include "qt4projectmanagerconstants.h"

#include <utils/qtcassert.h>

using namespace Qt4ProjectManager;
using namespace Qt4ProjectManager::Internal;

GdbMacrosBuildStep::GdbMacrosBuildStep(Qt4Project *project)
    : BuildStep(project), m_project(project)
{
}

GdbMacrosBuildStep::~GdbMacrosBuildStep()
{
}

bool GdbMacrosBuildStep::init(const QString &buildConfiguration)
{
    m_buildDirectory = m_project->buildDirectory(buildConfiguration);
    m_qmake = m_project->qtVersion(buildConfiguration)->qmakeCommand();
    m_buildConfiguration = buildConfiguration;
    return true;
}

void GdbMacrosBuildStep::run(QFutureInterface<bool> & fi)
{
    // TODO CONFIG handling

    QString dumperPath = ExtensionSystem::PluginManager::instance()->getObject<Core::ICore>()
                ->resourcePath() + "/gdbmacros/";
    QStringList files;
    files << "gdbmacros.cpp"
          << "gdbmacros.pro";


    QString destDir = m_buildDirectory + "/qtc-gdbmacros/";
    QDir dir;
    dir.mkpath(destDir);
    foreach (const QString &file, files) {
        QFile destination(destDir + file);
        if (destination.exists())
            destination.remove();
        QFile::copy(dumperPath + file, destDir + file);
    }

    Qt4Project *qt4Project = static_cast<Qt4Project *>(project());

    QProcess qmake;
    qmake.setEnvironment(qt4Project->environment(m_buildConfiguration).toStringList());
    qmake.setWorkingDirectory(destDir);
    QStringList configarguments;
    QStringList makeArguments;

    // Find qmake step...
    QMakeStep *qmakeStep = qt4Project->qmakeStep();
    // Find out which configuration is used in this build configuration
    // and what kind of CONFIG we need to pass to qmake for that
    if (qmakeStep->value(m_buildConfiguration, "buildConfiguration").isValid()) {
        QtVersion::QmakeBuildConfig defaultBuildConfiguration = qt4Project->qtVersion(m_buildConfiguration)->defaultBuildConfig();
        QtVersion::QmakeBuildConfig projectBuildConfiguration = QtVersion::QmakeBuildConfig(qmakeStep->value(m_buildConfiguration, "buildConfiguration").toInt());
        if ((defaultBuildConfiguration & QtVersion::BuildAll) && !(projectBuildConfiguration & QtVersion::BuildAll))
            configarguments << "CONFIG-=debug_and_release";
        if (!(defaultBuildConfiguration & QtVersion::BuildAll) && (projectBuildConfiguration & QtVersion::BuildAll))
            configarguments << "CONFIG+=debug_and_release";
        if ((defaultBuildConfiguration & QtVersion::DebugBuild) && !(projectBuildConfiguration & QtVersion::DebugBuild))
            configarguments << "CONFIG+=release";
        if (!(defaultBuildConfiguration & QtVersion::DebugBuild) && (projectBuildConfiguration & QtVersion::DebugBuild))
            configarguments << "CONFIG+=debug";
        if (projectBuildConfiguration & QtVersion::BuildAll)
            makeArguments << (projectBuildConfiguration & QtVersion::DebugBuild ? "debug" : "release");

    } else {
        // Old style with CONFIG+=debug_and_release
        configarguments << "CONFIG+=debug_and_release";
        const MakeStep *ms = qt4Project->makeStep();
        QStringList makeargs = ms->value(m_buildConfiguration, "makeargs").toStringList();
        if (makeargs.contains("debug")) {
            makeArguments <<  "debug";
        } else if (makeargs.contains("release")) {
            makeArguments << "release";
        }
    }

    QString mkspec = qt4Project->qtVersion(m_buildConfiguration)->mkspec();
    qmake.start(m_qmake, QStringList()<<"-spec"<<mkspec<<configarguments<<"gdbmacros.pro");
    qmake.waitForFinished();


    qmake.start(qt4Project->qtVersion(m_buildConfiguration)->makeCommand(), makeArguments);
    qmake.waitForFinished();

    fi.reportResult(true);
}

QString GdbMacrosBuildStep::name()
{
    return Constants::GDBMACROSBUILDSTEP;
}

QString GdbMacrosBuildStep::displayName()
{
    return "Gdb Macros Build";
}

ProjectExplorer::BuildStepConfigWidget *GdbMacrosBuildStep::createConfigWidget()
{
    return new GdbMacrosBuildStepConfigWidget;
}

bool GdbMacrosBuildStep::immutable() const
{
    return false;
}

bool GdbMacrosBuildStepFactory::canCreate(const QString &name) const
{
    return name == Constants::GDBMACROSBUILDSTEP;
}

ProjectExplorer::BuildStep *GdbMacrosBuildStepFactory::create(ProjectExplorer::Project *pro, const QString &name) const
{
    QTC_ASSERT(name == Constants::GDBMACROSBUILDSTEP, return 0);
    Qt4Project *qt4project = qobject_cast<Qt4Project *>(pro);
    QTC_ASSERT(qt4project, return 0);
    return new GdbMacrosBuildStep(qt4project);
}

QStringList GdbMacrosBuildStepFactory::canCreateForProject(ProjectExplorer::Project *pro) const
{
    QStringList results;
    if (qobject_cast<Qt4Project *>(pro))
        results <<  Constants::GDBMACROSBUILDSTEP;
    return results;
}

QString GdbMacrosBuildStepFactory::displayNameForName(const QString &name) const
{
    if (name == Constants::GDBMACROSBUILDSTEP)
        return "Gdb Macros Build";
    else
        return QString::null;
}

QString GdbMacrosBuildStepConfigWidget::displayName() const
{
    return "Gdb Macros Build";
}

void GdbMacrosBuildStepConfigWidget::init(const QString & /*buildConfiguration*/)
{
    // TODO
}

{'fraction_non_alphanumeric': 0.1346938775510204, 'fraction_numerical': 0.00510204081632653, 'mean_word_length': 4.683927091963546, 'pattern_counts': {'":': 0, '<': 103, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2270161', 'n_tokens_mistral': 3956, 'n_tokens_neox': 3863, 'n_words': 896}