Meson: Inline InfoParser inside mesoninfoparser.h

Change-Id: I29a811ce963f94f90d3cbb07adf72ff3729c3f5e
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2024-07-25 07:36:22 +02:00
parent ed2530a0f9
commit 61b139dbfe
5 changed files with 18 additions and 57 deletions

View File

@@ -10,7 +10,6 @@ add_qtc_plugin(MesonProjectManager
buildoptionsmodel.h buildoptionsmodel.h
buildoptionsparser.h buildoptionsparser.h
common.h common.h
infoparser.h
kitdata.h kitdata.h
mesonactionsmanager.cpp mesonactionsmanager.cpp
mesonactionsmanager.h mesonactionsmanager.h

View File

@@ -1,39 +0,0 @@
// Copyright (C) 2020 Alexis Jeandet.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include "common.h"
#include "mesonpluginconstants.h"
#include <QFile>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include <QVersionNumber>
namespace MesonProjectManager::Internal {
class InfoParser
{
static inline QVersionNumber load_info(const QJsonObject &obj)
{
auto version = obj["meson_version"].toObject();
return {version["major"].toInt(), version["minor"].toInt(), version["patch"].toInt()};
}
QVersionNumber m_info;
public:
InfoParser(const Utils::FilePath &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);
}
QVersionNumber info() { return m_info; }
};
} // namespace MesonProjectManager::Internal

View File

@@ -5,16 +5,16 @@
#include "buildoptions.h" #include "buildoptions.h"
#include "buildoptionsparser.h" #include "buildoptionsparser.h"
#include "infoparser.h" #include "common.h"
#include "target.h" #include "target.h"
#include <utils/filepath.h> #include <utils/filepath.h>
#include <QVersionNumber>
#include <optional> #include <optional>
namespace MesonProjectManager { namespace MesonProjectManager::Internal::MesonInfoParser {
namespace Internal {
namespace MesonInfoParser {
class TargetParser class TargetParser
{ {
@@ -116,7 +116,6 @@ public:
} }
}; };
struct Result struct Result
{ {
TargetsList targets; TargetsList targets;
@@ -125,12 +124,22 @@ struct Result
std::optional<QVersionNumber> mesonInfo; std::optional<QVersionNumber> mesonInfo;
}; };
inline QVersionNumber versionNumber(const Utils::FilePath &buildDir)
{
const Utils::FilePath jsonFile = buildDir / Constants::MESON_INFO_DIR / Constants::MESON_INFO;
auto obj = load<QJsonObject>(jsonFile.toFSPathString());
if (!obj)
return {};
auto version = obj->value("meson_version").toObject();
return {version["major"].toInt(), version["minor"].toInt(), version["patch"].toInt()};
}
inline Result parse(const Utils::FilePath &buildDir) inline Result parse(const Utils::FilePath &buildDir)
{ {
return {TargetParser::targetList(buildDir), return {TargetParser::targetList(buildDir),
BuildOptionsParser{buildDir}.takeBuildOptions(), BuildOptionsParser{buildDir}.takeBuildOptions(),
BuildSystemFilesParser::files(buildDir), BuildSystemFilesParser::files(buildDir),
InfoParser{buildDir}.info()}; versionNumber(buildDir)};
} }
inline Result parse(const QByteArray &data) inline Result parse(const QByteArray &data)
@@ -154,11 +163,4 @@ inline Result parse(QIODevice *introFile)
return {}; return {};
} }
inline std::optional<QVersionNumber> mesonInfo(const Utils::FilePath &buildDir) } // namespace MesonProjectManager::Internal::MesonInfoParser
{
return InfoParser{buildDir}.info();
}
} // namespace MesonInfoParser
} // namespace Internal
} // namespace MesonProjectManager

View File

@@ -27,7 +27,6 @@ Project {
"mesoninfoparser.h", "mesoninfoparser.h",
"buildoptionsparser.h", "buildoptionsparser.h",
"common.h", "common.h",
"infoparser.h",
"target.h", "target.h",
"mesonpluginconstants.h", "mesonpluginconstants.h",
"mesonprojectplugin.cpp", "mesonprojectplugin.cpp",

View File

@@ -309,9 +309,9 @@ bool MesonProjectParser::matchesKit(const KitData &kit)
bool MesonProjectParser::usesSameMesonVersion(const FilePath &buildPath) bool MesonProjectParser::usesSameMesonVersion(const FilePath &buildPath)
{ {
auto info = MesonInfoParser::mesonInfo(buildPath); auto version = MesonInfoParser::versionNumber(buildPath);
auto meson = MesonTools::toolById(m_meson, ToolType::Meson); auto meson = MesonTools::toolById(m_meson, ToolType::Meson);
return info && meson && *info == meson->version(); return !version.isNull() && meson && version == meson->version();
} }
bool MesonProjectParser::run(const Command &command, bool MesonProjectParser::run(const Command &command,