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 "mesonpluginconstants.h"
|
||||
|
||||
#include <utils/filepath.h>
|
||||
|
||||
#include <QFile>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
@@ -72,15 +74,14 @@ class BuildOptionsParser
|
||||
std::vector<std::unique_ptr<BuildOption>> m_buildOptions;
|
||||
|
||||
public:
|
||||
BuildOptionsParser(const QString &buildDir)
|
||||
BuildOptionsParser(const Utils::FilePath &buildDir)
|
||||
{
|
||||
auto arr = load<QJsonArray>(QString("%1/%2/%3")
|
||||
.arg(buildDir)
|
||||
.arg(Constants::MESON_INFO_DIR)
|
||||
.arg(Constants::MESON_INTRO_BUIDOPTIONS));
|
||||
Utils::FilePath path = buildDir / Constants::MESON_INFO_DIR / Constants::MESON_INTRO_BUIDOPTIONS;
|
||||
auto arr = load<QJsonArray>(path.toFSPathString());
|
||||
if (arr)
|
||||
m_buildOptions = load_options(*arr);
|
||||
}
|
||||
|
||||
BuildOptionsParser(const QJsonDocument &js)
|
||||
{
|
||||
auto obj = get<QJsonArray>(js.object(), "buildoptions");
|
||||
|
||||
@@ -32,12 +32,10 @@ class BuildSystemFilesParser
|
||||
}
|
||||
|
||||
public:
|
||||
BuildSystemFilesParser(const QString &buildDir)
|
||||
BuildSystemFilesParser(const Utils::FilePath &buildDir)
|
||||
{
|
||||
auto arr = load<QJsonArray>(QString("%1/%2/%3")
|
||||
.arg(buildDir)
|
||||
.arg(Constants::MESON_INFO_DIR)
|
||||
.arg(Constants::MESON_INTRO_BUILDSYSTEM_FILES));
|
||||
Utils::FilePath path = buildDir / Constants::MESON_INFO_DIR / Constants::MESON_INTRO_BUILDSYSTEM_FILES;
|
||||
auto arr = load<QJsonArray>(path.toFSPathString());
|
||||
appendFiles(arr, m_files);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,20 +30,14 @@ class InfoParser
|
||||
MesonInfo m_info;
|
||||
|
||||
public:
|
||||
InfoParser(const QString &buildDir)
|
||||
/*: AbstractParser(jsonFile(buildDir))*/
|
||||
InfoParser(const Utils::FilePath &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)
|
||||
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; }
|
||||
};
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "target.h"
|
||||
#include "targetparser.h"
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/filepath.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
@@ -30,7 +30,7 @@ struct Result
|
||||
std::optional<MesonInfo> mesonInfo;
|
||||
};
|
||||
|
||||
inline Result parse(const QString &buildDir)
|
||||
inline Result parse(const Utils::FilePath &buildDir)
|
||||
{
|
||||
return {TargetParser{buildDir}.targetList(),
|
||||
BuildOptionsParser{buildDir}.takeBuildOptions(),
|
||||
@@ -58,7 +58,8 @@ inline Result parse(QIODevice *introFile)
|
||||
}
|
||||
return {};
|
||||
}
|
||||
inline std::optional<MesonInfo> mesonInfo(const QString &buildDir)
|
||||
|
||||
inline std::optional<MesonInfo> mesonInfo(const Utils::FilePath &buildDir)
|
||||
{
|
||||
return InfoParser{buildDir}.info();
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ bool MesonProjectParser::startParser()
|
||||
m_parserFutureResult = Utils::asyncRun(
|
||||
ProjectExplorer::ProjectExplorerPlugin::sharedThreadPool(),
|
||||
[processOutput = m_process.stdOut(), introType = m_introType,
|
||||
buildDir = m_buildDir.toString(), srcDir = m_srcDir] {
|
||||
buildDir = m_buildDir, srcDir = m_srcDir] {
|
||||
if (introType == IntroDataType::file)
|
||||
return extractParserResults(srcDir, MesonInfoParser::parse(buildDir));
|
||||
else
|
||||
@@ -323,7 +323,7 @@ bool MesonProjectParser::matchesKit(const KitData &kit)
|
||||
|
||||
bool MesonProjectParser::usesSameMesonVersion(const Utils::FilePath &buildPath)
|
||||
{
|
||||
auto info = MesonInfoParser::mesonInfo(buildPath.toString());
|
||||
auto info = MesonInfoParser::mesonInfo(buildPath);
|
||||
auto meson = MesonTools::mesonWrapper(m_meson);
|
||||
return info && meson && info->mesonVersion == meson->version();
|
||||
}
|
||||
|
||||
@@ -63,12 +63,10 @@ class TargetParser
|
||||
}
|
||||
|
||||
public:
|
||||
TargetParser(const QString &buildDir)
|
||||
TargetParser(const Utils::FilePath &buildDir)
|
||||
{
|
||||
auto arr = load<QJsonArray>(QString("%1/%2/%3")
|
||||
.arg(buildDir)
|
||||
.arg(Constants::MESON_INFO_DIR)
|
||||
.arg(Constants::MESON_INTRO_TARGETS));
|
||||
Utils::FilePath path = buildDir / Constants::MESON_INFO_DIR / Constants::MESON_INTRO_TARGETS;
|
||||
auto arr = load<QJsonArray>(path.toFSPathString());
|
||||
if (arr)
|
||||
m_targets = load_targets(*arr);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace MesonProjectManager::Internal;
|
||||
using namespace Utils;
|
||||
|
||||
struct projectData
|
||||
{
|
||||
@@ -27,22 +28,9 @@ struct projectData
|
||||
QStringList targets;
|
||||
};
|
||||
|
||||
namespace {
|
||||
static const QList<projectData> projectList{
|
||||
{"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, ...) \
|
||||
{ \
|
||||
@@ -86,15 +74,24 @@ private slots:
|
||||
{
|
||||
QFETCH(QString, src_dir);
|
||||
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;
|
||||
std::transform(std::cbegin(result.targets),
|
||||
std::cend(result.targets),
|
||||
std::back_inserter(targetsNames),
|
||||
[](const auto &target) { return target.name; });
|
||||
QVERIFY(targetsNames == expectedTargets);
|
||||
})
|
||||
}
|
||||
|
||||
WITH_UNCONFIGURED_PROJECT(src_dir, introFile, {
|
||||
auto result = MesonInfoParser::parse(&introFile);
|
||||
|
||||
Reference in New Issue
Block a user