forked from qt-creator/qt-creator
Meson: Filepathify some parsers
Change-Id: I403a78e6a05a531b7ab8b5779fe9f87b0e01fc1d Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -7,6 +7,8 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "mesonpluginconstants.h"
|
#include "mesonpluginconstants.h"
|
||||||
|
|
||||||
|
#include <utils/filepath.h>
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
@@ -72,15 +74,14 @@ class BuildOptionsParser
|
|||||||
std::vector<std::unique_ptr<BuildOption>> m_buildOptions;
|
std::vector<std::unique_ptr<BuildOption>> m_buildOptions;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BuildOptionsParser(const QString &buildDir)
|
BuildOptionsParser(const Utils::FilePath &buildDir)
|
||||||
{
|
{
|
||||||
auto arr = load<QJsonArray>(QString("%1/%2/%3")
|
Utils::FilePath path = buildDir / Constants::MESON_INFO_DIR / Constants::MESON_INTRO_BUIDOPTIONS;
|
||||||
.arg(buildDir)
|
auto arr = load<QJsonArray>(path.toFSPathString());
|
||||||
.arg(Constants::MESON_INFO_DIR)
|
|
||||||
.arg(Constants::MESON_INTRO_BUIDOPTIONS));
|
|
||||||
if (arr)
|
if (arr)
|
||||||
m_buildOptions = load_options(*arr);
|
m_buildOptions = load_options(*arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
BuildOptionsParser(const QJsonDocument &js)
|
BuildOptionsParser(const QJsonDocument &js)
|
||||||
{
|
{
|
||||||
auto obj = get<QJsonArray>(js.object(), "buildoptions");
|
auto obj = get<QJsonArray>(js.object(), "buildoptions");
|
||||||
|
|||||||
@@ -32,12 +32,10 @@ class BuildSystemFilesParser
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BuildSystemFilesParser(const QString &buildDir)
|
BuildSystemFilesParser(const Utils::FilePath &buildDir)
|
||||||
{
|
{
|
||||||
auto arr = load<QJsonArray>(QString("%1/%2/%3")
|
Utils::FilePath path = buildDir / Constants::MESON_INFO_DIR / Constants::MESON_INTRO_BUILDSYSTEM_FILES;
|
||||||
.arg(buildDir)
|
auto arr = load<QJsonArray>(path.toFSPathString());
|
||||||
.arg(Constants::MESON_INFO_DIR)
|
|
||||||
.arg(Constants::MESON_INTRO_BUILDSYSTEM_FILES));
|
|
||||||
appendFiles(arr, m_files);
|
appendFiles(arr, m_files);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,20 +30,14 @@ class InfoParser
|
|||||||
MesonInfo m_info;
|
MesonInfo m_info;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
InfoParser(const QString &buildDir)
|
InfoParser(const Utils::FilePath &buildDir)
|
||||||
/*: AbstractParser(jsonFile(buildDir))*/
|
|
||||||
{
|
{
|
||||||
auto obj = load<QJsonObject>(jsonFile(buildDir));
|
Utils::FilePath jsonFile = buildDir / Constants::MESON_INFO_DIR / Constants::MESON_INFO;
|
||||||
|
auto obj = load<QJsonObject>(jsonFile.toFSPathString());
|
||||||
if (obj)
|
if (obj)
|
||||||
m_info = load_info(*obj);
|
m_info = load_info(*obj);
|
||||||
}
|
}
|
||||||
static inline QString jsonFile(const QString &buildDir)
|
|
||||||
{
|
|
||||||
return QString("%1/%2/%3")
|
|
||||||
.arg(buildDir)
|
|
||||||
.arg(Constants::MESON_INFO_DIR)
|
|
||||||
.arg(Constants::MESON_INFO);
|
|
||||||
}
|
|
||||||
MesonInfo info() { return m_info; }
|
MesonInfo info() { return m_info; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#include "target.h"
|
#include "target.h"
|
||||||
#include "targetparser.h"
|
#include "targetparser.h"
|
||||||
|
|
||||||
#include <utils/fileutils.h>
|
#include <utils/filepath.h>
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ struct Result
|
|||||||
std::optional<MesonInfo> mesonInfo;
|
std::optional<MesonInfo> mesonInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline Result parse(const QString &buildDir)
|
inline Result parse(const Utils::FilePath &buildDir)
|
||||||
{
|
{
|
||||||
return {TargetParser{buildDir}.targetList(),
|
return {TargetParser{buildDir}.targetList(),
|
||||||
BuildOptionsParser{buildDir}.takeBuildOptions(),
|
BuildOptionsParser{buildDir}.takeBuildOptions(),
|
||||||
@@ -58,7 +58,8 @@ inline Result parse(QIODevice *introFile)
|
|||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
inline std::optional<MesonInfo> mesonInfo(const QString &buildDir)
|
|
||||||
|
inline std::optional<MesonInfo> mesonInfo(const Utils::FilePath &buildDir)
|
||||||
{
|
{
|
||||||
return InfoParser{buildDir}.info();
|
return InfoParser{buildDir}.info();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ bool MesonProjectParser::startParser()
|
|||||||
m_parserFutureResult = Utils::asyncRun(
|
m_parserFutureResult = Utils::asyncRun(
|
||||||
ProjectExplorer::ProjectExplorerPlugin::sharedThreadPool(),
|
ProjectExplorer::ProjectExplorerPlugin::sharedThreadPool(),
|
||||||
[processOutput = m_process.stdOut(), introType = m_introType,
|
[processOutput = m_process.stdOut(), introType = m_introType,
|
||||||
buildDir = m_buildDir.toString(), srcDir = m_srcDir] {
|
buildDir = m_buildDir, srcDir = m_srcDir] {
|
||||||
if (introType == IntroDataType::file)
|
if (introType == IntroDataType::file)
|
||||||
return extractParserResults(srcDir, MesonInfoParser::parse(buildDir));
|
return extractParserResults(srcDir, MesonInfoParser::parse(buildDir));
|
||||||
else
|
else
|
||||||
@@ -323,7 +323,7 @@ bool MesonProjectParser::matchesKit(const KitData &kit)
|
|||||||
|
|
||||||
bool MesonProjectParser::usesSameMesonVersion(const Utils::FilePath &buildPath)
|
bool MesonProjectParser::usesSameMesonVersion(const Utils::FilePath &buildPath)
|
||||||
{
|
{
|
||||||
auto info = MesonInfoParser::mesonInfo(buildPath.toString());
|
auto info = MesonInfoParser::mesonInfo(buildPath);
|
||||||
auto meson = MesonTools::mesonWrapper(m_meson);
|
auto meson = MesonTools::mesonWrapper(m_meson);
|
||||||
return info && meson && info->mesonVersion == meson->version();
|
return info && meson && info->mesonVersion == meson->version();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,12 +63,10 @@ class TargetParser
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TargetParser(const QString &buildDir)
|
TargetParser(const Utils::FilePath &buildDir)
|
||||||
{
|
{
|
||||||
auto arr = load<QJsonArray>(QString("%1/%2/%3")
|
Utils::FilePath path = buildDir / Constants::MESON_INFO_DIR / Constants::MESON_INTRO_TARGETS;
|
||||||
.arg(buildDir)
|
auto arr = load<QJsonArray>(path.toFSPathString());
|
||||||
.arg(Constants::MESON_INFO_DIR)
|
|
||||||
.arg(Constants::MESON_INTRO_TARGETS));
|
|
||||||
if (arr)
|
if (arr)
|
||||||
m_targets = load_targets(*arr);
|
m_targets = load_targets(*arr);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace MesonProjectManager::Internal;
|
using namespace MesonProjectManager::Internal;
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
struct projectData
|
struct projectData
|
||||||
{
|
{
|
||||||
@@ -27,22 +28,9 @@ struct projectData
|
|||||||
QStringList targets;
|
QStringList targets;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace {
|
|
||||||
static const QList<projectData> projectList{
|
static const QList<projectData> projectList{
|
||||||
{"Simple C Project", "simplecproject", {"SimpleCProject"}}};
|
{"Simple C Project", "simplecproject", {"SimpleCProject"}}};
|
||||||
} // namespace
|
|
||||||
|
|
||||||
#define WITH_CONFIGURED_PROJECT(_source_dir, _build_dir, ...) \
|
|
||||||
{ \
|
|
||||||
QTemporaryDir _build_dir{"test-meson"}; \
|
|
||||||
const auto tool = MesonWrapper::find(); \
|
|
||||||
QVERIFY(tool.has_value()); \
|
|
||||||
const auto _meson = MesonWrapper("name", *tool); \
|
|
||||||
run_meson(_meson.setup(Utils::FilePath::fromString(_source_dir), \
|
|
||||||
Utils::FilePath::fromString(_build_dir.path()))); \
|
|
||||||
QVERIFY(isSetup(Utils::FilePath::fromString(_build_dir.path()))); \
|
|
||||||
__VA_ARGS__ \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define WITH_UNCONFIGURED_PROJECT(_source_dir, _intro_file, ...) \
|
#define WITH_UNCONFIGURED_PROJECT(_source_dir, _intro_file, ...) \
|
||||||
{ \
|
{ \
|
||||||
@@ -86,15 +74,24 @@ private slots:
|
|||||||
{
|
{
|
||||||
QFETCH(QString, src_dir);
|
QFETCH(QString, src_dir);
|
||||||
QFETCH(QStringList, expectedTargets);
|
QFETCH(QStringList, expectedTargets);
|
||||||
WITH_CONFIGURED_PROJECT(src_dir, build_dir, {
|
|
||||||
auto result = MesonInfoParser::parse(build_dir.path());
|
{
|
||||||
|
QTemporaryDir build_dir{"test-meson"};
|
||||||
|
FilePath buildDir = FilePath::fromString(build_dir.path());
|
||||||
|
const auto tool = MesonWrapper::find();
|
||||||
|
QVERIFY(tool.has_value());
|
||||||
|
MesonWrapper meson("name", *tool);
|
||||||
|
run_meson(meson.setup(FilePath::fromString(src_dir), buildDir));
|
||||||
|
QVERIFY(isSetup(buildDir));
|
||||||
|
|
||||||
|
auto result = MesonInfoParser::parse(buildDir);
|
||||||
QStringList targetsNames;
|
QStringList targetsNames;
|
||||||
std::transform(std::cbegin(result.targets),
|
std::transform(std::cbegin(result.targets),
|
||||||
std::cend(result.targets),
|
std::cend(result.targets),
|
||||||
std::back_inserter(targetsNames),
|
std::back_inserter(targetsNames),
|
||||||
[](const auto &target) { return target.name; });
|
[](const auto &target) { return target.name; });
|
||||||
QVERIFY(targetsNames == expectedTargets);
|
QVERIFY(targetsNames == expectedTargets);
|
||||||
})
|
}
|
||||||
|
|
||||||
WITH_UNCONFIGURED_PROJECT(src_dir, introFile, {
|
WITH_UNCONFIGURED_PROJECT(src_dir, introFile, {
|
||||||
auto result = MesonInfoParser::parse(&introFile);
|
auto result = MesonInfoParser::parse(&introFile);
|
||||||
|
|||||||
Reference in New Issue
Block a user