forked from qt-creator/qt-creator
Meson: Streamline setup a bit
Change-Id: I8d146b2b79beb9b09dcf6f8ed498039d79af0e76 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -10,7 +10,7 @@ using namespace Utils;
|
|||||||
namespace MesonProjectManager {
|
namespace MesonProjectManager {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
MesonTools::Tool_t tool(const Utils::Id &id,
|
MesonTools::Tool_t tool(const Id &id,
|
||||||
const std::vector<MesonTools::Tool_t> &tools,
|
const std::vector<MesonTools::Tool_t> &tools,
|
||||||
ToolType toolType)
|
ToolType toolType)
|
||||||
{
|
{
|
||||||
@@ -65,6 +65,22 @@ bool MesonTools::isNinjaWrapper(const MesonTools::Tool_t &tool)
|
|||||||
return tool->toolType() == ToolType::Ninja;
|
return tool->toolType() == ToolType::Ninja;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MesonTools::addTool(const Id &itemId, const QString &name, const FilePath &exe)
|
||||||
|
{
|
||||||
|
// TODO improve this
|
||||||
|
if (exe.fileName().contains("ninja"))
|
||||||
|
addTool(std::make_shared<ToolWrapper>(ToolType::Ninja, name, exe, itemId));
|
||||||
|
else
|
||||||
|
addTool(std::make_shared<ToolWrapper>(ToolType::Meson, name, exe, itemId));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MesonTools::addTool(Tool_t meson)
|
||||||
|
{
|
||||||
|
auto self = instance();
|
||||||
|
self->m_tools.emplace_back(std::move(meson));
|
||||||
|
emit self->toolAdded(self->m_tools.back());
|
||||||
|
}
|
||||||
|
|
||||||
void MesonTools::setTools(std::vector<MesonTools::Tool_t> &&tools)
|
void MesonTools::setTools(std::vector<MesonTools::Tool_t> &&tools)
|
||||||
{
|
{
|
||||||
auto self = instance();
|
auto self = instance();
|
||||||
@@ -73,12 +89,34 @@ void MesonTools::setTools(std::vector<MesonTools::Tool_t> &&tools)
|
|||||||
fixAutoDetected(self->m_tools, ToolType::Ninja);
|
fixAutoDetected(self->m_tools, ToolType::Ninja);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<ToolWrapper> MesonTools::ninjaWrapper(const Utils::Id &id)
|
void MesonTools::updateTool(const Id &itemId, const QString &name, const FilePath &exe)
|
||||||
|
{
|
||||||
|
auto self = instance();
|
||||||
|
auto item = std::find_if(std::begin(self->m_tools),
|
||||||
|
std::end(self->m_tools),
|
||||||
|
[&itemId](const Tool_t &tool) { return tool->id() == itemId; });
|
||||||
|
if (item != std::end(self->m_tools)) {
|
||||||
|
(*item)->setExe(exe);
|
||||||
|
(*item)->setName(name);
|
||||||
|
} else {
|
||||||
|
addTool(itemId, name, exe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MesonTools::removeTool(const Id &id)
|
||||||
|
{
|
||||||
|
auto self = instance();
|
||||||
|
auto item = Utils::take(self->m_tools, [&id](const auto &item) { return item->id() == id; });
|
||||||
|
QTC_ASSERT(item, return );
|
||||||
|
emit self->toolRemoved(*item);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<ToolWrapper> MesonTools::ninjaWrapper(const Id &id)
|
||||||
{
|
{
|
||||||
return tool(id, MesonTools::instance()->m_tools, ToolType::Ninja);
|
return tool(id, MesonTools::instance()->m_tools, ToolType::Ninja);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<ToolWrapper> MesonTools::mesonWrapper(const Utils::Id &id)
|
std::shared_ptr<ToolWrapper> MesonTools::mesonWrapper(const Id &id)
|
||||||
{
|
{
|
||||||
return tool(id, MesonTools::instance()->m_tools, ToolType::Meson);
|
return tool(id, MesonTools::instance()->m_tools, ToolType::Meson);
|
||||||
}
|
}
|
||||||
|
@@ -24,50 +24,20 @@ public:
|
|||||||
static bool isMesonWrapper(const Tool_t &tool);
|
static bool isMesonWrapper(const Tool_t &tool);
|
||||||
static bool isNinjaWrapper(const Tool_t &tool);
|
static bool isNinjaWrapper(const Tool_t &tool);
|
||||||
|
|
||||||
static inline void addTool(const Utils::Id &itemId,
|
static void addTool(const Utils::Id &itemId,
|
||||||
const QString &name,
|
const QString &name,
|
||||||
const Utils::FilePath &exe)
|
const Utils::FilePath &exe);
|
||||||
{
|
|
||||||
// TODO improve this
|
|
||||||
if (exe.fileName().contains("ninja"))
|
|
||||||
addTool(std::make_shared<ToolWrapper>(ToolType::Ninja, name, exe, itemId));
|
|
||||||
else
|
|
||||||
addTool(std::make_shared<ToolWrapper>(ToolType::Meson, name, exe, itemId));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void addTool(Tool_t meson)
|
static void addTool(Tool_t meson);
|
||||||
{
|
|
||||||
auto self = instance();
|
|
||||||
self->m_tools.emplace_back(std::move(meson));
|
|
||||||
emit self->toolAdded(self->m_tools.back());
|
|
||||||
}
|
|
||||||
|
|
||||||
static void setTools(std::vector<Tool_t> &&tools);
|
static void setTools(std::vector<Tool_t> &&tools);
|
||||||
|
|
||||||
static inline const std::vector<Tool_t> &tools() { return instance()->m_tools; }
|
static inline const std::vector<Tool_t> &tools() { return instance()->m_tools; }
|
||||||
|
|
||||||
static inline void updateTool(const Utils::Id &itemId,
|
static void updateTool(const Utils::Id &itemId,
|
||||||
const QString &name,
|
const QString &name,
|
||||||
const Utils::FilePath &exe)
|
const Utils::FilePath &exe);
|
||||||
{
|
static void removeTool(const Utils::Id &id);
|
||||||
auto self = instance();
|
|
||||||
auto item = std::find_if(std::begin(self->m_tools),
|
|
||||||
std::end(self->m_tools),
|
|
||||||
[&itemId](const Tool_t &tool) { return tool->id() == itemId; });
|
|
||||||
if (item != std::end(self->m_tools)) {
|
|
||||||
(*item)->setExe(exe);
|
|
||||||
(*item)->setName(name);
|
|
||||||
} else {
|
|
||||||
addTool(itemId, name, exe);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
static void removeTool(const Utils::Id &id)
|
|
||||||
{
|
|
||||||
auto self = instance();
|
|
||||||
auto item = Utils::take(self->m_tools, [&id](const auto &item) { return item->id() == id; });
|
|
||||||
QTC_ASSERT(item, return );
|
|
||||||
emit self->toolRemoved(*item);
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::shared_ptr<ToolWrapper> ninjaWrapper(const Utils::Id &id);
|
static std::shared_ptr<ToolWrapper> ninjaWrapper(const Utils::Id &id);
|
||||||
static std::shared_ptr<ToolWrapper> mesonWrapper(const Utils::Id &id);
|
static std::shared_ptr<ToolWrapper> mesonWrapper(const Utils::Id &id);
|
||||||
|
@@ -82,8 +82,6 @@ MesonToolKitAspectImpl::MesonToolKitAspectImpl(Kit *kit,
|
|||||||
this, &MesonToolKitAspectImpl::setCurrentToolIndex);
|
this, &MesonToolKitAspectImpl::setCurrentToolIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void MesonToolKitAspectImpl::addTool(const MesonTools::Tool_t &tool)
|
void MesonToolKitAspectImpl::addTool(const MesonTools::Tool_t &tool)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(tool, return );
|
QTC_ASSERT(tool, return );
|
||||||
|
@@ -31,8 +31,8 @@ class ToolsSettingsAccessor final : public UpgradingSettingsAccessor
|
|||||||
public:
|
public:
|
||||||
ToolsSettingsAccessor();
|
ToolsSettingsAccessor();
|
||||||
|
|
||||||
void saveMesonTools(const std::vector<MesonTools::Tool_t> &tools);
|
void saveMesonTools();
|
||||||
std::vector<MesonTools::Tool_t> loadMesonTools();
|
void loadMesonTools();
|
||||||
};
|
};
|
||||||
|
|
||||||
ToolsSettingsAccessor::ToolsSettingsAccessor()
|
ToolsSettingsAccessor::ToolsSettingsAccessor()
|
||||||
@@ -41,19 +41,19 @@ ToolsSettingsAccessor::ToolsSettingsAccessor()
|
|||||||
setApplicationDisplayName(QGuiApplication::applicationDisplayName());
|
setApplicationDisplayName(QGuiApplication::applicationDisplayName());
|
||||||
setBaseFilePath(ICore::userResourcePath(Constants::ToolsSettings::FILENAME));
|
setBaseFilePath(ICore::userResourcePath(Constants::ToolsSettings::FILENAME));
|
||||||
|
|
||||||
MesonTools::setTools(loadMesonTools());
|
loadMesonTools();
|
||||||
|
|
||||||
QObject::connect(ICore::instance(), &ICore::saveSettingsRequested, [this] {
|
QObject::connect(ICore::instance(), &ICore::saveSettingsRequested, [this] {
|
||||||
saveMesonTools(MesonTools::tools());
|
saveMesonTools();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolsSettingsAccessor::saveMesonTools(const std::vector<MesonTools::Tool_t> &tools)
|
void ToolsSettingsAccessor::saveMesonTools()
|
||||||
{
|
{
|
||||||
using namespace Constants;
|
using namespace Constants;
|
||||||
Store data;
|
Store data;
|
||||||
int entry_count = 0;
|
int entry_count = 0;
|
||||||
for (const MesonTools::Tool_t &tool : tools) {
|
for (const MesonTools::Tool_t &tool : MesonTools::tools()) {
|
||||||
data.insert(entryName(entry_count), variantFromStore(tool->toVariantMap()));
|
data.insert(entryName(entry_count), variantFromStore(tool->toVariantMap()));
|
||||||
++entry_count;
|
++entry_count;
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ void ToolsSettingsAccessor::saveMesonTools(const std::vector<MesonTools::Tool_t>
|
|||||||
saveSettings(data, ICore::dialogParent());
|
saveSettings(data, ICore::dialogParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<MesonTools::Tool_t> ToolsSettingsAccessor::loadMesonTools()
|
void ToolsSettingsAccessor::loadMesonTools()
|
||||||
{
|
{
|
||||||
using namespace Constants;
|
using namespace Constants;
|
||||||
auto data = restoreSettings(ICore::dialogParent());
|
auto data = restoreSettings(ICore::dialogParent());
|
||||||
@@ -70,15 +70,10 @@ std::vector<MesonTools::Tool_t> ToolsSettingsAccessor::loadMesonTools()
|
|||||||
for (auto toolIndex = 0; toolIndex < entry_count; toolIndex++) {
|
for (auto toolIndex = 0; toolIndex < entry_count; toolIndex++) {
|
||||||
Key name = entryName(toolIndex);
|
Key name = entryName(toolIndex);
|
||||||
Store store = storeFromVariant(data[name]);
|
Store store = storeFromVariant(data[name]);
|
||||||
QString type = store.value(ToolsSettings::TOOL_TYPE_KEY).toString();
|
result.emplace_back(new ToolWrapper(store));
|
||||||
if (type == ToolsSettings::TOOL_TYPE_NINJA)
|
|
||||||
result.emplace_back(ToolWrapper::fromVariantMap(storeFromVariant(data[name]), ToolType::Ninja));
|
|
||||||
else if (type == ToolsSettings::TOOL_TYPE_MESON)
|
|
||||||
result.emplace_back(ToolWrapper::fromVariantMap(storeFromVariant(data[name]), ToolType::Meson));
|
|
||||||
else
|
|
||||||
QTC_CHECK(false);
|
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
|
MesonTools::setTools(std::move(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupToolsSettingsAccessor()
|
void setupToolsSettingsAccessor()
|
||||||
|
@@ -20,6 +20,25 @@ using namespace Utils;
|
|||||||
namespace MesonProjectManager {
|
namespace MesonProjectManager {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
static ToolType typeFromId(const QString &id)
|
||||||
|
{
|
||||||
|
if (id == Constants::ToolsSettings::TOOL_TYPE_NINJA)
|
||||||
|
return ToolType::Ninja;
|
||||||
|
if (id == Constants::ToolsSettings::TOOL_TYPE_MESON)
|
||||||
|
return ToolType::Meson;
|
||||||
|
QTC_CHECK(false);
|
||||||
|
return ToolType::Meson;
|
||||||
|
}
|
||||||
|
|
||||||
|
ToolWrapper::ToolWrapper(const Store &data)
|
||||||
|
{
|
||||||
|
m_toolType = typeFromId(data.value(Constants::ToolsSettings::TOOL_TYPE_KEY).toString());
|
||||||
|
m_name = data[Constants::ToolsSettings::NAME_KEY].toString();
|
||||||
|
m_exe = FilePath::fromSettings(data[Constants::ToolsSettings::EXE_KEY]);
|
||||||
|
m_id = Id::fromSetting(data[Constants::ToolsSettings::ID_KEY]);
|
||||||
|
m_autoDetected = data[Constants::ToolsSettings::AUTO_DETECTED_KEY].toBool();
|
||||||
|
}
|
||||||
|
|
||||||
ToolWrapper::ToolWrapper(ToolType toolType,
|
ToolWrapper::ToolWrapper(ToolType toolType,
|
||||||
const QString &name,
|
const QString &name,
|
||||||
const FilePath &path,
|
const FilePath &path,
|
||||||
@@ -83,15 +102,6 @@ Store ToolWrapper::toVariantMap() const
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
ToolWrapper *ToolWrapper::fromVariantMap(const Store &data, ToolType toolType)
|
|
||||||
{
|
|
||||||
return new ToolWrapper(toolType,
|
|
||||||
data[Constants::ToolsSettings::NAME_KEY].toString(),
|
|
||||||
Utils::FilePath::fromSettings(data[Constants::ToolsSettings::EXE_KEY]),
|
|
||||||
Utils::Id::fromSetting(data[Constants::ToolsSettings::ID_KEY]),
|
|
||||||
data[Constants::ToolsSettings::AUTO_DETECTED_KEY].toBool());
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::optional<FilePath> findTool(const QStringList &exeNames)
|
static std::optional<FilePath> findTool(const QStringList &exeNames)
|
||||||
{
|
{
|
||||||
Environment systemEnvironment = Environment::systemEnvironment();
|
Environment systemEnvironment = Environment::systemEnvironment();
|
||||||
|
@@ -27,6 +27,7 @@ class ToolWrapper final
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ToolWrapper() = delete;
|
ToolWrapper() = delete;
|
||||||
|
explicit ToolWrapper(const Utils::Store &data);
|
||||||
ToolWrapper(ToolType toolType,
|
ToolWrapper(ToolType toolType,
|
||||||
const QString &name,
|
const QString &name,
|
||||||
const Utils::FilePath &path,
|
const Utils::FilePath &path,
|
||||||
@@ -52,7 +53,6 @@ public:
|
|||||||
static Version read_version(const Utils::FilePath &toolPath);
|
static Version read_version(const Utils::FilePath &toolPath);
|
||||||
|
|
||||||
Utils::Store toVariantMap() const;
|
Utils::Store toVariantMap() const;
|
||||||
static ToolWrapper *fromVariantMap(const Utils::Store &, ToolType toolType);
|
|
||||||
|
|
||||||
ToolType toolType() const { return m_toolType; }
|
ToolType toolType() const { return m_toolType; }
|
||||||
void setToolType(ToolType newToolType) { m_toolType = newToolType; }
|
void setToolType(ToolType newToolType) { m_toolType = newToolType; }
|
||||||
@@ -67,7 +67,7 @@ public:
|
|||||||
const Utils::FilePath &buildDirectory) const;
|
const Utils::FilePath &buildDirectory) const;
|
||||||
Command introspect(const Utils::FilePath &sourceDirectory) const;
|
Command introspect(const Utils::FilePath &sourceDirectory) const;
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
ToolType m_toolType;
|
ToolType m_toolType;
|
||||||
Version m_version;
|
Version m_version;
|
||||||
bool m_isValid;
|
bool m_isValid;
|
||||||
|
Reference in New Issue
Block a user