void TestRunner::compile_onMakeFinished_(int exitCode, QProcess::ExitStatus /*exitStatus*/)
{
    disconnect(process_,
            static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
            this,
            &TestRunner::compile_onMakeFinished_);

    compileOutput_ += process_->readAll();
    if (exitCode == 0)
    {
        QString time = getCurrentTime();
        compileOutput_ += time + ": The process \"" + process_->program() + "\" exited normally.\n";

        testBinPath_ = compileDir_.absoluteFilePath(testName_); // XXX TODO change this on Windows

        emit outputChanged();
        setStatus_(Status::NotRunYet);
        emit compileFinished(true);
    }
    else
    {
        QString time = getCurrentTime();
        compileOutput_ +=
                time + ": The process \"" + process_->program() +
                QString("\" exited with code %1.\n").arg(exitCode);

        failCompilation_("make failed.");
    }
}
void TestRunner::failCompilation_(const QString & errorMessage)
{
    QString time = getCurrentTime();
    compileOutput_ += time + ": Compilation failed: " + errorMessage + "\n";

    emit outputChanged();
    setStatus_(Status::CompileError);
    emit compileFinished(false);
}
void TestRunner::compile()
{
    // Check when is the last time that the test source has been modified
    const QString filePath = inDir_.filePath(fileName_);
    const QFileInfo fileInfo(filePath);
    const QDateTime lastModified = fileInfo.lastModified();

    // Compile if necessary
    Status s = status();
    bool notCompiledYet = (s == Status::NotCompiledYet) || (s == Status::CompileError);
    bool modified       = (lastCompiled_ < lastModified);
    bool processing     = (s == Status::Compiling) || (s == Status::Running);
    if (notCompiledYet || (modified && !processing))
    {
         setStatus_(Status::Compiling);
        compileOutput_.clear();
        lastCompiled_ = lastModified;

        // -------- Go to folder where to compile test --------

        QString compileDirPath = outDir_.absoluteFilePath(testName_);
        compileDir_ = outDir_;
        if (!compileDir_.cd(testName_))
        {
            // Create folder since it doesn't exist
            if (!outDir_.mkdir(testName_))
            {
                failCompilation_("Can't create build folder " + compileDirPath);
                return;
            }

            // Go to folder where to compile test
            // This is hard to reach (if we manage to create the folder, surely
            // we can cd to it), but doesn't hurt to check.
            if (!compileDir_.cd(testName_))
            {
                failCompilation_("Can't create build folder " + compileDirPath);
                return;
            }
        }


        // -------- Open all files for reading or writing --------

        const QString hFileName   = testName_ + ".gen.h";
        const QString cppFileName = testName_ + ".gen.cpp";
        const QString proFileName = testName_ + ".gen.pro";

        const QString hFilePath   = compileDir_.filePath(hFileName);
        const QString cppFilePath = compileDir_.filePath(cppFileName);
        const QString proFilePath = compileDir_.filePath(proFileName);

        QFile sourceFile(filePath);
        QFile hFile(hFilePath);
        QFile cppFile(cppFilePath);
        QFile proFile(proFilePath);

        if (!sourceFile.open(QFile::ReadOnly | QFile::Text))
        {
            failCompilation_("Can't open " + filePath);
            return;
        }

        if (!hFile.open(QFile::WriteOnly | QFile::Text))
        {
            failCompilation_("Can't write " + hFilePath);
            return;
        }

        if (!cppFile.open(QFile::WriteOnly | QFile::Text))
        {
            failCompilation_("Can't write " + cppFilePath);
            return;
        }

        if (!proFile.open(QFile::WriteOnly | QFile::Text))
        {
            failCompilation_("Can't write " + proFilePath);
            return;
        }


        // -------- Read source file --------

        QTextStream sourceStream(&sourceFile);
        const QString testSource = sourceStream.readAll();


        // -------- Generate and write test gen files --------

        QTextStream hStream(&hFile);
        QTextStream cppStream(&cppFile);
        QTextStream proStream(&proFile);

        hStream   << generateH(testName_, testSource);
        cppStream << generateCpp(testName_, testSource);
        proStream << generatePro(testName_, testSource);


        // -------- Run qmake --------

        QString program = QMAKE_QMAKE_QMAKE;
        QStringList arguments;
        arguments << "-spec" << QMAKE_QMAKESPEC << proFilePath;

        compileOutput_ +=
                getCurrentTime() +
                ": Starting: \"" +
                program + "\" " +
                arguments.join(' ') + "\n";

        process_->setWorkingDirectory(compileDirPath);
        connect(process_,
                static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
                this,
                &TestRunner::compile_onQmakeFinished_);

        emit outputChanged();

        process_->start(program, arguments);

        // -> go read qMakeFinished_(int exitCode) now.
    }
    else
    {
        emit compileFinished(true);
    }
}
Beispiel #4
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    auto keys = QStyleFactory::keys();
    for (auto s : keys)
    {
        qDebug(s.toStdString().c_str());
    }

    QString ss = load_stylesheet(":/Stylesheets/common.qss");

#ifdef _6IT_UI_MOBILE
    ss.append(load_stylesheet(":/Stylesheets/common_mobile.qss"));
#else
    ss.append(load_stylesheet(":/Stylesheets/common_desktop.qss"));
#endif

#ifdef _6IT_QT_WINRT_DESKTOP
    ss.append(load_stylesheet(":/Stylesheets/winrt_desktop.qss"));
#elif defined(_6IT_QT_WINRT_PHONE)
    a.setStyle(QStyleFactory::create("Fusion"));
    ss.append(load_stylesheet(":/Stylesheets/winrt_phone.qss"));
#elif defined(_6IT_QT_WINRT_DESKTOP)
    ss.append(load_stylesheet(":/Stylesheets/windows_desktop.qss"));
#elif defined(_6IT_QT_IOS)
    ss.append(load_stylesheet(":/Stylesheets/ios.qss"));
#elif defined(_6IT_QT_ANDROID)
    a.setStyle(QStyleFactory::create("Fusion"));
    ss.append(load_stylesheet(":/Stylesheets/android.qss"));
#elif defined(_6IT_QT_LINUX_DESKTOP)
    ss.append(load_stylesheet(":/Stylesheets/linux_desktop.qss"));
#endif

    a.setStyleSheet(ss);

    QThread thread;
    auto pworker = new RZQtSubCWorker();
    auto &worker = *pworker;
    worker.moveToThread(&thread);
    thread.start();

    FileListWindow fileListWindow;
    ViewSourceWindow editorWindow;
    RunWindow runWindow;
    CompileWindow compileWindow(worker);
    fileListWindow.show();

    QObject::connect(&fileListWindow, SIGNAL(sourceSelected(QString)), &editorWindow, SLOT(show()));
    QObject::connect(&fileListWindow, SIGNAL(sourceSelected(QString)), &editorWindow, SLOT(loadFile(QString)));
    QObject::connect(&fileListWindow, SIGNAL(sourceSelected(QString)), &fileListWindow, SLOT(hide()));

    QObject::connect(&editorWindow, SIGNAL(navigatedBack()), &fileListWindow, SLOT(show()));
    QObject::connect(&editorWindow, SIGNAL(navigatedBack()), &editorWindow, SLOT(hide()));

    QObject::connect(&editorWindow, SIGNAL(runCode(QString const &)), &editorWindow, SLOT(hide()));
    QObject::connect(&editorWindow, SIGNAL(runCode(QString const &)), &compileWindow, SLOT(show()));
    QObject::connect(&editorWindow, SIGNAL(runCode(QString const &)), &compileWindow, SLOT(clear()));
    QObject::connect(&editorWindow, SIGNAL(runCode(QString const &)), &worker, SLOT(setSource(QString const &)));

    QObject::connect(&compileWindow, SIGNAL(navigatedBack()), &editorWindow, SLOT(show()));
    QObject::connect(&compileWindow, SIGNAL(navigatedBack()), &compileWindow, SLOT(hide()));
    QObject::connect(&worker, SIGNAL(compilationWillStart()), &compileWindow, SLOT(compileStarted()));
    QObject::connect(&worker, SIGNAL(compilationDidFinish()), &compileWindow, SLOT(compileFinished()));

    QObject::connect(&compileWindow, SIGNAL(runClicked()), &compileWindow, SLOT(hide()));
    QObject::connect(&compileWindow, SIGNAL(runClicked()), &runWindow, SLOT(show()));
    QObject::connect(&compileWindow, SIGNAL(runClicked()), &worker, SLOT(run()));

    QObject::connect(&runWindow, SIGNAL(navigatedBack()), &compileWindow, SLOT(show()));
    QObject::connect(&runWindow, SIGNAL(navigatedBack()), &runWindow, SLOT(hide()));
    QObject::connect(&worker, SIGNAL(runWillStart()), &runWindow, SLOT(runStarted()));
    QObject::connect(&worker, SIGNAL(runDidFinish()), &runWindow, SLOT(runFinished()));

    QObject::connect(&worker, SIGNAL(sourceChanged()), &worker, SLOT(compile()));
    QObject::connect(&worker, SIGNAL(compilerConsoleOutput(QString const &, int)), &compileWindow, SLOT(printString(QString const &, int)));
    QObject::connect(&worker, SIGNAL(runConsoleOutput(QString const &, int)), &runWindow, SLOT(printString(QString const &, int)));

    return a.exec();
}