forked from qt-creator/qt-creator
Nim: Rework NimCompilerBuildStep
Use new ProjectExplorer infrastructure. Change-Id: Id8fed337895f9f18fec44f4756493f40ea07f3da Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -65,10 +65,6 @@ const QString C_NIMCOMPILERBUILDSTEP_USERCOMPILEROPTIONS = QStringLiteral("Nim.N
|
|||||||
const QString C_NIMCOMPILERBUILDSTEP_DEFAULTBUILDOPTIONS = QStringLiteral("Nim.NimCompilerBuildStep.DefaultBuildOptions");
|
const QString C_NIMCOMPILERBUILDSTEP_DEFAULTBUILDOPTIONS = QStringLiteral("Nim.NimCompilerBuildStep.DefaultBuildOptions");
|
||||||
const QString C_NIMCOMPILERBUILDSTEP_TARGETNIMFILE = QStringLiteral("Nim.NimCompilerBuildStep.TargetNimFile");
|
const QString C_NIMCOMPILERBUILDSTEP_TARGETNIMFILE = QStringLiteral("Nim.NimCompilerBuildStep.TargetNimFile");
|
||||||
|
|
||||||
// NimCompilerBuildStepWidget
|
|
||||||
const char C_NIMCOMPILERBUILDSTEPWIDGET_DISPLAY[] = QT_TRANSLATE_NOOP("NimCompilerBuildStepConfigWidget", "Nim build step");
|
|
||||||
const char C_NIMCOMPILERBUILDSTEPWIDGET_SUMMARY[] = QT_TRANSLATE_NOOP("NimCompilerBuildStepConfigWidget", "Nim build step");
|
|
||||||
|
|
||||||
// NimCompilerCleanStep
|
// NimCompilerCleanStep
|
||||||
const char C_NIMCOMPILERCLEANSTEP_ID[] = "Nim.NimCompilerCleanStep";
|
const char C_NIMCOMPILERCLEANSTEP_ID[] = "Nim.NimCompilerCleanStep";
|
||||||
|
|
||||||
|
@@ -84,26 +84,7 @@ NimBuildConfiguration::NimBuildConfiguration(Target *target, Utils::Id id)
|
|||||||
|
|
||||||
auto nimCompilerBuildStep = buildSteps()->firstOfType<NimCompilerBuildStep>();
|
auto nimCompilerBuildStep = buildSteps()->firstOfType<NimCompilerBuildStep>();
|
||||||
QTC_ASSERT(nimCompilerBuildStep, return);
|
QTC_ASSERT(nimCompilerBuildStep, return);
|
||||||
NimCompilerBuildStep::DefaultBuildOptions defaultOption;
|
nimCompilerBuildStep->setBuildType(info.buildType);
|
||||||
switch (info.buildType) {
|
|
||||||
case BuildConfiguration::Release:
|
|
||||||
defaultOption = NimCompilerBuildStep::DefaultBuildOptions::Release;
|
|
||||||
break;
|
|
||||||
case BuildConfiguration::Debug:
|
|
||||||
defaultOption = NimCompilerBuildStep::DefaultBuildOptions::Debug;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
defaultOption = NimCompilerBuildStep::DefaultBuildOptions::Empty;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
nimCompilerBuildStep->setDefaultCompilerOptions(defaultOption);
|
|
||||||
|
|
||||||
const Utils::FilePaths nimFiles = project()->files([](const Node *n) {
|
|
||||||
return Project::AllFiles(n) && n->path().endsWith(".nim");
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!nimFiles.isEmpty())
|
|
||||||
nimCompilerBuildStep->setTargetNimFile(nimFiles.first());
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,19 +96,12 @@ FilePath NimBuildConfiguration::cacheDirectory() const
|
|||||||
|
|
||||||
FilePath NimBuildConfiguration::outFilePath() const
|
FilePath NimBuildConfiguration::outFilePath() const
|
||||||
{
|
{
|
||||||
const NimCompilerBuildStep *step = nimCompilerBuildStep();
|
auto nimCompilerBuildStep = buildSteps()->firstOfType<NimCompilerBuildStep>();
|
||||||
QTC_ASSERT(step, return FilePath());
|
QTC_ASSERT(nimCompilerBuildStep, return {});
|
||||||
return step->outFilePath();
|
return nimCompilerBuildStep->outFilePath();
|
||||||
}
|
|
||||||
|
|
||||||
const NimCompilerBuildStep *NimBuildConfiguration::nimCompilerBuildStep() const
|
|
||||||
{
|
|
||||||
foreach (BuildStep *step, buildSteps()->steps())
|
|
||||||
if (step->id() == Constants::C_NIMCOMPILERBUILDSTEP_ID)
|
|
||||||
return qobject_cast<NimCompilerBuildStep *>(step);
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NimBuildConfigurationFactory
|
||||||
|
|
||||||
NimBuildConfigurationFactory::NimBuildConfigurationFactory()
|
NimBuildConfigurationFactory::NimBuildConfigurationFactory()
|
||||||
{
|
{
|
||||||
|
@@ -30,8 +30,6 @@
|
|||||||
|
|
||||||
namespace Nim {
|
namespace Nim {
|
||||||
|
|
||||||
class NimCompilerBuildStep;
|
|
||||||
|
|
||||||
class NimBuildConfiguration : public ProjectExplorer::BuildConfiguration
|
class NimBuildConfiguration : public ProjectExplorer::BuildConfiguration
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -42,13 +40,6 @@ class NimBuildConfiguration : public ProjectExplorer::BuildConfiguration
|
|||||||
public:
|
public:
|
||||||
Utils::FilePath cacheDirectory() const;
|
Utils::FilePath cacheDirectory() const;
|
||||||
Utils::FilePath outFilePath() const;
|
Utils::FilePath outFilePath() const;
|
||||||
|
|
||||||
signals:
|
|
||||||
void outFilePathChanged(const Utils::FilePath &outFilePath);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void setupBuild(const ProjectExplorer::BuildInfo *info);
|
|
||||||
const NimCompilerBuildStep *nimCompilerBuildStep() const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -39,9 +39,7 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/qtcprocess.h>
|
#include <utils/qtcprocess.h>
|
||||||
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QDir>
|
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
@@ -53,31 +51,6 @@ using namespace Utils;
|
|||||||
|
|
||||||
namespace Nim {
|
namespace Nim {
|
||||||
|
|
||||||
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
|
// NimParser
|
||||||
|
|
||||||
class NimParser : public ProjectExplorer::OutputTaskParser
|
class NimParser : public ProjectExplorer::OutputTaskParser
|
||||||
@@ -122,77 +95,93 @@ NimCompilerBuildStep::NimCompilerBuildStep(BuildStepList *parentList, Utils::Id
|
|||||||
{
|
{
|
||||||
setDefaultDisplayName(tr(Constants::C_NIMCOMPILERBUILDSTEP_DISPLAY));
|
setDefaultDisplayName(tr(Constants::C_NIMCOMPILERBUILDSTEP_DISPLAY));
|
||||||
setDisplayName(tr(Constants::C_NIMCOMPILERBUILDSTEP_DISPLAY));
|
setDisplayName(tr(Constants::C_NIMCOMPILERBUILDSTEP_DISPLAY));
|
||||||
|
setCommandLineProvider([this] { return commandLine(); });
|
||||||
|
|
||||||
auto bc = qobject_cast<NimBuildConfiguration *>(buildConfiguration());
|
|
||||||
connect(bc, &NimBuildConfiguration::buildDirectoryChanged,
|
|
||||||
this, &NimCompilerBuildStep::updateProcessParameters);
|
|
||||||
connect(bc, &BuildConfiguration::environmentChanged,
|
|
||||||
this, &NimCompilerBuildStep::updateProcessParameters);
|
|
||||||
connect(this, &NimCompilerBuildStep::outFilePathChanged,
|
|
||||||
bc, &NimBuildConfiguration::outFilePathChanged);
|
|
||||||
connect(project(), &ProjectExplorer::Project::fileListChanged,
|
connect(project(), &ProjectExplorer::Project::fileListChanged,
|
||||||
this, &NimCompilerBuildStep::updateTargetNimFile);
|
this, &NimCompilerBuildStep::updateTargetNimFile);
|
||||||
updateProcessParameters();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NimCompilerBuildStep::setupOutputFormatter(OutputFormatter *formatter)
|
void NimCompilerBuildStep::setupOutputFormatter(OutputFormatter *formatter)
|
||||||
{
|
{
|
||||||
formatter->addLineParser(new NimParser);
|
formatter->addLineParser(new NimParser);
|
||||||
formatter->addLineParsers(target()->kit()->createOutputParsers());
|
formatter->addLineParsers(target()->kit()->createOutputParsers());
|
||||||
formatter->addSearchDir(processParameters()->effectiveWorkingDirectory());
|
formatter->addSearchDir(buildDirectory());
|
||||||
AbstractProcessStep::setupOutputFormatter(formatter);
|
AbstractProcessStep::setupOutputFormatter(formatter);
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
BuildStepConfigWidget *NimCompilerBuildStep::createConfigWidget()
|
BuildStepConfigWidget *NimCompilerBuildStep::createConfigWidget()
|
||||||
{
|
{
|
||||||
return new NimCompilerBuildStepConfigWidget(this);
|
auto widget = new BuildStepConfigWidget(this);
|
||||||
|
|
||||||
|
widget->setDisplayName(tr("Nim build step"));
|
||||||
|
widget->setSummaryText(tr("Nim build step"));
|
||||||
|
|
||||||
|
auto targetComboBox = new QComboBox(widget);
|
||||||
|
|
||||||
|
auto additionalArgumentsLineEdit = new QLineEdit(widget);
|
||||||
|
|
||||||
|
auto commandTextEdit = new QTextEdit(widget);
|
||||||
|
commandTextEdit->setEnabled(false);
|
||||||
|
commandTextEdit->setMinimumSize(QSize(0, 0));
|
||||||
|
|
||||||
|
auto defaultArgumentsComboBox = new QComboBox(widget);
|
||||||
|
defaultArgumentsComboBox->addItem(tr("None"));
|
||||||
|
defaultArgumentsComboBox->addItem(tr("Debug"));
|
||||||
|
defaultArgumentsComboBox->addItem(tr("Release"));
|
||||||
|
|
||||||
|
auto formLayout = new QFormLayout(widget);
|
||||||
|
formLayout->addRow(tr("Target:"), targetComboBox);
|
||||||
|
formLayout->addRow(tr("Default arguments:"), defaultArgumentsComboBox);
|
||||||
|
formLayout->addRow(tr("Extra arguments:"), additionalArgumentsLineEdit);
|
||||||
|
formLayout->addRow(tr("Command:"), commandTextEdit);
|
||||||
|
|
||||||
|
auto updateUi = [=] {
|
||||||
|
const CommandLine cmd = commandLine();
|
||||||
|
const QStringList parts = QtcProcess::splitArgs(cmd.toUserOutput());
|
||||||
|
|
||||||
|
commandTextEdit->setText(parts.join(QChar::LineFeed));
|
||||||
|
|
||||||
|
// Re enter the files
|
||||||
|
targetComboBox->clear();
|
||||||
|
const FilePaths files = project()->files(Project::AllFiles);
|
||||||
|
for (const FilePath &file : files) {
|
||||||
|
if (file.endsWith(".nim"))
|
||||||
|
targetComboBox->addItem(file.fileName(), file.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
const int index = targetComboBox->findData(m_targetNimFile.toString());
|
||||||
|
targetComboBox->setCurrentIndex(index);
|
||||||
|
|
||||||
|
const QString text = m_userCompilerOptions.join(QChar::Space);
|
||||||
|
additionalArgumentsLineEdit->setText(text);
|
||||||
|
|
||||||
|
defaultArgumentsComboBox->setCurrentIndex(m_defaultOptions);
|
||||||
|
};
|
||||||
|
|
||||||
|
connect(project(), &Project::fileListChanged, this, updateUi);
|
||||||
|
|
||||||
|
connect(targetComboBox, QOverload<int>::of(&QComboBox::activated),
|
||||||
|
this, [this, targetComboBox, updateUi] {
|
||||||
|
const QVariant data = targetComboBox->currentData();
|
||||||
|
m_targetNimFile = FilePath::fromString(data.toString());
|
||||||
|
updateUi();
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(additionalArgumentsLineEdit, &QLineEdit::textEdited,
|
||||||
|
this, [this, updateUi](const QString &text) {
|
||||||
|
m_userCompilerOptions = text.split(QChar::Space);
|
||||||
|
updateUi();
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(defaultArgumentsComboBox, QOverload<int>::of(&QComboBox::activated),
|
||||||
|
this, [this, updateUi](int index) {
|
||||||
|
m_defaultOptions = static_cast<DefaultBuildOptions>(index);
|
||||||
|
updateUi();
|
||||||
|
});
|
||||||
|
|
||||||
|
updateUi();
|
||||||
|
|
||||||
|
return widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NimCompilerBuildStep::fromMap(const QVariantMap &map)
|
bool NimCompilerBuildStep::fromMap(const QVariantMap &map)
|
||||||
@@ -201,7 +190,6 @@ bool NimCompilerBuildStep::fromMap(const QVariantMap &map)
|
|||||||
m_userCompilerOptions = map[Constants::C_NIMCOMPILERBUILDSTEP_USERCOMPILEROPTIONS].toString().split('|');
|
m_userCompilerOptions = map[Constants::C_NIMCOMPILERBUILDSTEP_USERCOMPILEROPTIONS].toString().split('|');
|
||||||
m_defaultOptions = static_cast<DefaultBuildOptions>(map[Constants::C_NIMCOMPILERBUILDSTEP_DEFAULTBUILDOPTIONS].toInt());
|
m_defaultOptions = static_cast<DefaultBuildOptions>(map[Constants::C_NIMCOMPILERBUILDSTEP_DEFAULTBUILDOPTIONS].toInt());
|
||||||
m_targetNimFile = FilePath::fromString(map[Constants::C_NIMCOMPILERBUILDSTEP_TARGETNIMFILE].toString());
|
m_targetNimFile = FilePath::fromString(map[Constants::C_NIMCOMPILERBUILDSTEP_TARGETNIMFILE].toString());
|
||||||
updateProcessParameters();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,89 +202,41 @@ QVariantMap NimCompilerBuildStep::toMap() const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList NimCompilerBuildStep::userCompilerOptions() const
|
bool NimCompilerBuildStep::init()
|
||||||
{
|
{
|
||||||
return m_userCompilerOptions;
|
if (!AbstractProcessStep::init())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
setupProcessParameters(processParameters());
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NimCompilerBuildStep::setUserCompilerOptions(const QStringList &options)
|
void NimCompilerBuildStep::setBuildType(BuildConfiguration::BuildType buildType)
|
||||||
{
|
{
|
||||||
m_userCompilerOptions = options;
|
switch (buildType) {
|
||||||
emit userCompilerOptionsChanged(options);
|
case BuildConfiguration::Release:
|
||||||
updateProcessParameters();
|
m_defaultOptions = DefaultBuildOptions::Release;
|
||||||
|
break;
|
||||||
|
case BuildConfiguration::Debug:
|
||||||
|
m_defaultOptions = DefaultBuildOptions::Debug;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
m_defaultOptions = DefaultBuildOptions::Empty;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
NimCompilerBuildStep::DefaultBuildOptions NimCompilerBuildStep::defaultCompilerOptions() const
|
updateTargetNimFile();
|
||||||
{
|
|
||||||
return m_defaultOptions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NimCompilerBuildStep::setDefaultCompilerOptions(NimCompilerBuildStep::DefaultBuildOptions options)
|
CommandLine NimCompilerBuildStep::commandLine()
|
||||||
{
|
|
||||||
if (m_defaultOptions == options)
|
|
||||||
return;
|
|
||||||
m_defaultOptions = options;
|
|
||||||
emit defaultCompilerOptionsChanged(options);
|
|
||||||
updateProcessParameters();
|
|
||||||
}
|
|
||||||
|
|
||||||
FilePath NimCompilerBuildStep::targetNimFile() const
|
|
||||||
{
|
|
||||||
return m_targetNimFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NimCompilerBuildStep::setTargetNimFile(const FilePath &targetNimFile)
|
|
||||||
{
|
|
||||||
if (targetNimFile == m_targetNimFile)
|
|
||||||
return;
|
|
||||||
m_targetNimFile = targetNimFile;
|
|
||||||
emit targetNimFileChanged(targetNimFile);
|
|
||||||
updateProcessParameters();
|
|
||||||
}
|
|
||||||
|
|
||||||
FilePath NimCompilerBuildStep::outFilePath() const
|
|
||||||
{
|
|
||||||
return m_outFilePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NimCompilerBuildStep::setOutFilePath(const FilePath &outFilePath)
|
|
||||||
{
|
|
||||||
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());
|
|
||||||
setOutFilePath(buildDirectory().pathAppended(targetName));
|
|
||||||
}
|
|
||||||
|
|
||||||
void NimCompilerBuildStep::updateWorkingDirectory()
|
|
||||||
{
|
|
||||||
processParameters()->setWorkingDirectory(buildDirectory());
|
|
||||||
}
|
|
||||||
|
|
||||||
void NimCompilerBuildStep::updateCommand()
|
|
||||||
{
|
{
|
||||||
auto bc = qobject_cast<NimBuildConfiguration *>(buildConfiguration());
|
auto bc = qobject_cast<NimBuildConfiguration *>(buildConfiguration());
|
||||||
QTC_ASSERT(bc, return);
|
QTC_ASSERT(bc, return {});
|
||||||
|
|
||||||
QTC_ASSERT(target(), return);
|
|
||||||
QTC_ASSERT(target()->kit(), return);
|
|
||||||
Kit *kit = target()->kit();
|
Kit *kit = target()->kit();
|
||||||
auto tc = dynamic_cast<NimToolChain*>(ToolChainKitAspect::toolChain(kit, Constants::C_NIMLANGUAGE_ID));
|
auto tc = ToolChainKitAspect::toolChain(kit, Constants::C_NIMLANGUAGE_ID);
|
||||||
QTC_ASSERT(tc, return);
|
QTC_ASSERT(tc, return {});
|
||||||
|
|
||||||
CommandLine cmd{tc->compilerCommand()};
|
CommandLine cmd{tc->compilerCommand()};
|
||||||
|
|
||||||
@@ -307,7 +247,7 @@ void NimCompilerBuildStep::updateCommand()
|
|||||||
else if (m_defaultOptions == Debug)
|
else if (m_defaultOptions == Debug)
|
||||||
cmd.addArgs({"--debugInfo", "--lineDir:on"});
|
cmd.addArgs({"--debugInfo", "--lineDir:on"});
|
||||||
|
|
||||||
cmd.addArg("--out:" + m_outFilePath.toString());
|
cmd.addArg("--out:" + outFilePath().toString());
|
||||||
cmd.addArg("--nimCache:" + bc->cacheDirectory().toString());
|
cmd.addArg("--nimCache:" + bc->cacheDirectory().toString());
|
||||||
|
|
||||||
for (const QString &arg : m_userCompilerOptions) {
|
for (const QString &arg : m_userCompilerOptions) {
|
||||||
@@ -318,90 +258,27 @@ void NimCompilerBuildStep::updateCommand()
|
|||||||
if (!m_targetNimFile.isEmpty())
|
if (!m_targetNimFile.isEmpty())
|
||||||
cmd.addArg(m_targetNimFile.toString());
|
cmd.addArg(m_targetNimFile.toString());
|
||||||
|
|
||||||
processParameters()->setCommandLine(cmd);
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NimCompilerBuildStep::updateEnvironment()
|
FilePath NimCompilerBuildStep::outFilePath() const
|
||||||
{
|
{
|
||||||
processParameters()->setEnvironment(buildEnvironment());
|
const QString targetName = m_targetNimFile.toFileInfo().baseName();
|
||||||
|
return buildDirectory().pathAppended(HostOsInfo::withExecutableSuffix(targetName));
|
||||||
}
|
}
|
||||||
|
|
||||||
void NimCompilerBuildStep::updateTargetNimFile()
|
void NimCompilerBuildStep::updateTargetNimFile()
|
||||||
{
|
{
|
||||||
if (!m_targetNimFile.isEmpty())
|
if (!m_targetNimFile.isEmpty())
|
||||||
return;
|
return;
|
||||||
const Utils::FilePaths nimFiles = project()->files([](const Node *n) {
|
|
||||||
return Project::AllFiles(n) && n->path().endsWith(".nim");
|
const FilePaths files = project()->files(Project::AllFiles);
|
||||||
});
|
for (const FilePath &file : files) {
|
||||||
if (!nimFiles.isEmpty())
|
if (file.endsWith(".nim")) {
|
||||||
setTargetNimFile(nimFiles.at(0));
|
m_targetNimFile = file;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NimCompilerBuildStepFactory
|
// NimCompilerBuildStepFactory
|
||||||
|
@@ -41,40 +41,20 @@ public:
|
|||||||
|
|
||||||
NimCompilerBuildStep(ProjectExplorer::BuildStepList *parentList, Utils::Id id);
|
NimCompilerBuildStep(ProjectExplorer::BuildStepList *parentList, Utils::Id id);
|
||||||
|
|
||||||
|
void setBuildType(ProjectExplorer::BuildConfiguration::BuildType buildType);
|
||||||
|
Utils::FilePath outFilePath() const;
|
||||||
|
|
||||||
|
private:
|
||||||
void setupOutputFormatter(Utils::OutputFormatter *formatter) override;
|
void setupOutputFormatter(Utils::OutputFormatter *formatter) override;
|
||||||
ProjectExplorer::BuildStepConfigWidget *createConfigWidget() override;
|
ProjectExplorer::BuildStepConfigWidget *createConfigWidget() override;
|
||||||
|
|
||||||
bool fromMap(const QVariantMap &map) override;
|
bool fromMap(const QVariantMap &map) override;
|
||||||
QVariantMap toMap() const override;
|
QVariantMap toMap() const override;
|
||||||
|
|
||||||
QStringList userCompilerOptions() const;
|
bool init() override;
|
||||||
void setUserCompilerOptions(const QStringList &options);
|
|
||||||
|
|
||||||
DefaultBuildOptions defaultCompilerOptions() const;
|
|
||||||
void setDefaultCompilerOptions(DefaultBuildOptions options);
|
|
||||||
|
|
||||||
Utils::FilePath targetNimFile() const;
|
|
||||||
void setTargetNimFile(const Utils::FilePath &targetNimFile);
|
|
||||||
|
|
||||||
Utils::FilePath outFilePath() const;
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void userCompilerOptionsChanged(const QStringList &options);
|
|
||||||
void defaultCompilerOptionsChanged(DefaultBuildOptions options);
|
|
||||||
void targetNimFileChanged(const Utils::FilePath &targetNimFile);
|
|
||||||
void processParametersChanged();
|
|
||||||
void outFilePathChanged(const Utils::FilePath &outFilePath);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void setOutFilePath(const Utils::FilePath &outFilePath);
|
|
||||||
|
|
||||||
void updateOutFilePath();
|
|
||||||
void updateProcessParameters();
|
|
||||||
void updateCommand();
|
|
||||||
void updateWorkingDirectory();
|
|
||||||
void updateEnvironment();
|
|
||||||
|
|
||||||
void updateTargetNimFile();
|
void updateTargetNimFile();
|
||||||
|
Utils::CommandLine commandLine();
|
||||||
|
|
||||||
DefaultBuildOptions m_defaultOptions;
|
DefaultBuildOptions m_defaultOptions;
|
||||||
QStringList m_userCompilerOptions;
|
QStringList m_userCompilerOptions;
|
||||||
|
Reference in New Issue
Block a user