diff options
author | Christian Kandeler <[email protected]> | 2024-07-11 13:03:12 +0200 |
---|---|---|
committer | Christian Kandeler <[email protected]> | 2024-08-05 15:35:48 +0000 |
commit | 020883c47f62151684f5d72cb7204b6fc7061934 (patch) | |
tree | 590a4bf2b2674b2283cc52854e2342400e73f08d /src/plugins/nim | |
parent | 08d6b861623067eab11eeb7869228540e463fac7 (diff) |
ProjectExplorer: Stop pretending that C and C++ compilers are unrelated
Motivation:
a) It was ridiculous that when users wanted to manually
add a new toolchain, they had to do the entire setup twice.
b) It was equally weird that users had to take care to choose
matching toolchains when setting up a kit, or indeed that it was
even possible to mix random toolchains in the first place.
User-visible changes:
- The "C" and "C++" categories in the toolchain settings page have
been merged into a single "C/C++" category.
- When adding a new toolchain, the "C" and "C++" sub-menus are gone.
Instead, the toolchain config widget offers two path choosers if
the respective toolchain type supports C and C++ compilers.
- By default, the C++ compiler file path is derived from the C
compiler file path automatically, so the user usually has
to enter only the former.
- In the kit settings page, the "C" and "C++" toolchain combo boxes
have been replaced by a single "C/C++" combo box, relieving the user
of the responsibility to choose two matching toolchains.
Implementation:
The notion that a Toolchain object corresponds to a single compiler is so
deeply engrained in the code that it cannot realistically be changed in
the short term. We therefore introduce the concept of a "toolchain
bundle" as an additional layer that groups matching C and C++ toolchains
together. This way, most code dealing with toolchains stays unchanged,
and only the presentation layer (i.e. the toolchain and kit settings
pages) needed to be rewritten. Once set up in a bundle, toolchains stay
implicitly linked together so the matching only needs to be done once.
In follow-up patches, we will make use of toolchain bundles in all the
places where kits are auto-created, eliminating the risk of mixing
incompatible toolchains in a kit.
Change-Id: Ie6c5add9963e7c1096268dd77acd624671b2674f
Reviewed-by: Christian Stenger <[email protected]>
Reviewed-by: hjk <[email protected]>
Diffstat (limited to 'src/plugins/nim')
-rw-r--r-- | src/plugins/nim/project/nimtoolchain.cpp | 57 | ||||
-rw-r--r-- | src/plugins/nim/project/nimtoolchain.h | 3 |
2 files changed, 18 insertions, 42 deletions
diff --git a/src/plugins/nim/project/nimtoolchain.cpp b/src/plugins/nim/project/nimtoolchain.cpp index 701883de0c0..d333e618537 100644 --- a/src/plugins/nim/project/nimtoolchain.cpp +++ b/src/plugins/nim/project/nimtoolchain.cpp @@ -123,16 +123,12 @@ bool NimToolchain::parseVersion(const FilePath &path, std::tuple<int, int, int> class NimToolchainConfigWidget : public ToolchainConfigWidget { public: - explicit NimToolchainConfigWidget(NimToolchain *tc) - : ToolchainConfigWidget(tc) - , m_compilerCommand(new PathChooser) + explicit NimToolchainConfigWidget(const ToolchainBundle &bundle) + : ToolchainConfigWidget(bundle) , 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); + setCommandVersionArguments({"--version"}); m_compilerVersion->setReadOnly(true); m_mainLayout->addRow(Tr::tr("&Compiler version:"), m_compilerVersion); @@ -140,11 +136,9 @@ public: fillUI(); // Connect - connect(m_compilerCommand, &PathChooser::validChanged, this, [this] { - const FilePath path = m_compilerCommand->unexpandedFilePath(); - auto tc = static_cast<NimToolchain *>(toolchain()); - QTC_ASSERT(tc, return); - tc->setCompilerCommand(path); + connect(this, &ToolchainConfigWidget::compilerCommandChanged, this, [this] { + const FilePath path = compilerCommand(Constants::C_NIMLANGUAGE_ID); + this->bundle().setCompilerCommand(Constants::C_NIMLANGUAGE_ID, path); fillUI(); }); } @@ -158,47 +152,22 @@ protected: 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::applyImpl() {} 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); -} +bool NimToolchainConfigWidget::isDirtyImpl() const { return false; } +void NimToolchainConfigWidget::makeReadOnlyImpl() {} 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); + m_compilerVersion->setText(bundle().get(&NimToolchain::compilerVersion)); } // NimToolchainFactory @@ -247,4 +216,10 @@ Toolchains NimToolchainFactory::detectForImport(const ToolchainDescription &tcd) return result; } +std::unique_ptr<ToolchainConfigWidget> NimToolchainFactory::createConfigurationWidget( + const ProjectExplorer::ToolchainBundle &bundle) const +{ + return std::make_unique<NimToolchainConfigWidget>(bundle); +} + } // Nim diff --git a/src/plugins/nim/project/nimtoolchain.h b/src/plugins/nim/project/nimtoolchain.h index 6304143d8b8..a97225d702f 100644 --- a/src/plugins/nim/project/nimtoolchain.h +++ b/src/plugins/nim/project/nimtoolchain.h @@ -24,7 +24,6 @@ public: Utils::FilePath makeCommand(const Utils::Environment &env) const final; QString compilerVersion() const; QList<Utils::OutputLineParser *> createOutputParsers() const final; - std::unique_ptr<ProjectExplorer::ToolchainConfigWidget> createConfigurationWidget() final; void fromMap(const Utils::Store &data) final; @@ -41,6 +40,8 @@ public: ProjectExplorer::Toolchains autoDetect(const ProjectExplorer::ToolchainDetector &detector) const final; ProjectExplorer::Toolchains detectForImport(const ProjectExplorer::ToolchainDescription &tcd) const final; + std::unique_ptr<ProjectExplorer::ToolchainConfigWidget> createConfigurationWidget( + const ProjectExplorer::ToolchainBundle &bundle) const final; }; } // Nim |