Nim: Merge Toolchain related file pairs

Change-Id: Ia8526bc55934e6f2b29aa291a6269050309e3b4f
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2023-07-27 13:08:20 +02:00
parent fa2124f037
commit 209f3ba579
7 changed files with 151 additions and 184 deletions

View File

@@ -24,7 +24,6 @@ add_qtc_plugin(Nim
project/nimproject.cpp project/nimproject.h
project/nimrunconfiguration.cpp project/nimrunconfiguration.h
project/nimtoolchain.cpp project/nimtoolchain.h
project/nimtoolchainfactory.cpp project/nimtoolchainfactory.h
settings/nimcodestylepreferencesfactory.cpp settings/nimcodestylepreferencesfactory.h
settings/nimcodestylepreferenceswidget.cpp settings/nimcodestylepreferenceswidget.h
settings/nimcodestylesettingspage.cpp settings/nimcodestylesettingspage.h

View File

@@ -46,7 +46,6 @@ QtcPlugin {
"nimproject.h", "nimproject.cpp",
"nimrunconfiguration.h", "nimrunconfiguration.cpp",
"nimtoolchain.h", "nimtoolchain.cpp",
"nimtoolchainfactory.h", "nimtoolchainfactory.cpp",
"nimblebuildstep.h", "nimblebuildstep.cpp",
"nimbleproject.h", "nimbleproject.cpp",
"nimblerunconfiguration.h", "nimblerunconfiguration.cpp",

View File

@@ -14,7 +14,7 @@
#include "project/nimproject.h"
#include "project/nimbleproject.h"
#include "project/nimrunconfiguration.h"
#include "project/nimtoolchainfactory.h"
#include "project/nimtoolchain.h"
#include "project/nimblebuildstep.h"
#include "project/nimbletaskstep.h"
#include "settings/nimcodestylepreferencesfactory.h"

View File

@@ -4,13 +4,22 @@
#include "nimtoolchain.h"
#include "nimconstants.h"
#include "nimtoolchainfactory.h"
#include "nimtoolchain.h"
#include "nimtr.h"
#include <projectexplorer/abi.h>
#include <utils/environment.h>
#include <utils/process.h>
#include <projectexplorer/devicesupport/devicemanager.h>
#include <projectexplorer/toolchainconfigwidget.h>
#include <utils/algorithm.h>
#include <utils/environment.h>
#include <utils/environment.h>
#include <utils/fileutils.h>
#include <utils/pathchooser.h>
#include <utils/process.h>
#include <utils/qtcassert.h>
#include <QFormLayout>
#include <QRegularExpression>
using namespace ProjectExplorer;
@@ -70,11 +79,6 @@ QList<Utils::OutputLineParser *> NimToolChain::createOutputParsers() const
return {};
}
std::unique_ptr<ProjectExplorer::ToolChainConfigWidget> NimToolChain::createConfigurationWidget()
{
return std::make_unique<NimToolChainConfigWidget>(this);
}
QString NimToolChain::compilerVersion() const
{
return compilerCommand().isEmpty() || m_version == std::make_tuple(-1,-1,-1)
@@ -114,4 +118,133 @@ bool NimToolChain::parseVersion(const FilePath &path, std::tuple<int, int, int>
return true;
}
// NimToolChainConfigWidget
class NimToolChainConfigWidget : public ToolChainConfigWidget
{
public:
explicit NimToolChainConfigWidget(NimToolChain *tc)
: ToolChainConfigWidget(tc)
, m_compilerCommand(new PathChooser)
, m_compilerVersion(new QLineEdit)
{
// Create ui
const auto gnuVersionArgs = QStringList("--version");
m_compilerCommand->setExpectedKind(PathChooser::ExistingCommand);
m_compilerCommand->setCommandVersionArguments(gnuVersionArgs);
m_mainLayout->addRow(Tr::tr("&Compiler path:"), m_compilerCommand);
m_compilerVersion->setReadOnly(true);
m_mainLayout->addRow(Tr::tr("&Compiler version:"), m_compilerVersion);
// Fill
fillUI();
// Connect
connect(m_compilerCommand, &PathChooser::validChanged, this, [this] {
const FilePath path = m_compilerCommand->rawFilePath();
auto tc = static_cast<NimToolChain *>(toolChain());
QTC_ASSERT(tc, return);
tc->setCompilerCommand(path);
fillUI();
});
}
protected:
void applyImpl() final;
void discardImpl() final;
bool isDirtyImpl() const final;
void makeReadOnlyImpl() final;
private:
void fillUI();
Utils::PathChooser *m_compilerCommand;
QLineEdit *m_compilerVersion;
};
void NimToolChainConfigWidget::applyImpl()
{
auto tc = static_cast<NimToolChain *>(toolChain());
Q_ASSERT(tc);
if (tc->isAutoDetected())
return;
tc->setCompilerCommand(m_compilerCommand->filePath());
}
void NimToolChainConfigWidget::discardImpl()
{
fillUI();
}
bool NimToolChainConfigWidget::isDirtyImpl() const
{
auto tc = static_cast<NimToolChain *>(toolChain());
Q_ASSERT(tc);
return tc->compilerCommand() != m_compilerCommand->filePath();
}
void NimToolChainConfigWidget::makeReadOnlyImpl()
{
m_compilerCommand->setReadOnly(true);
}
void NimToolChainConfigWidget::fillUI()
{
auto tc = static_cast<NimToolChain *>(toolChain());
Q_ASSERT(tc);
m_compilerCommand->setFilePath(tc->compilerCommand());
m_compilerVersion->setText(tc->compilerVersion());
}
std::unique_ptr<ToolChainConfigWidget> NimToolChain::createConfigurationWidget()
{
return std::make_unique<NimToolChainConfigWidget>(this);
}
// NimToolChainFactory
NimToolChainFactory::NimToolChainFactory()
{
setDisplayName(Tr::tr("Nim"));
setSupportedToolChainType(Constants::C_NIMTOOLCHAIN_TYPEID);
setSupportedLanguages({Constants::C_NIMLANGUAGE_ID});
setToolchainConstructor([] { return new NimToolChain; });
setUserCreatable(true);
}
Toolchains NimToolChainFactory::autoDetect(const ToolchainDetector &detector) const
{
Toolchains result;
const FilePath compilerPath = detector.device->searchExecutableInPath("nim");
if (compilerPath.isEmpty())
return result;
result = Utils::filtered(detector.alreadyKnown, [compilerPath](ToolChain *tc) {
return tc->typeId() == Constants::C_NIMTOOLCHAIN_TYPEID
&& tc->compilerCommand() == compilerPath;
});
if (!result.empty())
return result;
auto tc = new NimToolChain;
tc->setDetection(ToolChain::AutoDetection);
tc->setCompilerCommand(compilerPath);
result.append(tc);
return result;
}
Toolchains NimToolChainFactory::detectForImport(const ToolChainDescription &tcd) const
{
Toolchains result;
if (tcd.language == Constants::C_NIMLANGUAGE_ID) {
auto tc = new NimToolChain;
tc->setDetection(ToolChain::ManualDetection); // FIXME: sure?
tc->setCompilerCommand(tcd.compilerPath);
result.append(tc);
}
return result;
}
} // Nim

View File

@@ -34,4 +34,13 @@ private:
std::tuple<int, int, int> m_version;
};
class NimToolChainFactory : public ProjectExplorer::ToolChainFactory
{
public:
NimToolChainFactory();
ProjectExplorer::Toolchains autoDetect(const ProjectExplorer::ToolchainDetector &detector) const final;
ProjectExplorer::Toolchains detectForImport(const ProjectExplorer::ToolChainDescription &tcd) const final;
};
} // Nim

View File

@@ -1,129 +0,0 @@
// Copyright (C) Filippo Cucchetto <filippocucchetto@gmail.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "nimtoolchainfactory.h"
#include "nimconstants.h"
#include "nimtoolchain.h"
#include "nimtr.h"
#include <projectexplorer/devicesupport/devicemanager.h>
#include <utils/algorithm.h>
#include <utils/environment.h>
#include <utils/fileutils.h>
#include <utils/pathchooser.h>
#include <utils/qtcassert.h>
#include <QFormLayout>
using namespace ProjectExplorer;
using namespace Utils;
namespace Nim {
NimToolChainFactory::NimToolChainFactory()
{
setDisplayName(Tr::tr("Nim"));
setSupportedToolChainType(Constants::C_NIMTOOLCHAIN_TYPEID);
setSupportedLanguages({Constants::C_NIMLANGUAGE_ID});
setToolchainConstructor([] { return new NimToolChain; });
setUserCreatable(true);
}
Toolchains NimToolChainFactory::autoDetect(const ToolchainDetector &detector) const
{
Toolchains result;
const FilePath compilerPath = detector.device->searchExecutableInPath("nim");
if (compilerPath.isEmpty())
return result;
result = Utils::filtered(detector.alreadyKnown, [compilerPath](ToolChain *tc) {
return tc->typeId() == Constants::C_NIMTOOLCHAIN_TYPEID
&& tc->compilerCommand() == compilerPath;
});
if (!result.empty())
return result;
auto tc = new NimToolChain;
tc->setDetection(ToolChain::AutoDetection);
tc->setCompilerCommand(compilerPath);
result.append(tc);
return result;
}
Toolchains NimToolChainFactory::detectForImport(const ToolChainDescription &tcd) const
{
Toolchains result;
if (tcd.language == Constants::C_NIMLANGUAGE_ID) {
auto tc = new NimToolChain;
tc->setDetection(ToolChain::ManualDetection); // FIXME: sure?
tc->setCompilerCommand(tcd.compilerPath);
result.append(tc);
}
return result;
}
NimToolChainConfigWidget::NimToolChainConfigWidget(NimToolChain *tc)
: ToolChainConfigWidget(tc)
, m_compilerCommand(new PathChooser)
, m_compilerVersion(new QLineEdit)
{
// Create ui
const auto gnuVersionArgs = QStringList("--version");
m_compilerCommand->setExpectedKind(PathChooser::ExistingCommand);
m_compilerCommand->setCommandVersionArguments(gnuVersionArgs);
m_mainLayout->addRow(Tr::tr("&Compiler path:"), m_compilerCommand);
m_compilerVersion->setReadOnly(true);
m_mainLayout->addRow(Tr::tr("&Compiler version:"), m_compilerVersion);
// Fill
fillUI();
// Connect
connect(m_compilerCommand, &PathChooser::validChanged, this, [this] {
const FilePath path = m_compilerCommand->rawFilePath();
auto tc = static_cast<NimToolChain *>(toolChain());
QTC_ASSERT(tc, return);
tc->setCompilerCommand(path);
fillUI();
});
}
void NimToolChainConfigWidget::applyImpl()
{
auto tc = static_cast<NimToolChain *>(toolChain());
Q_ASSERT(tc);
if (tc->isAutoDetected())
return;
tc->setCompilerCommand(m_compilerCommand->filePath());
}
void NimToolChainConfigWidget::discardImpl()
{
fillUI();
}
bool NimToolChainConfigWidget::isDirtyImpl() const
{
auto tc = static_cast<NimToolChain *>(toolChain());
Q_ASSERT(tc);
return tc->compilerCommand() != m_compilerCommand->filePath();
}
void NimToolChainConfigWidget::makeReadOnlyImpl()
{
m_compilerCommand->setReadOnly(true);
}
void NimToolChainConfigWidget::fillUI()
{
auto tc = static_cast<NimToolChain *>(toolChain());
Q_ASSERT(tc);
m_compilerCommand->setFilePath(tc->compilerCommand());
m_compilerVersion->setText(tc->compilerVersion());
}
}

View File

@@ -1,44 +0,0 @@
// Copyright (C) Filippo Cucchetto <filippocucchetto@gmail.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include <projectexplorer/toolchain.h>
#include <projectexplorer/toolchainconfigwidget.h>
namespace Utils { class PathChooser; }
namespace Nim {
class NimToolChain;
class NimToolChainFactory : public ProjectExplorer::ToolChainFactory
{
public:
NimToolChainFactory();
ProjectExplorer::Toolchains autoDetect(const ProjectExplorer::ToolchainDetector &detector) const final;
ProjectExplorer::Toolchains detectForImport(const ProjectExplorer::ToolChainDescription &tcd) const final;
};
class NimToolChainConfigWidget : public ProjectExplorer::ToolChainConfigWidget
{
Q_OBJECT
public:
explicit NimToolChainConfigWidget(NimToolChain *tc);
protected:
void applyImpl() final;
void discardImpl() final;
bool isDirtyImpl() const final;
void makeReadOnlyImpl() final;
private:
void fillUI();
Utils::PathChooser *m_compilerCommand;
QLineEdit *m_compilerVersion;
};
} // Nim