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-10-29 10:20:14 +01:00
|
|
|
|
2020-05-01 18:20:56 +02:00
|
|
|
#pragma once
|
2020-10-29 10:20:14 +01:00
|
|
|
|
2024-07-22 12:11:22 +02:00
|
|
|
#include "mesonpluginconstants.h"
|
2020-10-29 10:20:14 +01:00
|
|
|
#include "versionhelper.h"
|
|
|
|
|
|
2021-05-11 14:34:56 +02:00
|
|
|
#include <utils/commandline.h>
|
2020-05-01 18:20:56 +02:00
|
|
|
#include <utils/environment.h>
|
2020-06-26 13:59:38 +02:00
|
|
|
#include <utils/id.h>
|
2020-05-01 18:20:56 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2024-07-22 12:11:22 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
2023-08-24 16:14:26 +02:00
|
|
|
#include <utils/store.h>
|
2020-05-01 18:20:56 +02:00
|
|
|
|
2022-08-26 10:30:00 +02:00
|
|
|
#include <optional>
|
|
|
|
|
|
2020-05-01 18:20:56 +02:00
|
|
|
namespace MesonProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class Command
|
|
|
|
|
{
|
|
|
|
|
Utils::CommandLine m_cmd;
|
|
|
|
|
Utils::FilePath m_workDir;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
Command() = default;
|
|
|
|
|
Command(const Utils::FilePath &exe, const Utils::FilePath &workDir, const QStringList &args)
|
|
|
|
|
: m_cmd{exe, args}
|
|
|
|
|
, m_workDir{workDir}
|
|
|
|
|
{}
|
2023-08-24 16:14:26 +02:00
|
|
|
const Utils::CommandLine &cmdLine() const { return m_cmd; }
|
|
|
|
|
const Utils::FilePath &workDir() const { return m_workDir; }
|
|
|
|
|
Utils::FilePath executable() const { return m_cmd.executable(); }
|
|
|
|
|
QStringList arguments() const { return m_cmd.splitArguments(); }
|
|
|
|
|
QString toUserOutput() const { return m_cmd.toUserOutput(); }
|
2020-05-01 18:20:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ToolWrapper
|
|
|
|
|
{
|
|
|
|
|
public:
|
2023-08-24 16:14:26 +02:00
|
|
|
virtual ~ToolWrapper() {}
|
2020-05-01 18:20:56 +02:00
|
|
|
ToolWrapper() = delete;
|
|
|
|
|
ToolWrapper(const QString &name, const Utils::FilePath &path, bool autoDetected = false);
|
|
|
|
|
ToolWrapper(const QString &name,
|
|
|
|
|
const Utils::FilePath &path,
|
2020-06-26 13:59:38 +02:00
|
|
|
const Utils::Id &id,
|
2020-05-01 18:20:56 +02:00
|
|
|
bool autoDetected = false);
|
|
|
|
|
ToolWrapper(const ToolWrapper &other) = default;
|
|
|
|
|
ToolWrapper(ToolWrapper &&other) = default;
|
|
|
|
|
ToolWrapper &operator=(const ToolWrapper &other) = default;
|
|
|
|
|
ToolWrapper &operator=(ToolWrapper &&other) = default;
|
|
|
|
|
|
2023-08-24 16:14:26 +02:00
|
|
|
const Version &version() const noexcept { return m_version; }
|
|
|
|
|
bool isValid() const noexcept { return m_isValid; }
|
|
|
|
|
bool autoDetected() const noexcept { return m_autoDetected; }
|
|
|
|
|
Utils::Id id() const noexcept { return m_id; }
|
|
|
|
|
Utils::FilePath exe() const noexcept { return m_exe; }
|
|
|
|
|
QString name() const noexcept { return m_name; }
|
2020-05-01 18:20:56 +02:00
|
|
|
|
|
|
|
|
inline void setName(const QString &newName) { m_name = newName; }
|
|
|
|
|
virtual void setExe(const Utils::FilePath &newExe);
|
|
|
|
|
|
|
|
|
|
static Version read_version(const Utils::FilePath &toolPath);
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
2023-08-24 16:14:26 +02:00
|
|
|
friend Utils::Store toVariantMap(const T &);
|
2020-05-01 18:20:56 +02:00
|
|
|
template<typename T>
|
2023-08-24 16:14:26 +02:00
|
|
|
friend T fromVariantMap(const Utils::Store &);
|
2020-05-01 18:20:56 +02:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
Version m_version;
|
|
|
|
|
bool m_isValid;
|
|
|
|
|
bool m_autoDetected;
|
2020-06-26 13:59:38 +02:00
|
|
|
Utils::Id m_id;
|
2020-05-01 18:20:56 +02:00
|
|
|
Utils::FilePath m_exe;
|
|
|
|
|
QString m_name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
2023-08-24 16:14:26 +02:00
|
|
|
Utils::Store toVariantMap(const T &);
|
2020-05-01 18:20:56 +02:00
|
|
|
template<typename T>
|
2023-08-24 16:14:26 +02:00
|
|
|
T fromVariantMap(const Utils::Store &);
|
2020-05-01 18:20:56 +02:00
|
|
|
|
2024-07-22 12:11:22 +02:00
|
|
|
bool run_meson(const Command &command, QIODevice *output = nullptr);
|
|
|
|
|
|
|
|
|
|
bool isSetup(const Utils::FilePath &buildPath);
|
|
|
|
|
|
|
|
|
|
class MesonWrapper final : public ToolWrapper
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
using ToolWrapper::ToolWrapper;
|
|
|
|
|
|
|
|
|
|
Command setup(const Utils::FilePath &sourceDirectory,
|
|
|
|
|
const Utils::FilePath &buildDirectory,
|
|
|
|
|
const QStringList &options = {}) const;
|
|
|
|
|
Command configure(const Utils::FilePath &sourceDirectory,
|
|
|
|
|
const Utils::FilePath &buildDirectory,
|
|
|
|
|
const QStringList &options = {}) const;
|
|
|
|
|
|
|
|
|
|
Command regenerate(const Utils::FilePath &sourceDirectory,
|
|
|
|
|
const Utils::FilePath &buildDirectory) const;
|
|
|
|
|
|
|
|
|
|
Command introspect(const Utils::FilePath &sourceDirectory) const;
|
|
|
|
|
|
|
|
|
|
static std::optional<Utils::FilePath> find();
|
|
|
|
|
|
|
|
|
|
static QString toolName() { return {"Meson"}; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
inline Utils::Store toVariantMap<MesonWrapper>(const MesonWrapper &meson)
|
|
|
|
|
{
|
|
|
|
|
Utils::Store data;
|
|
|
|
|
data.insert(Constants::ToolsSettings::NAME_KEY, meson.m_name);
|
|
|
|
|
data.insert(Constants::ToolsSettings::EXE_KEY, meson.m_exe.toSettings());
|
|
|
|
|
data.insert(Constants::ToolsSettings::AUTO_DETECTED_KEY, meson.m_autoDetected);
|
|
|
|
|
data.insert(Constants::ToolsSettings::ID_KEY, meson.m_id.toSetting());
|
|
|
|
|
data.insert(Constants::ToolsSettings::TOOL_TYPE_KEY, Constants::ToolsSettings::TOOL_TYPE_MESON);
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
template<>
|
|
|
|
|
inline MesonWrapper *fromVariantMap<MesonWrapper *>(const Utils::Store &data)
|
|
|
|
|
{
|
|
|
|
|
return new MesonWrapper(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());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class NinjaWrapper final : public ToolWrapper
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
using ToolWrapper::ToolWrapper;
|
|
|
|
|
|
|
|
|
|
static std::optional<Utils::FilePath> find();
|
|
|
|
|
static QString toolName() { return {"Ninja"}; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
inline Utils::Store toVariantMap<NinjaWrapper>(const NinjaWrapper &meson)
|
|
|
|
|
{
|
|
|
|
|
Utils::Store data;
|
|
|
|
|
data.insert(Constants::ToolsSettings::NAME_KEY, meson.m_name);
|
|
|
|
|
data.insert(Constants::ToolsSettings::EXE_KEY, meson.m_exe.toSettings());
|
|
|
|
|
data.insert(Constants::ToolsSettings::AUTO_DETECTED_KEY, meson.m_autoDetected);
|
|
|
|
|
data.insert(Constants::ToolsSettings::ID_KEY, meson.m_id.toSetting());
|
|
|
|
|
data.insert(Constants::ToolsSettings::TOOL_TYPE_KEY, Constants::ToolsSettings::TOOL_TYPE_NINJA);
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
template<>
|
|
|
|
|
inline NinjaWrapper *fromVariantMap<NinjaWrapper *>(const Utils::Store &data)
|
|
|
|
|
{
|
|
|
|
|
return new NinjaWrapper(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());
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-01 18:20:56 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace MesonProjectManager
|