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-06-26 13:59:38 +02:00
|
|
|
#include <utils/id.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 {
|
|
|
|
|
|
2024-07-22 17:14:09 +02:00
|
|
|
enum class ToolType { Meson, Ninja };
|
|
|
|
|
|
2020-05-01 18:20:56 +02:00
|
|
|
class Command
|
|
|
|
|
{
|
|
|
|
|
public:
|
2024-07-22 13:17:46 +02:00
|
|
|
Utils::CommandLine cmdLine;
|
|
|
|
|
Utils::FilePath workDir;
|
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;
|
2024-07-22 17:14:09 +02:00
|
|
|
ToolWrapper(ToolType toolType,
|
|
|
|
|
const QString &name,
|
|
|
|
|
const Utils::FilePath &path,
|
|
|
|
|
bool autoDetected = false);
|
|
|
|
|
ToolWrapper(ToolType toolType,
|
|
|
|
|
const QString &name,
|
2020-05-01 18:20:56 +02:00
|
|
|
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);
|
|
|
|
|
|
2024-07-22 17:14:09 +02:00
|
|
|
Utils::Store toVariantMap() const;
|
|
|
|
|
static ToolWrapper *fromVariantMap(const Utils::Store &, ToolType toolType);
|
|
|
|
|
|
|
|
|
|
ToolType toolType() const { return m_toolType; }
|
|
|
|
|
void setToolType(ToolType newToolType) { m_toolType = newToolType; }
|
2020-05-01 18:20:56 +02:00
|
|
|
|
|
|
|
|
protected:
|
2024-07-22 17:14:09 +02:00
|
|
|
ToolType m_toolType;
|
2020-05-01 18:20:56 +02:00
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class NinjaWrapper final : public ToolWrapper
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
using ToolWrapper::ToolWrapper;
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-22 17:14:09 +02:00
|
|
|
std::optional<Utils::FilePath> findMesonTool();
|
|
|
|
|
std::optional<Utils::FilePath> findNinjaTool();
|
2024-07-22 12:11:22 +02:00
|
|
|
|
2020-05-01 18:20:56 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace MesonProjectManager
|