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"
|
2021-02-02 16:47:42 +01:00
|
|
|
#include "nimoutputtaskparser.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 <QComboBox>
|
|
|
|
|
#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-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
|
|
|
{
|
2020-08-31 09:56:10 +02:00
|
|
|
setCommandLineProvider([this] { return commandLine(); });
|
2015-08-26 09:37:55 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
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);
|
2020-09-07 15:56:18 +02:00
|
|
|
formatter->addLineParsers(kit()->createOutputParsers());
|
2020-08-31 09:56:10 +02:00
|
|
|
formatter->addSearchDir(buildDirectory());
|
2020-04-16 13:53:05 +02:00
|
|
|
AbstractProcessStep::setupOutputFormatter(formatter);
|
2017-01-30 23:36:18 +01:00
|
|
|
}
|
|
|
|
|
|
2020-10-02 17:53:39 +02:00
|
|
|
QWidget *NimCompilerBuildStep::createConfigWidget()
|
2020-08-26 10:48:29 +02:00
|
|
|
{
|
2020-10-02 17:53:39 +02:00
|
|
|
auto widget = new QWidget;
|
2020-08-31 09:56:10 +02:00
|
|
|
|
2020-09-14 12:37:32 +02:00
|
|
|
setDisplayName(tr("Nim build step"));
|
|
|
|
|
setSummaryText(tr("Nim build step"));
|
2020-08-31 09:56:10 +02:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
});
|
2020-08-26 10:48:29 +02:00
|
|
|
|
|
|
|
|
updateUi();
|
|
|
|
|
|
2020-08-31 09:56:10 +02:00
|
|
|
return widget;
|
2015-08-26 09:37:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-31 09:56:10 +02:00
|
|
|
void NimCompilerBuildStep::setBuildType(BuildConfiguration::BuildType buildType)
|
|
|
|
|
{
|
|
|
|
|
switch (buildType) {
|
|
|
|
|
case BuildConfiguration::Release:
|
|
|
|
|
m_defaultOptions = DefaultBuildOptions::Release;
|
|
|
|
|
break;
|
|
|
|
|
case BuildConfiguration::Debug:
|
|
|
|
|
m_defaultOptions = DefaultBuildOptions::Debug;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
m_defaultOptions = DefaultBuildOptions::Empty;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-08-26 09:37:55 +02:00
|
|
|
|
2020-08-31 09:56:10 +02:00
|
|
|
updateTargetNimFile();
|
2015-08-26 09:37:55 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-31 09:56:10 +02:00
|
|
|
CommandLine NimCompilerBuildStep::commandLine()
|
2015-08-26 09:37:55 +02:00
|
|
|
{
|
|
|
|
|
auto bc = qobject_cast<NimBuildConfiguration *>(buildConfiguration());
|
2020-08-31 09:56:10 +02:00
|
|
|
QTC_ASSERT(bc, return {});
|
2015-08-26 09:37:55 +02:00
|
|
|
|
2020-09-07 15:56:18 +02:00
|
|
|
auto tc = ToolChainKitAspect::toolChain(kit(), Constants::C_NIMLANGUAGE_ID);
|
2020-08-31 09:56:10 +02:00
|
|
|
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"});
|
|
|
|
|
|
2020-08-31 09:56:10 +02:00
|
|
|
cmd.addArg("--out:" + outFilePath().toString());
|
2019-06-21 08:31:37 +02:00
|
|
|
cmd.addArg("--nimCache:" + bc->cacheDirectory().toString());
|
|
|
|
|
|
2021-02-15 10:03:57 +01:00
|
|
|
for (const QString &arg : qAsConst(m_userCompilerOptions)) {
|
2019-06-21 08:31:37 +02:00
|
|
|
if (!arg.isEmpty())
|
|
|
|
|
cmd.addArg(arg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_targetNimFile.isEmpty())
|
|
|
|
|
cmd.addArg(m_targetNimFile.toString());
|
2015-08-26 09:37:55 +02:00
|
|
|
|
2020-08-31 09:56:10 +02:00
|
|
|
return cmd;
|
2015-08-26 09:37:55 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-31 09:56:10 +02:00
|
|
|
FilePath NimCompilerBuildStep::outFilePath() const
|
2015-08-26 09:37:55 +02:00
|
|
|
{
|
2020-08-31 09:56:10 +02:00
|
|
|
const QString targetName = m_targetNimFile.toFileInfo().baseName();
|
|
|
|
|
return buildDirectory().pathAppended(HostOsInfo::withExecutableSuffix(targetName));
|
2015-08-26 09:37:55 +02:00
|
|
|
}
|
|
|
|
|
|
2016-10-20 16:17:22 +02:00
|
|
|
void NimCompilerBuildStep::updateTargetNimFile()
|
|
|
|
|
{
|
|
|
|
|
if (!m_targetNimFile.isEmpty())
|
|
|
|
|
return;
|
2020-08-26 10:48:29 +02:00
|
|
|
|
2020-08-31 09:56:10 +02:00
|
|
|
const FilePaths files = project()->files(Project::AllFiles);
|
|
|
|
|
for (const FilePath &file : files) {
|
|
|
|
|
if (file.endsWith(".nim")) {
|
|
|
|
|
m_targetNimFile = file;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-26 10:48:29 +02:00
|
|
|
}
|
|
|
|
|
|
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
|