Meson: Hide the tool aspect implementation

Change-Id: Ib8cf56385d7e369a2c185d6cbd62613b4b28bc79
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2024-07-22 11:32:02 +02:00
parent 95cf4a46ff
commit d09063de87
12 changed files with 235 additions and 291 deletions

View File

@@ -35,8 +35,6 @@ add_qtc_plugin(MesonProjectManager
mesonprojectplugin.cpp mesonprojectplugin.cpp
mesonrunconfiguration.cpp mesonrunconfiguration.cpp
mesonrunconfiguration.h mesonrunconfiguration.h
mesontoolkitaspect.cpp
mesontoolkitaspect.h
mesontools.cpp mesontools.cpp
mesontools.h mesontools.h
mesonwrapper.cpp mesonwrapper.cpp
@@ -45,8 +43,6 @@ add_qtc_plugin(MesonProjectManager
ninjabuildstep.h ninjabuildstep.h
ninjaparser.cpp ninjaparser.cpp
ninjaparser.h ninjaparser.h
ninjatoolkitaspect.cpp
ninjatoolkitaspect.h
ninjawrapper.h ninjawrapper.h
projecttree.cpp projecttree.cpp
projecttree.h projecttree.h

View File

@@ -6,8 +6,8 @@
#include "kitdata.h" #include "kitdata.h"
#include "mesonbuildconfiguration.h" #include "mesonbuildconfiguration.h"
#include "mesonprojectmanagertr.h" #include "mesonprojectmanagertr.h"
#include "mesontoolkitaspect.h"
#include "settings.h" #include "settings.h"
#include "toolkitaspectwidget.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
@@ -24,8 +24,6 @@
#include <utils/macroexpander.h> #include <utils/macroexpander.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <optional>
#include <QLoggingCategory> #include <QLoggingCategory>
#define LEAVE_IF_BUSY() \ #define LEAVE_IF_BUSY() \

View File

@@ -5,8 +5,7 @@
#include "mesonpluginconstants.h" #include "mesonpluginconstants.h"
#include "mesonprojectmanagertr.h" #include "mesonprojectmanagertr.h"
#include "mesontoolkitaspect.h" #include "toolkitaspectwidget.h"
#include "ninjatoolkitaspect.h"
#include <coreplugin/icontext.h> #include <coreplugin/icontext.h>

View File

@@ -68,10 +68,6 @@ Project {
"resources_meson.qrc", "resources_meson.qrc",
"settings.cpp", "settings.cpp",
"settings.h", "settings.h",
"mesontoolkitaspect.cpp",
"mesontoolkitaspect.h",
"ninjatoolkitaspect.cpp",
"ninjatoolkitaspect.h",
"toolkitaspectwidget.cpp", "toolkitaspectwidget.cpp",
"toolkitaspectwidget.h", "toolkitaspectwidget.h",
"toolitemsettings.cpp", "toolitemsettings.cpp",

View File

@@ -1,82 +0,0 @@
// Copyright (C) 2020 Alexis Jeandet.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "mesontoolkitaspect.h"
#include "mesonprojectmanagertr.h"
#include "toolkitaspectwidget.h"
#include <utils/qtcassert.h>
using namespace ProjectExplorer;
namespace MesonProjectManager::Internal {
const char TOOL_ID[] = "MesonProjectManager.MesonKitInformation.Meson";
void MesonToolKitAspect::setMesonTool(Kit *kit, Utils::Id id)
{
QTC_ASSERT(kit && id.isValid(), return );
kit->setValue(TOOL_ID, id.toSetting());
}
Utils::Id MesonToolKitAspect::mesonToolId(const Kit *kit)
{
QTC_ASSERT(kit, return {});
return Utils::Id::fromSetting(kit->value(TOOL_ID));
}
// MesonToolKitAspectFactory
class MesonToolKitAspectFactory final : public KitAspectFactory
{
public:
MesonToolKitAspectFactory()
{
setId(TOOL_ID);
setDisplayName(Tr::tr("Meson Tool"));
setDescription(Tr::tr("The Meson tool to use when building a project with Meson.<br>"
"This setting is ignored when using other build systems."));
setPriority(9000);
}
Tasks validate(const Kit *k) const final
{
Tasks tasks;
const auto tool = MesonToolKitAspect::mesonTool(k);
if (tool && !tool->isValid())
tasks << BuildSystemTask{Task::Warning, Tr::tr("Cannot validate this meson executable.")};
return tasks;
}
void setup(Kit *k) final
{
const auto tool = MesonToolKitAspect::mesonTool(k);
if (!tool) {
const auto autoDetected = MesonTools::mesonWrapper();
if (autoDetected)
MesonToolKitAspect::setMesonTool(k, autoDetected->id());
}
}
void fix(Kit *k) final
{
setup(k);
}
KitAspect *createKitAspect(Kit *k) const override
{
return new MesonToolKitAspectImpl{k, this, MesonToolKitAspectImpl::ToolType::Meson};
}
ItemList toUserOutput(const Kit *k) const override
{
const auto tool = MesonToolKitAspect::mesonTool(k);
if (tool)
return {{Tr::tr("Meson"), tool->name()}};
return {{Tr::tr("Meson"), Tr::tr("Unconfigured")}};
}
};
const MesonToolKitAspectFactory theMesonKitAspectFactory;
} // MesonProjectManager::Internal

View File

@@ -1,31 +0,0 @@
// Copyright (C) 2020 Alexis Jeandet.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include "mesontools.h"
#include <projectexplorer/kit.h>
#include <projectexplorer/kitmanager.h>
namespace MesonProjectManager::Internal {
class MesonToolKitAspect final
{
public:
static void setMesonTool(ProjectExplorer::Kit *kit, Utils::Id id);
static Utils::Id mesonToolId(const ProjectExplorer::Kit *kit);
static inline decltype(auto) mesonTool(const ProjectExplorer::Kit *kit)
{
return MesonTools::mesonWrapper(MesonToolKitAspect::mesonToolId(kit));
}
static inline bool isValid(const ProjectExplorer::Kit *kit)
{
auto tool = mesonTool(kit);
return (tool && tool->isValid());
}
};
} // MesonProjectManager::Internal

View File

@@ -3,7 +3,6 @@
#pragma once #pragma once
#include "mesonpluginconstants.h"
#include "mesonwrapper.h" #include "mesonwrapper.h"
#include "ninjawrapper.h" #include "ninjawrapper.h"
#include "toolwrapper.h" #include "toolwrapper.h"

View File

@@ -7,8 +7,8 @@
#include "mesonpluginconstants.h" #include "mesonpluginconstants.h"
#include "mesonprojectmanagertr.h" #include "mesonprojectmanagertr.h"
#include "mesonoutputparser.h" #include "mesonoutputparser.h"
#include "ninjatoolkitaspect.h"
#include "settings.h" #include "settings.h"
#include "toolkitaspectwidget.h"
#include <coreplugin/find/itemviewfind.h> #include <coreplugin/find/itemviewfind.h>

View File

@@ -1,83 +0,0 @@
// Copyright (C) 2020 Alexis Jeandet.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "ninjatoolkitaspect.h"
#include "mesonprojectmanagertr.h"
#include "toolkitaspectwidget.h"
#include <utils/qtcassert.h>
using namespace ProjectExplorer;
namespace MesonProjectManager::Internal {
const char TOOL_ID[] = "MesonProjectManager.MesonKitInformation.Ninja";
void NinjaToolKitAspect::setNinjaTool(ProjectExplorer::Kit *kit, Utils::Id id)
{
QTC_ASSERT(kit && id.isValid(), return );
kit->setValue(TOOL_ID, id.toSetting());
}
Utils::Id NinjaToolKitAspect::ninjaToolId(const ProjectExplorer::Kit *kit)
{
QTC_ASSERT(kit, return {});
return Utils::Id::fromSetting(kit->value(TOOL_ID));
}
// NinjaToolKitAspectFactory
class NinjaToolKitAspectFactory final : public ProjectExplorer::KitAspectFactory
{
public:
NinjaToolKitAspectFactory()
{
setId(TOOL_ID);
setDisplayName(Tr::tr("Ninja Tool"));
setDescription(Tr::tr("The Ninja tool to use when building a project with Meson.<br>"
"This setting is ignored when using other build systems."));
setPriority(9000);
}
Tasks validate(const Kit *k) const final
{
Tasks tasks;
const auto tool = NinjaToolKitAspect::ninjaTool(k);
if (tool && !tool->isValid())
tasks << BuildSystemTask{Task::Warning,
Tr::tr("Cannot validate this Ninja executable.")};
return tasks;
}
void setup(Kit *k) final
{
const auto tool = NinjaToolKitAspect::ninjaTool(k);
if (!tool) {
const auto autoDetected = MesonTools::ninjaWrapper();
if (autoDetected)
NinjaToolKitAspect::setNinjaTool(k, autoDetected->id());
}
}
void fix(Kit *k) final
{
setup(k);
}
ItemList toUserOutput(const Kit *k) const override
{
const auto tool = NinjaToolKitAspect::ninjaTool(k);
if (tool)
return {{Tr::tr("Ninja"), tool->name()}};
return {{Tr::tr("Ninja"), Tr::tr("Unconfigured")}};
}
KitAspect *createKitAspect(Kit *k) const final
{
return new MesonToolKitAspectImpl(k, this, MesonToolKitAspectImpl::ToolType::Ninja);
}
};
const NinjaToolKitAspectFactory theNinjaToolKitAspectFactory;
} // MesonProjectManager::Internal

View File

@@ -1,30 +0,0 @@
// Copyright (C) 2020 Alexis Jeandet.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include "mesontools.h"
#include <projectexplorer/kit.h>
#include <projectexplorer/kitmanager.h>
namespace MesonProjectManager::Internal {
class NinjaToolKitAspect final
{
public:
static void setNinjaTool(ProjectExplorer::Kit *kit, Utils::Id id);
static Utils::Id ninjaToolId(const ProjectExplorer::Kit *kit);
static inline decltype(auto) ninjaTool(const ProjectExplorer::Kit *kit)
{
return MesonTools::ninjaWrapper(NinjaToolKitAspect::ninjaToolId(kit));
}
static inline bool isValid(const ProjectExplorer::Kit *kit)
{
auto tool = ninjaTool(kit);
return (tool && tool->isValid());
}
};
} // MesonProjectManager::Internal

View File

@@ -4,15 +4,63 @@
#include "toolkitaspectwidget.h" #include "toolkitaspectwidget.h"
#include "mesonpluginconstants.h" #include "mesonpluginconstants.h"
#include "mesontoolkitaspect.h" #include "mesonprojectmanagertr.h"
#include "ninjatoolkitaspect.h" #include "mesontools.h"
#include <utils/layoutbuilder.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QComboBox>
#include <QCoreApplication>
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils;
namespace MesonProjectManager::Internal { namespace MesonProjectManager::Internal {
enum class ToolType { Meson, Ninja };
// Meson/Ninja KitAspect base
class MesonToolKitAspectImpl final : public KitAspect
{
public:
MesonToolKitAspectImpl(Kit *kit,
const KitAspectFactory *factory,
ToolType type);
~MesonToolKitAspectImpl() { delete m_toolsComboBox; }
private:
void addTool(const MesonTools::Tool_t &tool);
void removeTool(const MesonTools::Tool_t &tool);
void setCurrentToolIndex(int index);
int indexOf(const Id &id);
bool isCompatible(const MesonTools::Tool_t &tool);
void loadTools();
void setToDefault();
void makeReadOnly() final { m_toolsComboBox->setEnabled(false); }
void addToInnerLayout(Layouting::Layout &parent) final
{
addMutableAction(m_toolsComboBox);
parent.addItem(m_toolsComboBox);
}
void refresh() final
{
const auto id = [this] {
if (m_type == ToolType::Meson)
return MesonToolKitAspect::mesonToolId(m_kit);
return NinjaToolKitAspect::ninjaToolId(m_kit);
}();
m_toolsComboBox->setCurrentIndex(indexOf(id));
}
QComboBox *m_toolsComboBox;
ToolType m_type;
};
MesonToolKitAspectImpl::MesonToolKitAspectImpl(Kit *kit, MesonToolKitAspectImpl::MesonToolKitAspectImpl(Kit *kit,
const KitAspectFactory *factory, const KitAspectFactory *factory,
ToolType type) ToolType type)
@@ -36,10 +84,7 @@ MesonToolKitAspectImpl::MesonToolKitAspectImpl(Kit *kit,
this, &MesonToolKitAspectImpl::setCurrentToolIndex); this, &MesonToolKitAspectImpl::setCurrentToolIndex);
} }
MesonToolKitAspectImpl::~MesonToolKitAspectImpl()
{
delete m_toolsComboBox;
}
void MesonToolKitAspectImpl::addTool(const MesonTools::Tool_t &tool) void MesonToolKitAspectImpl::addTool(const MesonTools::Tool_t &tool)
{ {
@@ -64,17 +109,17 @@ void MesonToolKitAspectImpl::setCurrentToolIndex(int index)
{ {
if (m_toolsComboBox->count() == 0) if (m_toolsComboBox->count() == 0)
return; return;
const Utils::Id id = Utils::Id::fromSetting(m_toolsComboBox->itemData(index)); const Id id = Id::fromSetting(m_toolsComboBox->itemData(index));
if (m_type == ToolType::Meson) if (m_type == ToolType::Meson)
MesonToolKitAspect::setMesonTool(m_kit, id); MesonToolKitAspect::setMesonTool(m_kit, id);
else else
NinjaToolKitAspect::setNinjaTool(m_kit, id); NinjaToolKitAspect::setNinjaTool(m_kit, id);
} }
int MesonToolKitAspectImpl::indexOf(const Utils::Id &id) int MesonToolKitAspectImpl::indexOf(const Id &id)
{ {
for (int i = 0; i < m_toolsComboBox->count(); ++i) { for (int i = 0; i < m_toolsComboBox->count(); ++i) {
if (id == Utils::Id::fromSetting(m_toolsComboBox->itemData(i))) if (id == Id::fromSetting(m_toolsComboBox->itemData(i)))
return i; return i;
} }
return -1; return -1;
@@ -113,4 +158,165 @@ void MesonToolKitAspectImpl::setToDefault()
} }
} }
// MesonToolKitAspect
const char MESON_TOOL_ID[] = "MesonProjectManager.MesonKitInformation.Meson";
void MesonToolKitAspect::setMesonTool(Kit *kit, Id id)
{
QTC_ASSERT(kit && id.isValid(), return );
kit->setValue(MESON_TOOL_ID, id.toSetting());
}
Id MesonToolKitAspect::mesonToolId(const Kit *kit)
{
QTC_ASSERT(kit, return {});
return Id::fromSetting(kit->value(MESON_TOOL_ID));
}
std::shared_ptr<MesonWrapper> MesonToolKitAspect::mesonTool(const Kit *kit)
{
return MesonTools::mesonWrapper(MesonToolKitAspect::mesonToolId(kit));
}
bool MesonToolKitAspect::isValid(const Kit *kit)
{
auto tool = mesonTool(kit);
return tool && tool->isValid();
}
// MesonToolKitAspectFactory
class MesonToolKitAspectFactory final : public KitAspectFactory
{
public:
MesonToolKitAspectFactory()
{
setId(MESON_TOOL_ID);
setDisplayName(Tr::tr("Meson Tool"));
setDescription(Tr::tr("The Meson tool to use when building a project with Meson.<br>"
"This setting is ignored when using other build systems."));
setPriority(9000);
}
Tasks validate(const Kit *k) const final
{
Tasks tasks;
const auto tool = MesonToolKitAspect::mesonTool(k);
if (tool && !tool->isValid())
tasks << BuildSystemTask{Task::Warning, Tr::tr("Cannot validate this meson executable.")};
return tasks;
}
void setup(Kit *k) final
{
const auto tool = MesonToolKitAspect::mesonTool(k);
if (!tool) {
const auto autoDetected = MesonTools::mesonWrapper();
if (autoDetected)
MesonToolKitAspect::setMesonTool(k, autoDetected->id());
}
}
void fix(Kit *k) final
{
setup(k);
}
KitAspect *createKitAspect(Kit *k) const final
{
return new MesonToolKitAspectImpl(k, this, ToolType::Meson);
}
ItemList toUserOutput(const Kit *k) const final
{
const auto tool = MesonToolKitAspect::mesonTool(k);
if (tool)
return {{Tr::tr("Meson"), tool->name()}};
return {{Tr::tr("Meson"), Tr::tr("Unconfigured")}};
}
};
const MesonToolKitAspectFactory theMesonKitAspectFactory;
// NinjaToolKitAspect
const char NINJA_TOOL_ID[] = "MesonProjectManager.MesonKitInformation.Ninja";
void NinjaToolKitAspect::setNinjaTool(Kit *kit, Id id)
{
QTC_ASSERT(kit && id.isValid(), return );
kit->setValue(NINJA_TOOL_ID, id.toSetting());
}
Id NinjaToolKitAspect::ninjaToolId(const Kit *kit)
{
QTC_ASSERT(kit, return {});
return Id::fromSetting(kit->value(NINJA_TOOL_ID));
}
std::shared_ptr<NinjaWrapper> NinjaToolKitAspect::ninjaTool(const Kit *kit)
{
return MesonTools::ninjaWrapper(NinjaToolKitAspect::ninjaToolId(kit));
}
bool NinjaToolKitAspect::isValid(const Kit *kit)
{
auto tool = ninjaTool(kit);
return tool && tool->isValid();
}
// NinjaToolKitAspectFactory
class NinjaToolKitAspectFactory final : public KitAspectFactory
{
public:
NinjaToolKitAspectFactory()
{
setId(NINJA_TOOL_ID);
setDisplayName(Tr::tr("Ninja Tool"));
setDescription(Tr::tr("The Ninja tool to use when building a project with Meson.<br>"
"This setting is ignored when using other build systems."));
setPriority(9000);
}
Tasks validate(const Kit *k) const final
{
Tasks tasks;
const auto tool = NinjaToolKitAspect::ninjaTool(k);
if (tool && !tool->isValid())
tasks << BuildSystemTask{Task::Warning, Tr::tr("Cannot validate this Ninja executable.")};
return tasks;
}
void setup(Kit *k) final
{
const auto tool = NinjaToolKitAspect::ninjaTool(k);
if (!tool) {
const auto autoDetected = MesonTools::ninjaWrapper();
if (autoDetected)
NinjaToolKitAspect::setNinjaTool(k, autoDetected->id());
}
}
void fix(Kit *k) final
{
setup(k);
}
ItemList toUserOutput(const Kit *k) const final
{
const auto tool = NinjaToolKitAspect::ninjaTool(k);
if (tool)
return {{Tr::tr("Ninja"), tool->name()}};
return {{Tr::tr("Ninja"), Tr::tr("Unconfigured")}};
}
KitAspect *createKitAspect(Kit *k) const final
{
return new MesonToolKitAspectImpl(k, this, ToolType::Ninja);
}
};
const NinjaToolKitAspectFactory theNinjaToolKitAspectFactory;
} // MesonProjectManager::Internal } // MesonProjectManager::Internal

View File

@@ -1,58 +1,34 @@
// Copyright (C) 2020 Alexis Jeandet. // Copyright (C) 2020 Alexis Jeandet.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once #pragma once
#include "mesontoolkitaspect.h" #include "mesonwrapper.h"
#include "ninjatoolkitaspect.h" #include "ninjawrapper.h"
#include <projectexplorer/kit.h>
#include <projectexplorer/kitmanager.h> #include <projectexplorer/kitmanager.h>
#include <utils/layoutbuilder.h>
#include <QComboBox>
#include <QCoreApplication>
namespace MesonProjectManager::Internal { namespace MesonProjectManager::Internal {
class MesonToolKitAspectImpl final : public ProjectExplorer::KitAspect class MesonToolKitAspect final
{ {
public: public:
enum class ToolType { Meson, Ninja }; static void setMesonTool(ProjectExplorer::Kit *kit, Utils::Id id);
static Utils::Id mesonToolId(const ProjectExplorer::Kit *kit);
MesonToolKitAspectImpl(ProjectExplorer::Kit *kit, static bool isValid(const ProjectExplorer::Kit *kit);
const ProjectExplorer::KitAspectFactory *factory, static std::shared_ptr<MesonWrapper> mesonTool(const ProjectExplorer::Kit *kit);
ToolType type); };
~MesonToolKitAspectImpl();
private: class NinjaToolKitAspect final
void addTool(const MesonTools::Tool_t &tool); {
void removeTool(const MesonTools::Tool_t &tool); public:
void setCurrentToolIndex(int index); static void setNinjaTool(ProjectExplorer::Kit *kit, Utils::Id id);
int indexOf(const Utils::Id &id); static Utils::Id ninjaToolId(const ProjectExplorer::Kit *kit);
bool isCompatible(const MesonTools::Tool_t &tool);
void loadTools();
void setToDefault();
void makeReadOnly() override { m_toolsComboBox->setEnabled(false); } static bool isValid(const ProjectExplorer::Kit *kit);
static std::shared_ptr<NinjaWrapper> ninjaTool(const ProjectExplorer::Kit *kit);
void addToInnerLayout(Layouting::Layout &parent) override
{
addMutableAction(m_toolsComboBox);
parent.addItem(m_toolsComboBox);
}
void refresh() override
{
const auto id = [this] {
if (m_type == ToolType::Meson)
return MesonToolKitAspect::mesonToolId(m_kit);
return NinjaToolKitAspect::ninjaToolId(m_kit);
}();
m_toolsComboBox->setCurrentIndex(indexOf(id));
}
QComboBox *m_toolsComboBox;
ToolType m_type;
}; };
} // MesonProjectManager::Internal } // MesonProjectManager::Internal