forked from qt-creator/qt-creator
Meson: Merge toolwrapper and mesontool file pairs
Change-Id: I6383a5ee060957ba133ddf98a1a383bbe2489369 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -59,8 +59,6 @@ add_qtc_plugin(MesonProjectManager
|
|||||||
toolssettingspage.h
|
toolssettingspage.h
|
||||||
tooltreeitem.cpp
|
tooltreeitem.cpp
|
||||||
tooltreeitem.h
|
tooltreeitem.h
|
||||||
toolwrapper.cpp
|
|
||||||
toolwrapper.h
|
|
||||||
versionhelper.h
|
versionhelper.h
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -81,8 +79,7 @@ add_qtc_test(tst_mesonwrapper
|
|||||||
TEST_RELATIVE_LIBEXEC_PATH="${TEST_RELATIVE_LIBEXEC_PATH}"
|
TEST_RELATIVE_LIBEXEC_PATH="${TEST_RELATIVE_LIBEXEC_PATH}"
|
||||||
SOURCES
|
SOURCES
|
||||||
tests/testmesonwrapper.cpp
|
tests/testmesonwrapper.cpp
|
||||||
toolwrapper.h
|
mesontools.cpp
|
||||||
toolwrapper.cpp
|
|
||||||
mesontools.h
|
mesontools.h
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -99,10 +96,9 @@ add_qtc_test(tst_mesoninfoparser
|
|||||||
TEST_RELATIVE_LIBEXEC_PATH="${TEST_RELATIVE_LIBEXEC_PATH}"
|
TEST_RELATIVE_LIBEXEC_PATH="${TEST_RELATIVE_LIBEXEC_PATH}"
|
||||||
SOURCES
|
SOURCES
|
||||||
tests/testmesoninfoparser.cpp
|
tests/testmesoninfoparser.cpp
|
||||||
toolwrapper.h
|
|
||||||
toolwrapper.cpp
|
|
||||||
mesontools.h
|
|
||||||
mesoninfoparser.h
|
mesoninfoparser.h
|
||||||
|
mesontools.cpp
|
||||||
|
mesontools.h
|
||||||
)
|
)
|
||||||
|
|
||||||
add_qtc_test(tst_ninjaparser
|
add_qtc_test(tst_ninjaparser
|
||||||
|
@@ -20,8 +20,6 @@ Project {
|
|||||||
files: [
|
files: [
|
||||||
"mesontools.cpp",
|
"mesontools.cpp",
|
||||||
"mesontools.h",
|
"mesontools.h",
|
||||||
"toolwrapper.cpp",
|
|
||||||
"toolwrapper.h",
|
|
||||||
"kitdata.h",
|
"kitdata.h",
|
||||||
"mesonactionsmanager.cpp",
|
"mesonactionsmanager.cpp",
|
||||||
"mesonactionsmanager.h",
|
"mesonactionsmanager.h",
|
||||||
@@ -91,8 +89,6 @@ Project {
|
|||||||
cpp.includePaths: "."
|
cpp.includePaths: "."
|
||||||
|
|
||||||
files: [
|
files: [
|
||||||
"toolwrapper.h",
|
|
||||||
"toolwrapper.cpp",
|
|
||||||
"mesontools.h",
|
"mesontools.h",
|
||||||
"tests/testmesonwrapper.cpp",
|
"tests/testmesonwrapper.cpp",
|
||||||
]
|
]
|
||||||
@@ -108,8 +104,6 @@ Project {
|
|||||||
cpp.includePaths: "."
|
cpp.includePaths: "."
|
||||||
|
|
||||||
files: [
|
files: [
|
||||||
"toolwrapper.h",
|
|
||||||
"toolwrapper.cpp",
|
|
||||||
"mesontools.h",
|
"mesontools.h",
|
||||||
"mesoninfoparser.h",
|
"mesoninfoparser.h",
|
||||||
"tests/testmesoninfoparser.cpp",
|
"tests/testmesoninfoparser.cpp",
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
#include "mesoninfoparser.h"
|
#include "mesoninfoparser.h"
|
||||||
#include "mesonoutputparser.h"
|
#include "mesonoutputparser.h"
|
||||||
#include "mesonprojectnodes.h"
|
#include "mesonprojectnodes.h"
|
||||||
#include "toolwrapper.h"
|
#include "mesontools.h"
|
||||||
|
|
||||||
#include <projectexplorer/buildsystem.h>
|
#include <projectexplorer/buildsystem.h>
|
||||||
#include <projectexplorer/kit.h>
|
#include <projectexplorer/kit.h>
|
||||||
|
@@ -3,13 +3,226 @@
|
|||||||
|
|
||||||
#include "mesontools.h"
|
#include "mesontools.h"
|
||||||
|
|
||||||
|
#include "mesonpluginconstants.h"
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
|
#include <utils/fileutils.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
#include <utils/qtcprocess.h>
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QTemporaryFile>
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace MesonProjectManager::Internal {
|
namespace MesonProjectManager::Internal {
|
||||||
|
|
||||||
|
static ToolType typeFromId(const QString &id)
|
||||||
|
{
|
||||||
|
if (id == Constants::ToolsSettings::TOOL_TYPE_NINJA)
|
||||||
|
return ToolType::Ninja;
|
||||||
|
if (id == Constants::ToolsSettings::TOOL_TYPE_MESON)
|
||||||
|
return ToolType::Meson;
|
||||||
|
QTC_CHECK(false);
|
||||||
|
return ToolType::Meson;
|
||||||
|
}
|
||||||
|
|
||||||
|
ToolWrapper::ToolWrapper(const Store &data)
|
||||||
|
{
|
||||||
|
m_toolType = typeFromId(data.value(Constants::ToolsSettings::TOOL_TYPE_KEY).toString());
|
||||||
|
m_name = data[Constants::ToolsSettings::NAME_KEY].toString();
|
||||||
|
m_exe = FilePath::fromSettings(data[Constants::ToolsSettings::EXE_KEY]);
|
||||||
|
m_id = Id::fromSetting(data[Constants::ToolsSettings::ID_KEY]);
|
||||||
|
m_autoDetected = data[Constants::ToolsSettings::AUTO_DETECTED_KEY].toBool();
|
||||||
|
}
|
||||||
|
|
||||||
|
ToolWrapper::ToolWrapper(ToolType toolType,
|
||||||
|
const QString &name,
|
||||||
|
const FilePath &path,
|
||||||
|
bool autoDetected)
|
||||||
|
: m_toolType(toolType)
|
||||||
|
, m_version(read_version(path))
|
||||||
|
, m_isValid{path.exists() && m_version.isValid}
|
||||||
|
, m_autoDetected{autoDetected}
|
||||||
|
, m_id{Utils::Id::generate()}
|
||||||
|
, m_exe{path}
|
||||||
|
, m_name{name}
|
||||||
|
{}
|
||||||
|
|
||||||
|
ToolWrapper::ToolWrapper(ToolType toolType,
|
||||||
|
const QString &name,
|
||||||
|
const FilePath &path,
|
||||||
|
const Id &id,
|
||||||
|
bool autoDetected)
|
||||||
|
: m_toolType(toolType)
|
||||||
|
, m_version(read_version(path))
|
||||||
|
, m_isValid{path.exists() && m_version.isValid}
|
||||||
|
, m_autoDetected{autoDetected}
|
||||||
|
, m_id{id}
|
||||||
|
, m_exe{path}
|
||||||
|
, m_name{name}
|
||||||
|
{
|
||||||
|
QTC_ASSERT(m_id.isValid(), m_id = Utils::Id::generate());
|
||||||
|
}
|
||||||
|
|
||||||
|
ToolWrapper::~ToolWrapper() = default;
|
||||||
|
|
||||||
|
void ToolWrapper::setExe(const Utils::FilePath &newExe)
|
||||||
|
{
|
||||||
|
m_exe = newExe;
|
||||||
|
m_version = read_version(m_exe);
|
||||||
|
}
|
||||||
|
|
||||||
|
Version ToolWrapper::read_version(const Utils::FilePath &toolPath)
|
||||||
|
{
|
||||||
|
if (toolPath.toFileInfo().isExecutable()) {
|
||||||
|
Utils::Process process;
|
||||||
|
process.setCommand({ toolPath, { "--version" } });
|
||||||
|
process.start();
|
||||||
|
if (process.waitForFinished())
|
||||||
|
return Version::fromString(process.cleanedStdOut());
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
Store ToolWrapper::toVariantMap() const
|
||||||
|
{
|
||||||
|
Utils::Store data;
|
||||||
|
data.insert(Constants::ToolsSettings::NAME_KEY, m_name);
|
||||||
|
data.insert(Constants::ToolsSettings::EXE_KEY, m_exe.toSettings());
|
||||||
|
data.insert(Constants::ToolsSettings::AUTO_DETECTED_KEY, m_autoDetected);
|
||||||
|
data.insert(Constants::ToolsSettings::ID_KEY, m_id.toSetting());
|
||||||
|
if (m_toolType == ToolType::Meson)
|
||||||
|
data.insert(Constants::ToolsSettings::TOOL_TYPE_KEY, Constants::ToolsSettings::TOOL_TYPE_MESON);
|
||||||
|
else
|
||||||
|
data.insert(Constants::ToolsSettings::TOOL_TYPE_KEY, Constants::ToolsSettings::TOOL_TYPE_NINJA);
|
||||||
|
;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename First>
|
||||||
|
void impl_option_cat(QStringList &list, const First &first)
|
||||||
|
{
|
||||||
|
list.append(first);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename First, typename... T>
|
||||||
|
void impl_option_cat(QStringList &list, const First &first, const T &...args)
|
||||||
|
{
|
||||||
|
impl_option_cat(list, first);
|
||||||
|
impl_option_cat(list, args...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename... T>
|
||||||
|
QStringList options_cat(const T &...args)
|
||||||
|
{
|
||||||
|
QStringList result;
|
||||||
|
impl_option_cat(result, args...);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Command ToolWrapper::setup(const FilePath &sourceDirectory,
|
||||||
|
const FilePath &buildDirectory,
|
||||||
|
const QStringList &options) const
|
||||||
|
{
|
||||||
|
return {{m_exe, options_cat("setup", options, sourceDirectory.path(), buildDirectory.path())},
|
||||||
|
sourceDirectory};
|
||||||
|
}
|
||||||
|
|
||||||
|
Command ToolWrapper::configure(const FilePath &sourceDirectory,
|
||||||
|
const FilePath &buildDirectory,
|
||||||
|
const QStringList &options) const
|
||||||
|
{
|
||||||
|
if (!isSetup(buildDirectory))
|
||||||
|
return setup(sourceDirectory, buildDirectory, options);
|
||||||
|
return {{m_exe, options_cat("configure", options, buildDirectory.path())},
|
||||||
|
buildDirectory};
|
||||||
|
}
|
||||||
|
|
||||||
|
Command ToolWrapper::regenerate(const FilePath &sourceDirectory,
|
||||||
|
const FilePath &buildDirectory) const
|
||||||
|
{
|
||||||
|
return {{m_exe,
|
||||||
|
options_cat("--internal",
|
||||||
|
"regenerate",
|
||||||
|
sourceDirectory.path(),
|
||||||
|
buildDirectory.path(),
|
||||||
|
"--backend",
|
||||||
|
"ninja")},
|
||||||
|
buildDirectory};
|
||||||
|
}
|
||||||
|
|
||||||
|
Command ToolWrapper::introspect(const Utils::FilePath &sourceDirectory) const
|
||||||
|
{
|
||||||
|
return {{m_exe,
|
||||||
|
{"introspect", "--all", QString("%1/meson.build").arg(sourceDirectory.path())}},
|
||||||
|
sourceDirectory};
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename File_t>
|
||||||
|
bool containsFiles(const QString &path, const File_t &file)
|
||||||
|
{
|
||||||
|
return QFileInfo::exists(QString("%1/%2").arg(path).arg(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename File_t, typename... T>
|
||||||
|
bool containsFiles(const QString &path, const File_t &file, const T &...files)
|
||||||
|
{
|
||||||
|
return containsFiles(path, file) && containsFiles(path, files...);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool run_meson(const Command &command, QIODevice *output)
|
||||||
|
{
|
||||||
|
Utils::Process process;
|
||||||
|
process.setWorkingDirectory(command.workDir);
|
||||||
|
process.setCommand(command.cmdLine);
|
||||||
|
process.start();
|
||||||
|
if (!process.waitForFinished())
|
||||||
|
return false;
|
||||||
|
if (output) {
|
||||||
|
output->write(process.rawStdOut());
|
||||||
|
}
|
||||||
|
return process.exitCode() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isSetup(const Utils::FilePath &buildPath)
|
||||||
|
{
|
||||||
|
using namespace Utils;
|
||||||
|
return containsFiles(buildPath.pathAppended(Constants::MESON_INFO_DIR).toString(),
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::optional<FilePath> findToolHelper(const QStringList &exeNames)
|
||||||
|
{
|
||||||
|
Environment systemEnvironment = Environment::systemEnvironment();
|
||||||
|
for (const auto &exe : exeNames) {
|
||||||
|
const FilePath exe_path = systemEnvironment.searchInPath(exe);
|
||||||
|
if (exe_path.exists())
|
||||||
|
return exe_path;
|
||||||
|
}
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<FilePath> findTool(ToolType toolType)
|
||||||
|
{
|
||||||
|
if (toolType == ToolType::Meson)
|
||||||
|
return findToolHelper({"meson.py", "meson"});
|
||||||
|
if (toolType == ToolType::Ninja)
|
||||||
|
return findToolHelper({"ninja", "ninja-build"});
|
||||||
|
QTC_CHECK(false);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<MesonTools::Tool_t> s_tools;
|
std::vector<MesonTools::Tool_t> s_tools;
|
||||||
|
|
||||||
static MesonTools::Tool_t findTool(const Id &id, ToolType toolType)
|
static MesonTools::Tool_t findTool(const Id &id, ToolType toolType)
|
||||||
|
@@ -3,12 +3,86 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "toolwrapper.h"
|
#include "versionhelper.h"
|
||||||
|
|
||||||
|
#include <utils/commandline.h>
|
||||||
|
#include <utils/id.h>
|
||||||
|
#include <utils/store.h>
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace MesonProjectManager::Internal {
|
namespace MesonProjectManager::Internal {
|
||||||
|
|
||||||
|
enum class ToolType { Meson, Ninja };
|
||||||
|
|
||||||
|
class Command
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Utils::CommandLine cmdLine;
|
||||||
|
Utils::FilePath workDir;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ToolWrapper final
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ToolWrapper() = delete;
|
||||||
|
explicit ToolWrapper(const Utils::Store &data);
|
||||||
|
ToolWrapper(ToolType toolType,
|
||||||
|
const QString &name,
|
||||||
|
const Utils::FilePath &path,
|
||||||
|
bool autoDetected = false);
|
||||||
|
ToolWrapper(ToolType toolType,
|
||||||
|
const QString &name,
|
||||||
|
const Utils::FilePath &path,
|
||||||
|
const Utils::Id &id,
|
||||||
|
bool autoDetected = false);
|
||||||
|
|
||||||
|
~ToolWrapper();
|
||||||
|
|
||||||
|
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; }
|
||||||
|
|
||||||
|
void setName(const QString &newName) { m_name = newName; }
|
||||||
|
void setExe(const Utils::FilePath &newExe);
|
||||||
|
|
||||||
|
static Version read_version(const Utils::FilePath &toolPath);
|
||||||
|
|
||||||
|
Utils::Store toVariantMap() const;
|
||||||
|
|
||||||
|
ToolType toolType() const { return m_toolType; }
|
||||||
|
void setToolType(ToolType newToolType) { m_toolType = newToolType; }
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ToolType m_toolType;
|
||||||
|
Version m_version;
|
||||||
|
bool m_isValid;
|
||||||
|
bool m_autoDetected;
|
||||||
|
Utils::Id m_id;
|
||||||
|
Utils::FilePath m_exe;
|
||||||
|
QString m_name;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool run_meson(const Command &command, QIODevice *output = nullptr);
|
||||||
|
|
||||||
|
bool isSetup(const Utils::FilePath &buildPath);
|
||||||
|
|
||||||
|
std::optional<Utils::FilePath> findTool(ToolType toolType);
|
||||||
|
|
||||||
class MesonTools : public QObject
|
class MesonTools : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
// Copyright (C) 2020 Alexis Jeandet.
|
// Copyright (C) 2020 Alexis Jeandet.
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
#include "toolwrapper.h"
|
|
||||||
#include "mesoninfoparser.h"
|
#include "mesoninfoparser.h"
|
||||||
|
#include "mesontools.h"
|
||||||
|
|
||||||
#include <utils/launcherinterface.h>
|
#include <utils/launcherinterface.h>
|
||||||
#include <utils/singleton.h>
|
#include <utils/singleton.h>
|
||||||
@@ -19,15 +19,15 @@
|
|||||||
using namespace MesonProjectManager::Internal;
|
using namespace MesonProjectManager::Internal;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
struct projectData
|
struct ProjectData
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
QString path;
|
QString path;
|
||||||
QStringList targets;
|
QStringList targets;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const QList<projectData> projectList{
|
static const ProjectData projectList[] =
|
||||||
{"Simple C Project", "simplecproject", {"SimpleCProject"}}};
|
{{"Simple C Project", "simplecproject", {"SimpleCProject"}}};
|
||||||
|
|
||||||
|
|
||||||
#define WITH_UNCONFIGURED_PROJECT(_source_dir, _intro_file, ...) \
|
#define WITH_UNCONFIGURED_PROJECT(_source_dir, _intro_file, ...) \
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
// Copyright (C) 2020 Alexis Jeandet.
|
// Copyright (C) 2020 Alexis Jeandet.
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
#include "../toolwrapper.h"
|
#include "../mesontools.h"
|
||||||
|
|
||||||
#include <utils/launcherinterface.h>
|
#include <utils/launcherinterface.h>
|
||||||
#include <utils/singleton.h>
|
#include <utils/singleton.h>
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "toolwrapper.h"
|
#include "mesontools.h"
|
||||||
|
|
||||||
#include <projectexplorer/kit.h>
|
#include <projectexplorer/kit.h>
|
||||||
#include <projectexplorer/kitmanager.h>
|
#include <projectexplorer/kitmanager.h>
|
||||||
|
Reference in New Issue
Block a user