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
|
|
|
|
|
|
|
|
#pragma once
|
2020-10-29 10:20:14 +01:00
|
|
|
|
2022-10-06 16:58:18 +02:00
|
|
|
#include "mesonpluginconstants.h"
|
2020-05-01 18:20:56 +02:00
|
|
|
#include "toolwrapper.h"
|
2020-10-29 10:20:14 +01:00
|
|
|
|
|
|
|
|
#include <utils/environment.h>
|
|
|
|
|
#include <utils/fileutils.h>
|
2020-06-26 13:59:38 +02:00
|
|
|
#include <utils/id.h>
|
2023-05-03 17:05:35 +02:00
|
|
|
#include <utils/process.h>
|
2020-10-29 10:20:14 +01:00
|
|
|
|
2020-05-01 18:20:56 +02:00
|
|
|
#include <QFile>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QTemporaryFile>
|
|
|
|
|
|
2022-08-26 10:30:00 +02:00
|
|
|
#include <optional>
|
2020-10-29 10:20:14 +01:00
|
|
|
#include <tuple>
|
|
|
|
|
|
2020-05-01 18:20:56 +02:00
|
|
|
namespace MesonProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
template<typename File_t>
|
|
|
|
|
bool containsFiles(const QString &path, const File_t &file)
|
|
|
|
|
{
|
|
|
|
|
return QFile::exists(QString("%1/%2").arg(path).arg(file));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename File_t, typename... T>
|
2020-10-27 22:36:27 +01:00
|
|
|
bool containsFiles(const QString &path, const File_t &file, const T &...files)
|
2020-05-01 18:20:56 +02:00
|
|
|
{
|
|
|
|
|
return containsFiles(path, file) && containsFiles(path, files...);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool run_meson(const Command &command, QIODevice *output = nullptr)
|
|
|
|
|
{
|
2023-05-03 16:00:22 +02:00
|
|
|
Utils::Process process;
|
2021-11-03 14:58:33 +01:00
|
|
|
process.setWorkingDirectory(command.workDir());
|
|
|
|
|
process.setCommand(command.cmdLine());
|
|
|
|
|
process.start();
|
2020-05-01 18:20:56 +02:00
|
|
|
if (!process.waitForFinished())
|
|
|
|
|
return false;
|
|
|
|
|
if (output) {
|
2023-01-05 17:55:04 +01:00
|
|
|
output->write(process.readAllRawStandardOutput());
|
2020-05-01 18:20:56 +02:00
|
|
|
}
|
|
|
|
|
return process.exitCode() == 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool isSetup(const Utils::FilePath &buildPath)
|
|
|
|
|
{
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
return containsFiles(buildPath.pathAppended(Constants::MESON_INFO_DIR).toString(),
|
2020-10-27 22:36:27 +01:00
|
|
|
Constants::MESON_INTRO_TESTS,
|
|
|
|
|
Constants::MESON_INTRO_TARGETS,
|
|
|
|
|
Constants::MESON_INTRO_INSTALLED,
|
|
|
|
|
Constants::MESON_INTRO_BENCHMARKS,
|
|
|
|
|
Constants::MESON_INTRO_BUIDOPTIONS,
|
|
|
|
|
Constants::MESON_INTRO_PROJECTINFO,
|
|
|
|
|
Constants::MESON_INTRO_DEPENDENCIES,
|
|
|
|
|
Constants::MESON_INTRO_BUILDSYSTEM_FILES);
|
2020-05-01 18:20:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,
|
2020-10-27 22:36:27 +01:00
|
|
|
const Utils::FilePath &buildDirectory) const;
|
2020-05-01 18:20:56 +02:00
|
|
|
|
|
|
|
|
Command introspect(const Utils::FilePath &sourceDirectory) const;
|
|
|
|
|
|
2023-08-24 16:14:26 +02:00
|
|
|
static std::optional<Utils::FilePath> find()
|
2020-05-01 18:20:56 +02:00
|
|
|
{
|
2020-10-27 22:36:27 +01:00
|
|
|
return ToolWrapper::findTool({"meson.py", "meson"});
|
2020-05-01 18:20:56 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-24 16:14:26 +02:00
|
|
|
static QString toolName() { return {"Meson"}; }
|
2020-05-01 18:20:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<>
|
2023-08-24 16:14:26 +02:00
|
|
|
inline Utils::Store toVariantMap<MesonWrapper>(const MesonWrapper &meson)
|
2020-05-01 18:20:56 +02:00
|
|
|
{
|
2023-08-24 16:14:26 +02:00
|
|
|
Utils::Store data;
|
2020-05-01 18:20:56 +02:00
|
|
|
data.insert(Constants::ToolsSettings::NAME_KEY, meson.m_name);
|
2023-01-03 12:31:52 +01:00
|
|
|
data.insert(Constants::ToolsSettings::EXE_KEY, meson.m_exe.toSettings());
|
2020-05-01 18:20:56 +02:00
|
|
|
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<>
|
2023-08-24 16:14:26 +02:00
|
|
|
inline MesonWrapper *fromVariantMap<MesonWrapper *>(const Utils::Store &data)
|
2020-05-01 18:20:56 +02:00
|
|
|
{
|
|
|
|
|
return new MesonWrapper(data[Constants::ToolsSettings::NAME_KEY].toString(),
|
2023-01-03 12:31:52 +01:00
|
|
|
Utils::FilePath::fromSettings(data[Constants::ToolsSettings::EXE_KEY]),
|
2020-06-26 13:59:38 +02:00
|
|
|
Utils::Id::fromSetting(data[Constants::ToolsSettings::ID_KEY]),
|
2020-05-01 18:20:56 +02:00
|
|
|
data[Constants::ToolsSettings::AUTO_DETECTED_KEY].toBool());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace MesonProjectManager
|