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
|
|
|
|
|
|
|
|
#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>
|
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);
|
|
|
|
|
|
2022-08-26 10:30:00 +02:00
|
|
|
static std::optional<Utils::FilePath> findTool(const QStringList &exeNames);
|
2020-05-01 18:20:56 +02:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace MesonProjectManager
|