forked from qt-creator/qt-creator
Meson: Inline InfoParser inside mesoninfoparser.h
Change-Id: I29a811ce963f94f90d3cbb07adf72ff3729c3f5e Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -10,7 +10,6 @@ add_qtc_plugin(MesonProjectManager
|
||||
buildoptionsmodel.h
|
||||
buildoptionsparser.h
|
||||
common.h
|
||||
infoparser.h
|
||||
kitdata.h
|
||||
mesonactionsmanager.cpp
|
||||
mesonactionsmanager.h
|
||||
|
||||
@@ -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
|
||||
@@ -5,16 +5,16 @@
|
||||
|
||||
#include "buildoptions.h"
|
||||
#include "buildoptionsparser.h"
|
||||
#include "infoparser.h"
|
||||
#include "common.h"
|
||||
#include "target.h"
|
||||
|
||||
#include <utils/filepath.h>
|
||||
|
||||
#include <QVersionNumber>
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace MesonProjectManager {
|
||||
namespace Internal {
|
||||
namespace MesonInfoParser {
|
||||
namespace MesonProjectManager::Internal::MesonInfoParser {
|
||||
|
||||
class TargetParser
|
||||
{
|
||||
@@ -116,7 +116,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct Result
|
||||
{
|
||||
TargetsList targets;
|
||||
@@ -125,12 +124,22 @@ struct Result
|
||||
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)
|
||||
{
|
||||
return {TargetParser::targetList(buildDir),
|
||||
BuildOptionsParser{buildDir}.takeBuildOptions(),
|
||||
BuildSystemFilesParser::files(buildDir),
|
||||
InfoParser{buildDir}.info()};
|
||||
versionNumber(buildDir)};
|
||||
}
|
||||
|
||||
inline Result parse(const QByteArray &data)
|
||||
@@ -154,11 +163,4 @@ inline Result parse(QIODevice *introFile)
|
||||
return {};
|
||||
}
|
||||
|
||||
inline std::optional<QVersionNumber> mesonInfo(const Utils::FilePath &buildDir)
|
||||
{
|
||||
return InfoParser{buildDir}.info();
|
||||
}
|
||||
|
||||
} // namespace MesonInfoParser
|
||||
} // namespace Internal
|
||||
} // namespace MesonProjectManager
|
||||
} // namespace MesonProjectManager::Internal::MesonInfoParser
|
||||
|
||||
@@ -27,7 +27,6 @@ Project {
|
||||
"mesoninfoparser.h",
|
||||
"buildoptionsparser.h",
|
||||
"common.h",
|
||||
"infoparser.h",
|
||||
"target.h",
|
||||
"mesonpluginconstants.h",
|
||||
"mesonprojectplugin.cpp",
|
||||
|
||||
@@ -309,9 +309,9 @@ bool MesonProjectParser::matchesKit(const KitData &kit)
|
||||
|
||||
bool MesonProjectParser::usesSameMesonVersion(const FilePath &buildPath)
|
||||
{
|
||||
auto info = MesonInfoParser::mesonInfo(buildPath);
|
||||
auto version = MesonInfoParser::versionNumber(buildPath);
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user