2015-08-26 09:37:55 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) Filippo Cucchetto <filippocucchetto@gmail.com>
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2016-06-14 20:33:55 +03:00
|
|
|
#include "nimcompilerbuildstep.h"
|
2020-08-26 10:48:29 +02:00
|
|
|
|
2016-06-14 20:33:55 +03:00
|
|
|
#include "nimbuildconfiguration.h"
|
2019-08-19 12:31:25 +02:00
|
|
|
#include "nimbuildsystem.h"
|
|
|
|
|
#include "nimconstants.h"
|
2017-01-21 23:36:14 +01:00
|
|
|
#include "nimtoolchain.h"
|
2015-08-26 09:37:55 +02:00
|
|
|
|
2020-08-26 10:48:29 +02:00
|
|
|
#include <projectexplorer/processparameters.h>
|
2015-08-26 09:37:55 +02:00
|
|
|
#include <projectexplorer/buildconfiguration.h>
|
2017-01-30 23:36:18 +01:00
|
|
|
#include <projectexplorer/ioutputparser.h>
|
2018-11-17 21:19:04 +02:00
|
|
|
#include <projectexplorer/kitinformation.h>
|
|
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2020-08-26 10:48:29 +02:00
|
|
|
|
2015-08-26 09:37:55 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2020-08-26 10:48:29 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
2015-08-26 09:37:55 +02:00
|
|
|
|
2020-08-26 10:48:29 +02:00
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QComboBox>
|
2015-08-26 09:37:55 +02:00
|
|
|
#include <QDir>
|
2020-08-26 10:48:29 +02:00
|
|
|
#include <QFormLayout>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QLineEdit>
|
2017-01-30 23:36:18 +01:00
|
|
|
#include <QRegularExpression>
|
2020-08-26 10:48:29 +02:00
|
|
|
#include <QTextEdit>
|
2015-08-26 09:37:55 +02:00
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
|
|
namespace Nim {
|
|
|
|
|
|
2020-08-26 10:48:29 +02:00
|
|
|
class NimCompilerBuildStepConfigWidget : public ProjectExplorer::BuildStepConfigWidget
|
|
|
|
|
{
|
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(Nim::NimCompilerBuildStep)
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit NimCompilerBuildStepConfigWidget(NimCompilerBuildStep *buildStep);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void updateUi();
|
|
|
|
|
void updateCommandLineText();
|
|
|
|
|
void updateTargetComboBox();
|
|
|
|
|
void updateAdditionalArgumentsLineEdit();
|
|
|
|
|
void updateDefaultArgumentsComboBox();
|
|
|
|
|
|
|
|
|
|
void onAdditionalArgumentsTextEdited(const QString &text);
|
|
|
|
|
void onTargetChanged(int index);
|
|
|
|
|
void onDefaultArgumentsComboBoxIndexChanged(int index);
|
|
|
|
|
|
|
|
|
|
NimCompilerBuildStep *m_buildStep;
|
|
|
|
|
QTextEdit *m_commandTextEdit;
|
|
|
|
|
QComboBox *m_defaultArgumentsComboBox;
|
|
|
|
|
QComboBox *m_targetComboBox;
|
|
|
|
|
QLineEdit *m_additionalArgumentsLineEdit;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// NimParser
|
|
|
|
|
|
2020-04-15 14:59:51 +02:00
|
|
|
class NimParser : public ProjectExplorer::OutputTaskParser
|
2017-01-30 23:36:18 +01:00
|
|
|
{
|
2020-04-16 13:53:05 +02:00
|
|
|
Result handleLine(const QString &lne, Utils::OutputFormat) override
|
2017-01-30 23:36:18 +01:00
|
|
|
{
|
2020-04-08 17:45:39 +02:00
|
|
|
const QString line = lne.trimmed();
|
2020-06-18 11:18:36 +02:00
|
|
|
static const QRegularExpression regex("(.+.nim)\\((\\d+), (\\d+)\\) (.+)");
|
|
|
|
|
static const QRegularExpression warning("(Warning):(.*)");
|
|
|
|
|
static const QRegularExpression error("(Error):(.*)");
|
2017-01-30 23:36:18 +01:00
|
|
|
|
2020-06-18 11:18:36 +02:00
|
|
|
const QRegularExpressionMatch match = regex.match(line);
|
2017-01-30 23:36:18 +01:00
|
|
|
if (!match.hasMatch())
|
2020-04-08 17:45:39 +02:00
|
|
|
return Status::NotHandled;
|
2017-01-30 23:36:18 +01:00
|
|
|
const QString filename = match.captured(1);
|
|
|
|
|
bool lineOk = false;
|
|
|
|
|
const int lineNumber = match.captured(2).toInt(&lineOk);
|
|
|
|
|
const QString message = match.captured(4);
|
|
|
|
|
if (!lineOk)
|
2020-04-08 17:45:39 +02:00
|
|
|
return Status::NotHandled;
|
2017-01-30 23:36:18 +01:00
|
|
|
|
|
|
|
|
Task::TaskType type = Task::Unknown;
|
|
|
|
|
|
|
|
|
|
if (warning.match(message).hasMatch())
|
|
|
|
|
type = Task::Warning;
|
|
|
|
|
else if (error.match(message).hasMatch())
|
|
|
|
|
type = Task::Error;
|
|
|
|
|
else
|
2020-04-08 17:45:39 +02:00
|
|
|
return Status::NotHandled;
|
2017-01-30 23:36:18 +01:00
|
|
|
|
2020-04-16 13:53:05 +02:00
|
|
|
const CompileTask t(type, message, absoluteFilePath(FilePath::fromUserInput(filename)),
|
|
|
|
|
lineNumber);
|
|
|
|
|
LinkSpecs linkSpecs;
|
|
|
|
|
addLinkSpecForAbsoluteFilePath(linkSpecs, t.file, t.line, match, 1);
|
|
|
|
|
scheduleTask(t, 1);
|
|
|
|
|
return {Status::Done, linkSpecs};
|
2017-01-30 23:36:18 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
NimCompilerBuildStep::NimCompilerBuildStep(BuildStepList *parentList, Utils::Id id)
|
2019-12-20 17:05:30 +01:00
|
|
|
: AbstractProcessStep(parentList, id)
|
2015-08-26 09:37:55 +02:00
|
|
|
{
|
|
|
|
|
setDefaultDisplayName(tr(Constants::C_NIMCOMPILERBUILDSTEP_DISPLAY));
|
|
|
|
|
setDisplayName(tr(Constants::C_NIMCOMPILERBUILDSTEP_DISPLAY));
|
|
|
|
|
|
|
|
|
|
auto bc = qobject_cast<NimBuildConfiguration *>(buildConfiguration());
|
|
|
|
|
connect(bc, &NimBuildConfiguration::buildDirectoryChanged,
|
|
|
|
|
this, &NimCompilerBuildStep::updateProcessParameters);
|
2018-06-14 15:50:27 +04:30
|
|
|
connect(bc, &BuildConfiguration::environmentChanged,
|
|
|
|
|
this, &NimCompilerBuildStep::updateProcessParameters);
|
2015-08-26 09:37:55 +02:00
|
|
|
connect(this, &NimCompilerBuildStep::outFilePathChanged,
|
|
|
|
|
bc, &NimBuildConfiguration::outFilePathChanged);
|
2020-02-19 11:55:48 +01:00
|
|
|
connect(project(), &ProjectExplorer::Project::fileListChanged,
|
2016-10-20 16:17:22 +02:00
|
|
|
this, &NimCompilerBuildStep::updateTargetNimFile);
|
2015-08-26 09:37:55 +02:00
|
|
|
updateProcessParameters();
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 13:53:05 +02:00
|
|
|
void NimCompilerBuildStep::setupOutputFormatter(OutputFormatter *formatter)
|
2017-01-30 23:36:18 +01:00
|
|
|
{
|
2020-04-16 13:53:05 +02:00
|
|
|
formatter->addLineParser(new NimParser);
|
|
|
|
|
formatter->addLineParsers(target()->kit()->createOutputParsers());
|
|
|
|
|
formatter->addSearchDir(processParameters()->effectiveWorkingDirectory());
|
|
|
|
|
AbstractProcessStep::setupOutputFormatter(formatter);
|
2017-01-30 23:36:18 +01:00
|
|
|
}
|
|
|
|
|
|
2020-08-26 10:48:29 +02:00
|
|
|
NimCompilerBuildStepConfigWidget::NimCompilerBuildStepConfigWidget(NimCompilerBuildStep *buildStep)
|
|
|
|
|
: BuildStepConfigWidget(buildStep)
|
|
|
|
|
, m_buildStep(buildStep)
|
|
|
|
|
{
|
|
|
|
|
setDisplayName(tr(Constants::C_NIMCOMPILERBUILDSTEPWIDGET_DISPLAY));
|
|
|
|
|
setSummaryText(tr(Constants::C_NIMCOMPILERBUILDSTEPWIDGET_SUMMARY));
|
|
|
|
|
|
|
|
|
|
m_targetComboBox = new QComboBox(this);
|
|
|
|
|
|
|
|
|
|
m_additionalArgumentsLineEdit = new QLineEdit(this);
|
|
|
|
|
|
|
|
|
|
m_commandTextEdit = new QTextEdit(this);
|
|
|
|
|
m_commandTextEdit->setEnabled(false);
|
|
|
|
|
m_commandTextEdit->setMinimumSize(QSize(0, 0));
|
|
|
|
|
|
|
|
|
|
m_defaultArgumentsComboBox = new QComboBox(this);
|
|
|
|
|
m_defaultArgumentsComboBox->addItem(tr("None"));
|
|
|
|
|
m_defaultArgumentsComboBox->addItem(tr("Debug"));
|
|
|
|
|
m_defaultArgumentsComboBox->addItem(tr("Release"));
|
|
|
|
|
|
|
|
|
|
auto formLayout = new QFormLayout(this);
|
|
|
|
|
formLayout->addRow(tr("Target:"), m_targetComboBox);
|
|
|
|
|
formLayout->addRow(tr("Default arguments:"), m_defaultArgumentsComboBox);
|
|
|
|
|
formLayout->addRow(tr("Extra arguments:"), m_additionalArgumentsLineEdit);
|
|
|
|
|
formLayout->addRow(tr("Command:"), m_commandTextEdit);
|
|
|
|
|
|
|
|
|
|
// Connect the project signals
|
|
|
|
|
connect(m_buildStep->project(),
|
|
|
|
|
&Project::fileListChanged,
|
|
|
|
|
this,
|
|
|
|
|
&NimCompilerBuildStepConfigWidget::updateUi);
|
|
|
|
|
|
|
|
|
|
// Connect build step signals
|
|
|
|
|
connect(m_buildStep, &NimCompilerBuildStep::processParametersChanged,
|
|
|
|
|
this, &NimCompilerBuildStepConfigWidget::updateUi);
|
|
|
|
|
|
|
|
|
|
// Connect UI signals
|
|
|
|
|
connect(m_targetComboBox, QOverload<int>::of(&QComboBox::activated),
|
|
|
|
|
this, &NimCompilerBuildStepConfigWidget::onTargetChanged);
|
|
|
|
|
connect(m_additionalArgumentsLineEdit, &QLineEdit::textEdited,
|
|
|
|
|
this, &NimCompilerBuildStepConfigWidget::onAdditionalArgumentsTextEdited);
|
|
|
|
|
connect(m_defaultArgumentsComboBox, QOverload<int>::of(&QComboBox::activated),
|
|
|
|
|
this, &NimCompilerBuildStepConfigWidget::onDefaultArgumentsComboBoxIndexChanged);
|
|
|
|
|
|
|
|
|
|
updateUi();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-26 09:37:55 +02:00
|
|
|
BuildStepConfigWidget *NimCompilerBuildStep::createConfigWidget()
|
|
|
|
|
{
|
|
|
|
|
return new NimCompilerBuildStepConfigWidget(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NimCompilerBuildStep::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
|
|
|
|
AbstractProcessStep::fromMap(map);
|
2017-06-12 14:23:34 +02:00
|
|
|
m_userCompilerOptions = map[Constants::C_NIMCOMPILERBUILDSTEP_USERCOMPILEROPTIONS].toString().split('|');
|
2015-08-26 09:37:55 +02:00
|
|
|
m_defaultOptions = static_cast<DefaultBuildOptions>(map[Constants::C_NIMCOMPILERBUILDSTEP_DEFAULTBUILDOPTIONS].toInt());
|
2019-05-28 13:49:26 +02:00
|
|
|
m_targetNimFile = FilePath::fromString(map[Constants::C_NIMCOMPILERBUILDSTEP_TARGETNIMFILE].toString());
|
2015-08-26 09:37:55 +02:00
|
|
|
updateProcessParameters();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap NimCompilerBuildStep::toMap() const
|
|
|
|
|
{
|
|
|
|
|
QVariantMap result = AbstractProcessStep::toMap();
|
2017-06-12 14:23:34 +02:00
|
|
|
result[Constants::C_NIMCOMPILERBUILDSTEP_USERCOMPILEROPTIONS] = m_userCompilerOptions.join('|');
|
2015-08-26 09:37:55 +02:00
|
|
|
result[Constants::C_NIMCOMPILERBUILDSTEP_DEFAULTBUILDOPTIONS] = m_defaultOptions;
|
|
|
|
|
result[Constants::C_NIMCOMPILERBUILDSTEP_TARGETNIMFILE] = m_targetNimFile.toString();
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList NimCompilerBuildStep::userCompilerOptions() const
|
|
|
|
|
{
|
|
|
|
|
return m_userCompilerOptions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NimCompilerBuildStep::setUserCompilerOptions(const QStringList &options)
|
|
|
|
|
{
|
|
|
|
|
m_userCompilerOptions = options;
|
|
|
|
|
emit userCompilerOptionsChanged(options);
|
|
|
|
|
updateProcessParameters();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NimCompilerBuildStep::DefaultBuildOptions NimCompilerBuildStep::defaultCompilerOptions() const
|
|
|
|
|
{
|
|
|
|
|
return m_defaultOptions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NimCompilerBuildStep::setDefaultCompilerOptions(NimCompilerBuildStep::DefaultBuildOptions options)
|
|
|
|
|
{
|
|
|
|
|
if (m_defaultOptions == options)
|
|
|
|
|
return;
|
|
|
|
|
m_defaultOptions = options;
|
|
|
|
|
emit defaultCompilerOptionsChanged(options);
|
|
|
|
|
updateProcessParameters();
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
FilePath NimCompilerBuildStep::targetNimFile() const
|
2015-08-26 09:37:55 +02:00
|
|
|
{
|
|
|
|
|
return m_targetNimFile;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
void NimCompilerBuildStep::setTargetNimFile(const FilePath &targetNimFile)
|
2015-08-26 09:37:55 +02:00
|
|
|
{
|
|
|
|
|
if (targetNimFile == m_targetNimFile)
|
|
|
|
|
return;
|
|
|
|
|
m_targetNimFile = targetNimFile;
|
|
|
|
|
emit targetNimFileChanged(targetNimFile);
|
|
|
|
|
updateProcessParameters();
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
FilePath NimCompilerBuildStep::outFilePath() const
|
2015-08-26 09:37:55 +02:00
|
|
|
{
|
|
|
|
|
return m_outFilePath;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
void NimCompilerBuildStep::setOutFilePath(const FilePath &outFilePath)
|
2015-08-26 09:37:55 +02:00
|
|
|
{
|
|
|
|
|
if (outFilePath == m_outFilePath)
|
|
|
|
|
return;
|
|
|
|
|
m_outFilePath = outFilePath;
|
|
|
|
|
emit outFilePathChanged(outFilePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NimCompilerBuildStep::updateProcessParameters()
|
|
|
|
|
{
|
|
|
|
|
updateOutFilePath();
|
|
|
|
|
updateCommand();
|
|
|
|
|
updateWorkingDirectory();
|
|
|
|
|
updateEnvironment();
|
|
|
|
|
emit processParametersChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NimCompilerBuildStep::updateOutFilePath()
|
|
|
|
|
{
|
|
|
|
|
const QString targetName = Utils::HostOsInfo::withExecutableSuffix(m_targetNimFile.toFileInfo().baseName());
|
2020-02-19 11:55:48 +01:00
|
|
|
setOutFilePath(buildDirectory().pathAppended(targetName));
|
2015-08-26 09:37:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NimCompilerBuildStep::updateWorkingDirectory()
|
|
|
|
|
{
|
2020-02-19 11:55:48 +01:00
|
|
|
processParameters()->setWorkingDirectory(buildDirectory());
|
2015-08-26 09:37:55 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-21 08:31:37 +02:00
|
|
|
void NimCompilerBuildStep::updateCommand()
|
2015-08-26 09:37:55 +02:00
|
|
|
{
|
|
|
|
|
auto bc = qobject_cast<NimBuildConfiguration *>(buildConfiguration());
|
|
|
|
|
QTC_ASSERT(bc, return);
|
|
|
|
|
|
2019-06-21 08:31:37 +02:00
|
|
|
QTC_ASSERT(target(), return);
|
|
|
|
|
QTC_ASSERT(target()->kit(), return);
|
|
|
|
|
Kit *kit = target()->kit();
|
|
|
|
|
auto tc = dynamic_cast<NimToolChain*>(ToolChainKitAspect::toolChain(kit, Constants::C_NIMLANGUAGE_ID));
|
|
|
|
|
QTC_ASSERT(tc, return);
|
2015-08-26 09:37:55 +02:00
|
|
|
|
2019-06-21 08:31:37 +02:00
|
|
|
CommandLine cmd{tc->compilerCommand()};
|
2015-08-26 09:37:55 +02:00
|
|
|
|
2019-06-21 08:31:37 +02:00
|
|
|
cmd.addArg("c");
|
2015-08-26 09:37:55 +02:00
|
|
|
|
2019-06-21 08:31:37 +02:00
|
|
|
if (m_defaultOptions == Release)
|
|
|
|
|
cmd.addArg("-d:release");
|
|
|
|
|
else if (m_defaultOptions == Debug)
|
|
|
|
|
cmd.addArgs({"--debugInfo", "--lineDir:on"});
|
|
|
|
|
|
|
|
|
|
cmd.addArg("--out:" + m_outFilePath.toString());
|
|
|
|
|
cmd.addArg("--nimCache:" + bc->cacheDirectory().toString());
|
|
|
|
|
|
|
|
|
|
for (const QString &arg : m_userCompilerOptions) {
|
|
|
|
|
if (!arg.isEmpty())
|
|
|
|
|
cmd.addArg(arg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_targetNimFile.isEmpty())
|
|
|
|
|
cmd.addArg(m_targetNimFile.toString());
|
2015-08-26 09:37:55 +02:00
|
|
|
|
2019-06-21 08:31:37 +02:00
|
|
|
processParameters()->setCommandLine(cmd);
|
2015-08-26 09:37:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NimCompilerBuildStep::updateEnvironment()
|
|
|
|
|
{
|
2020-02-19 11:55:48 +01:00
|
|
|
processParameters()->setEnvironment(buildEnvironment());
|
2015-08-26 09:37:55 +02:00
|
|
|
}
|
|
|
|
|
|
2016-10-20 16:17:22 +02:00
|
|
|
void NimCompilerBuildStep::updateTargetNimFile()
|
|
|
|
|
{
|
|
|
|
|
if (!m_targetNimFile.isEmpty())
|
|
|
|
|
return;
|
2019-12-17 14:07:53 +01:00
|
|
|
const Utils::FilePaths nimFiles = project()->files([](const Node *n) {
|
2019-11-22 12:41:15 +01:00
|
|
|
return Project::AllFiles(n) && n->path().endsWith(".nim");
|
|
|
|
|
});
|
2016-10-20 16:17:22 +02:00
|
|
|
if (!nimFiles.isEmpty())
|
|
|
|
|
setTargetNimFile(nimFiles.at(0));
|
2015-08-26 09:37:55 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-26 10:48:29 +02:00
|
|
|
void NimCompilerBuildStepConfigWidget::onTargetChanged(int index)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(index)
|
|
|
|
|
auto data = m_targetComboBox->currentData();
|
|
|
|
|
FilePath path = FilePath::fromString(data.toString());
|
|
|
|
|
m_buildStep->setTargetNimFile(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NimCompilerBuildStepConfigWidget::onDefaultArgumentsComboBoxIndexChanged(int index)
|
|
|
|
|
{
|
|
|
|
|
auto options = static_cast<NimCompilerBuildStep::DefaultBuildOptions>(index);
|
|
|
|
|
m_buildStep->setDefaultCompilerOptions(options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NimCompilerBuildStepConfigWidget::updateUi()
|
|
|
|
|
{
|
|
|
|
|
updateCommandLineText();
|
|
|
|
|
updateTargetComboBox();
|
|
|
|
|
updateAdditionalArgumentsLineEdit();
|
|
|
|
|
updateDefaultArgumentsComboBox();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NimCompilerBuildStepConfigWidget::onAdditionalArgumentsTextEdited(const QString &text)
|
|
|
|
|
{
|
|
|
|
|
m_buildStep->setUserCompilerOptions(text.split(QChar::Space));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NimCompilerBuildStepConfigWidget::updateCommandLineText()
|
|
|
|
|
{
|
|
|
|
|
ProcessParameters *parameters = m_buildStep->processParameters();
|
|
|
|
|
|
|
|
|
|
const CommandLine cmd = parameters->command();
|
|
|
|
|
const QStringList parts = QtcProcess::splitArgs(cmd.toUserOutput());
|
|
|
|
|
|
|
|
|
|
m_commandTextEdit->setText(parts.join(QChar::LineFeed));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NimCompilerBuildStepConfigWidget::updateTargetComboBox()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_buildStep, return );
|
|
|
|
|
|
|
|
|
|
// Re enter the files
|
|
|
|
|
m_targetComboBox->clear();
|
|
|
|
|
|
|
|
|
|
const FilePaths nimFiles = m_buildStep->project()->files([](const Node *n) {
|
|
|
|
|
return Project::AllFiles(n) && n->path().endsWith(".nim");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
for (const FilePath &file : nimFiles)
|
|
|
|
|
m_targetComboBox->addItem(file.fileName(), file.toString());
|
|
|
|
|
|
|
|
|
|
const int index = m_targetComboBox->findData(m_buildStep->targetNimFile().toString());
|
|
|
|
|
m_targetComboBox->setCurrentIndex(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NimCompilerBuildStepConfigWidget::updateAdditionalArgumentsLineEdit()
|
|
|
|
|
{
|
|
|
|
|
const QString text = m_buildStep->userCompilerOptions().join(QChar::Space);
|
|
|
|
|
m_additionalArgumentsLineEdit->setText(text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NimCompilerBuildStepConfigWidget::updateDefaultArgumentsComboBox()
|
|
|
|
|
{
|
|
|
|
|
const int index = m_buildStep->defaultCompilerOptions();
|
|
|
|
|
m_defaultArgumentsComboBox->setCurrentIndex(index);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-17 19:05:42 +01:00
|
|
|
// NimCompilerBuildStepFactory
|
|
|
|
|
|
|
|
|
|
NimCompilerBuildStepFactory::NimCompilerBuildStepFactory()
|
|
|
|
|
{
|
|
|
|
|
registerStep<NimCompilerBuildStep>(Constants::C_NIMCOMPILERBUILDSTEP_ID);
|
2018-05-14 17:50:56 +02:00
|
|
|
setDisplayName(NimCompilerBuildStep::tr("Nim Compiler Build Step"));
|
2018-01-17 19:05:42 +01:00
|
|
|
setSupportedStepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
|
|
|
|
|
setSupportedConfiguration(Constants::C_NIMBUILDCONFIGURATION_ID);
|
|
|
|
|
setRepeatable(false);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-20 16:17:22 +02:00
|
|
|
} // namespace Nim
|
2017-01-30 23:36:18 +01:00
|
|
|
|
|
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
|
|
|
|
|
#include "nimplugin.h"
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/outputparser_test.h>
|
|
|
|
|
|
|
|
|
|
#include <QTest>
|
|
|
|
|
|
|
|
|
|
namespace Nim {
|
|
|
|
|
|
|
|
|
|
void NimPlugin::testNimParser_data()
|
|
|
|
|
{
|
|
|
|
|
QTest::addColumn<QString>("input");
|
|
|
|
|
QTest::addColumn<OutputParserTester::Channel>("inputChannel");
|
|
|
|
|
QTest::addColumn<QString>("childStdOutLines");
|
|
|
|
|
QTest::addColumn<QString>("childStdErrLines");
|
2019-05-27 16:09:44 +02:00
|
|
|
QTest::addColumn<Tasks >("tasks");
|
2017-01-30 23:36:18 +01:00
|
|
|
QTest::addColumn<QString>("outputLines");
|
|
|
|
|
|
|
|
|
|
// negative tests
|
|
|
|
|
QTest::newRow("pass-through stdout")
|
|
|
|
|
<< "Sometext" << OutputParserTester::STDOUT
|
|
|
|
|
<< "Sometext\n" << QString()
|
2019-05-27 16:09:44 +02:00
|
|
|
<< Tasks()
|
2017-01-30 23:36:18 +01:00
|
|
|
<< QString();
|
|
|
|
|
QTest::newRow("pass-through stderr")
|
|
|
|
|
<< "Sometext" << OutputParserTester::STDERR
|
|
|
|
|
<< QString() << "Sometext\n"
|
2019-05-27 16:09:44 +02:00
|
|
|
<< Tasks()
|
2017-01-30 23:36:18 +01:00
|
|
|
<< QString();
|
|
|
|
|
|
|
|
|
|
// positive tests
|
|
|
|
|
QTest::newRow("Parse error string")
|
|
|
|
|
<< QString::fromLatin1("main.nim(23, 1) Error: undeclared identifier: 'x'")
|
|
|
|
|
<< OutputParserTester::STDERR
|
2020-04-08 17:45:39 +02:00
|
|
|
<< QString() << QString()
|
2020-01-15 08:56:11 +01:00
|
|
|
<< Tasks({CompileTask(Task::Error,
|
|
|
|
|
"Error: undeclared identifier: 'x'",
|
|
|
|
|
FilePath::fromUserInput("main.nim"), 23)})
|
2017-01-30 23:36:18 +01:00
|
|
|
<< QString();
|
|
|
|
|
|
|
|
|
|
QTest::newRow("Parse warning string")
|
|
|
|
|
<< QString::fromLatin1("lib/pure/parseopt.nim(56, 34) Warning: quoteIfContainsWhite is deprecated [Deprecated]")
|
|
|
|
|
<< OutputParserTester::STDERR
|
2020-04-08 17:45:39 +02:00
|
|
|
<< QString() << QString()
|
2020-01-15 08:56:11 +01:00
|
|
|
<< Tasks({CompileTask(Task::Warning,
|
|
|
|
|
"Warning: quoteIfContainsWhite is deprecated [Deprecated]",
|
|
|
|
|
FilePath::fromUserInput("lib/pure/parseopt.nim"), 56)})
|
2017-01-30 23:36:18 +01:00
|
|
|
<< QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NimPlugin::testNimParser()
|
|
|
|
|
{
|
|
|
|
|
OutputParserTester testbench;
|
2020-04-08 17:45:39 +02:00
|
|
|
testbench.addLineParser(new NimParser);
|
2017-01-30 23:36:18 +01:00
|
|
|
QFETCH(QString, input);
|
|
|
|
|
QFETCH(OutputParserTester::Channel, inputChannel);
|
2019-05-27 16:09:44 +02:00
|
|
|
QFETCH(Tasks, tasks);
|
2017-01-30 23:36:18 +01:00
|
|
|
QFETCH(QString, childStdOutLines);
|
|
|
|
|
QFETCH(QString, childStdErrLines);
|
|
|
|
|
QFETCH(QString, outputLines);
|
|
|
|
|
|
|
|
|
|
testbench.testParsing(input, inputChannel,
|
|
|
|
|
tasks, childStdOutLines, childStdErrLines,
|
|
|
|
|
outputLines);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endif
|