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:
@@ -39,9 +39,7 @@
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QComboBox>
|
||||
#include <QDir>
|
||||
#include <QFormLayout>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
@@ -53,31 +51,6 @@ using namespace Utils;
|
||||
|
||||
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
|
||||
|
||||
class NimParser : public ProjectExplorer::OutputTaskParser
|
||||
@@ -122,77 +95,93 @@ NimCompilerBuildStep::NimCompilerBuildStep(BuildStepList *parentList, Utils::Id
|
||||
{
|
||||
setDefaultDisplayName(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,
|
||||
this, &NimCompilerBuildStep::updateTargetNimFile);
|
||||
updateProcessParameters();
|
||||
}
|
||||
|
||||
void NimCompilerBuildStep::setupOutputFormatter(OutputFormatter *formatter)
|
||||
{
|
||||
formatter->addLineParser(new NimParser);
|
||||
formatter->addLineParsers(target()->kit()->createOutputParsers());
|
||||
formatter->addSearchDir(processParameters()->effectiveWorkingDirectory());
|
||||
formatter->addSearchDir(buildDirectory());
|
||||
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()
|
||||
{
|
||||
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)
|
||||
@@ -201,7 +190,6 @@ bool NimCompilerBuildStep::fromMap(const QVariantMap &map)
|
||||
m_userCompilerOptions = map[Constants::C_NIMCOMPILERBUILDSTEP_USERCOMPILEROPTIONS].toString().split('|');
|
||||
m_defaultOptions = static_cast<DefaultBuildOptions>(map[Constants::C_NIMCOMPILERBUILDSTEP_DEFAULTBUILDOPTIONS].toInt());
|
||||
m_targetNimFile = FilePath::fromString(map[Constants::C_NIMCOMPILERBUILDSTEP_TARGETNIMFILE].toString());
|
||||
updateProcessParameters();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -214,89 +202,41 @@ QVariantMap NimCompilerBuildStep::toMap() const
|
||||
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;
|
||||
emit userCompilerOptionsChanged(options);
|
||||
updateProcessParameters();
|
||||
switch (buildType) {
|
||||
case BuildConfiguration::Release:
|
||||
m_defaultOptions = DefaultBuildOptions::Release;
|
||||
break;
|
||||
case BuildConfiguration::Debug:
|
||||
m_defaultOptions = DefaultBuildOptions::Debug;
|
||||
break;
|
||||
default:
|
||||
m_defaultOptions = DefaultBuildOptions::Empty;
|
||||
break;
|
||||
}
|
||||
|
||||
updateTargetNimFile();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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()
|
||||
CommandLine NimCompilerBuildStep::commandLine()
|
||||
{
|
||||
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();
|
||||
auto tc = dynamic_cast<NimToolChain*>(ToolChainKitAspect::toolChain(kit, Constants::C_NIMLANGUAGE_ID));
|
||||
QTC_ASSERT(tc, return);
|
||||
auto tc = ToolChainKitAspect::toolChain(kit, Constants::C_NIMLANGUAGE_ID);
|
||||
QTC_ASSERT(tc, return {});
|
||||
|
||||
CommandLine cmd{tc->compilerCommand()};
|
||||
|
||||
@@ -307,7 +247,7 @@ void NimCompilerBuildStep::updateCommand()
|
||||
else if (m_defaultOptions == Debug)
|
||||
cmd.addArgs({"--debugInfo", "--lineDir:on"});
|
||||
|
||||
cmd.addArg("--out:" + m_outFilePath.toString());
|
||||
cmd.addArg("--out:" + outFilePath().toString());
|
||||
cmd.addArg("--nimCache:" + bc->cacheDirectory().toString());
|
||||
|
||||
for (const QString &arg : m_userCompilerOptions) {
|
||||
@@ -318,90 +258,27 @@ void NimCompilerBuildStep::updateCommand()
|
||||
if (!m_targetNimFile.isEmpty())
|
||||
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()
|
||||
{
|
||||
if (!m_targetNimFile.isEmpty())
|
||||
return;
|
||||
const Utils::FilePaths nimFiles = project()->files([](const Node *n) {
|
||||
return Project::AllFiles(n) && n->path().endsWith(".nim");
|
||||
});
|
||||
if (!nimFiles.isEmpty())
|
||||
setTargetNimFile(nimFiles.at(0));
|
||||
}
|
||||
|
||||
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);
|
||||
const FilePaths files = project()->files(Project::AllFiles);
|
||||
for (const FilePath &file : files) {
|
||||
if (file.endsWith(".nim")) {
|
||||
m_targetNimFile = file;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NimCompilerBuildStepFactory
|
||||
|
||||
Reference in New Issue
Block a user