2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2020 Alexis Jeandet.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2020-05-01 18:20:56 +02:00
|
|
|
|
|
|
|
|
#include "ninjatoolkitaspect.h"
|
2020-10-29 10:20:14 +01:00
|
|
|
|
2022-10-10 09:14:04 +02:00
|
|
|
#include "mesonprojectmanagertr.h"
|
2020-05-01 18:20:56 +02:00
|
|
|
#include "toolkitaspectwidget.h"
|
2020-10-29 10:20:14 +01:00
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
2020-05-01 18:20:56 +02:00
|
|
|
|
2023-08-17 18:12:06 +02:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
2023-08-10 16:20:25 +02:00
|
|
|
namespace MesonProjectManager::Internal {
|
2020-05-01 18:20:56 +02:00
|
|
|
|
2023-08-17 18:12:06 +02:00
|
|
|
const char TOOL_ID[] = "MesonProjectManager.MesonKitInformation.Ninja";
|
2020-05-01 18:20:56 +02:00
|
|
|
|
2023-08-17 18:12:06 +02:00
|
|
|
void NinjaToolKitAspect::setNinjaTool(ProjectExplorer::Kit *kit, Utils::Id id)
|
2020-05-01 18:20:56 +02:00
|
|
|
{
|
2023-08-17 18:12:06 +02:00
|
|
|
QTC_ASSERT(kit && id.isValid(), return );
|
|
|
|
|
kit->setValue(TOOL_ID, id.toSetting());
|
2020-05-01 18:20:56 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-17 18:12:06 +02:00
|
|
|
Utils::Id NinjaToolKitAspect::ninjaToolId(const ProjectExplorer::Kit *kit)
|
2020-05-01 18:20:56 +02:00
|
|
|
{
|
2023-08-17 18:12:06 +02:00
|
|
|
QTC_ASSERT(kit, return {});
|
|
|
|
|
return Utils::Id::fromSetting(kit->value(TOOL_ID));
|
2020-05-01 18:20:56 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-17 18:12:06 +02:00
|
|
|
// NinjaToolKitAspectFactory
|
|
|
|
|
|
|
|
|
|
class NinjaToolKitAspectFactory final : public ProjectExplorer::KitAspectFactory
|
2020-05-01 18:20:56 +02:00
|
|
|
{
|
2023-08-17 18:12:06 +02:00
|
|
|
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);
|
2020-05-01 18:20:56 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-17 18:12:06 +02:00
|
|
|
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;
|
|
|
|
|
}
|
2020-05-01 18:20:56 +02:00
|
|
|
|
2023-08-17 18:12:06 +02:00
|
|
|
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);
|
|
|
|
|
}
|
2020-05-01 18:20:56 +02:00
|
|
|
|
2023-08-17 18:12:06 +02:00
|
|
|
ItemList toUserOutput( const Kit *k) const
|
|
|
|
|
{
|
|
|
|
|
const auto tool = NinjaToolKitAspect::ninjaTool(k);
|
|
|
|
|
if (tool)
|
|
|
|
|
return {{Tr::tr("Ninja"), tool->name()}};
|
|
|
|
|
return {{Tr::tr("Ninja"), Tr::tr("Unconfigured")}};
|
|
|
|
|
}
|
2020-05-01 18:20:56 +02:00
|
|
|
|
2023-08-17 18:12:06 +02:00
|
|
|
KitAspect *createKitAspect(Kit *k) const final
|
|
|
|
|
{
|
|
|
|
|
return new ToolKitAspectWidget(k, this, ToolKitAspectWidget::ToolType::Ninja);
|
|
|
|
|
}
|
|
|
|
|
};
|
2020-05-01 18:20:56 +02:00
|
|
|
|
2023-08-17 18:12:06 +02:00
|
|
|
const NinjaToolKitAspectFactory theNinjaToolKitAspectFactory;
|
2023-08-10 16:20:25 +02:00
|
|
|
|
|
|
|
|
} // MesonProjectManager::Internal
|