Files
qt-creator/src/plugins/mesonprojectmanager/mesontools.cpp
Kai Köhne 56baf8c058 Remove GPL-3.0+ from license identifiers
Since we also license under GPL-3.0 WITH Qt-GPL-exception-1.0,
this applies only to a hypothetical newer version of GPL, that doesn't
exist yet. If such a version emerges, we can still decide to relicense...

While at it, replace (deprecated) GPL-3.0 with more explicit GPL-3.0-only

Change was done by running

  find . -type f -exec perl -pi -e "s/LicenseRef-Qt-Commercial OR GPL-3.0\+ OR GPL-3.0 WITH Qt-GPL-exception-1.0/LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0/g" {} \;

Change-Id: I5097e6ce8d10233993ee30d7e25120e2659eb10b
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2023-01-06 11:15:13 +00:00

92 lines
2.7 KiB
C++

// Copyright (C) 2020 Alexis Jeandet.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "mesontools.h"
namespace MesonProjectManager {
namespace Internal {
template<typename T>
inline bool is(const MesonTools::Tool_t &tool)
{
return bool(std::dynamic_pointer_cast<T>(tool));
}
template<typename T>
std::shared_ptr<T> tool(const Utils::Id &id, const std::vector<MesonTools::Tool_t> &tools)
{
static_assert(std::is_base_of<ToolWrapper, T>::value, "Type must derive from ToolWrapper");
const auto tool = std::find_if(std::cbegin(tools),
std::cend(tools),
[&id](const MesonTools::Tool_t &tool) {
return tool->id() == id;
});
if (tool != std::cend(tools) && is<T>(*tool))
return std::dynamic_pointer_cast<T>(*tool);
return nullptr;
}
template<typename T>
std::shared_ptr<T> autoDetected(const std::vector<MesonTools::Tool_t> &tools)
{
static_assert(std::is_base_of<ToolWrapper, T>::value, "Type must derive from ToolWrapper");
for (const auto &tool : tools) {
if (tool->autoDetected() && is<T>(tool)) {
return std::dynamic_pointer_cast<T>(tool);
}
}
return nullptr;
}
template<typename T>
void fixAutoDetected(std::vector<MesonTools::Tool_t> &tools)
{
auto autoDetectedTool = autoDetected<T>(tools);
if (!autoDetectedTool) {
auto path = T::find();
if (path)
tools.emplace_back(std::make_shared<T>(
QString("System %1 at %2").arg(T::toolName()).arg(path->toString()), *path, true));
}
}
bool MesonTools::isMesonWrapper(const MesonTools::Tool_t &tool)
{
return is<MesonWrapper>(tool);
}
bool MesonTools::isNinjaWrapper(const MesonTools::Tool_t &tool)
{
return is<NinjaWrapper>(tool);
}
void MesonTools::setTools(std::vector<MesonTools::Tool_t> &&tools)
{
auto self = instance();
std::swap(self->m_tools, tools);
fixAutoDetected<MesonWrapper>(self->m_tools);
fixAutoDetected<NinjaWrapper>(self->m_tools);
}
std::shared_ptr<NinjaWrapper> MesonTools::ninjaWrapper(const Utils::Id &id)
{
return tool<NinjaWrapper>(id, MesonTools::instance()->m_tools);
}
std::shared_ptr<MesonWrapper> MesonTools::mesonWrapper(const Utils::Id &id)
{
return tool<MesonWrapper>(id, MesonTools::instance()->m_tools);
}
std::shared_ptr<NinjaWrapper> MesonTools::ninjaWrapper()
{
return autoDetected<NinjaWrapper>(MesonTools::instance()->m_tools);
}
std::shared_ptr<MesonWrapper> MesonTools::mesonWrapper()
{
return autoDetected<MesonWrapper>(MesonTools::instance()->m_tools);
}
} // namespace Internal
} // namespace MesonProjectManager