forked from qt-creator/qt-creator
Meson: Dismantle classes in favor of static methods
Change-Id: Ifefd2847feb57c613a4089ed9d12b0d07d91d30c Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -20,9 +20,7 @@ using namespace Utils;
|
||||
|
||||
namespace MesonProjectManager::Internal::MesonInfoParser {
|
||||
|
||||
class BuildOptionsParser
|
||||
{
|
||||
static inline std::unique_ptr<BuildOption> load_option(const QJsonObject &option)
|
||||
static std::unique_ptr<BuildOption> loadOption(const QJsonObject &option)
|
||||
{
|
||||
const auto type = option["type"].toString();
|
||||
if (type == "string")
|
||||
@@ -61,118 +59,99 @@ class BuildOptionsParser
|
||||
option["description"].toString());
|
||||
}
|
||||
|
||||
static inline std::vector<std::unique_ptr<BuildOption>> load_options(const QJsonArray &arr)
|
||||
static std::vector<std::unique_ptr<BuildOption>> loadOptions(const QJsonArray &arr)
|
||||
{
|
||||
std::vector<std::unique_ptr<BuildOption>> buildOptions;
|
||||
std::transform(std::cbegin(arr),
|
||||
std::cend(arr),
|
||||
std::back_inserter(buildOptions),
|
||||
[](const auto &option) { return load_option(option.toObject()); });
|
||||
[](const auto &option) { return loadOption(option.toObject()); });
|
||||
return buildOptions;
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<BuildOption>> m_buildOptions;
|
||||
|
||||
public:
|
||||
BuildOptionsParser(const FilePath &buildDir)
|
||||
static std::vector<std::unique_ptr<BuildOption>> buildOptionsList(const FilePath &buildDir)
|
||||
{
|
||||
FilePath path = buildDir / Constants::MESON_INFO_DIR / Constants::MESON_INTRO_BUIDOPTIONS;
|
||||
auto arr = load<QJsonArray>(path.toFSPathString());
|
||||
if (arr)
|
||||
m_buildOptions = load_options(*arr);
|
||||
return loadOptions(*arr);
|
||||
return {};
|
||||
}
|
||||
|
||||
BuildOptionsParser(const QJsonDocument &js)
|
||||
static std::vector<std::unique_ptr<BuildOption>> buildOptionsList(const QJsonDocument &js)
|
||||
{
|
||||
auto obj = get<QJsonArray>(js.object(), "buildoptions");
|
||||
if (obj)
|
||||
m_buildOptions = load_options(*obj);
|
||||
return loadOptions(*obj);
|
||||
return {};
|
||||
}
|
||||
|
||||
inline std::vector<std::unique_ptr<BuildOption>> takeBuildOptions()
|
||||
{
|
||||
return std::move(m_buildOptions);
|
||||
}
|
||||
};
|
||||
|
||||
class TargetParser
|
||||
{
|
||||
static inline Target::SourceGroup extract_source(const QJsonValue &source)
|
||||
static Target::SourceGroup extract_source(const QJsonValue &source)
|
||||
{
|
||||
const auto srcObj = source.toObject();
|
||||
return {srcObj["language"].toString(),
|
||||
return {
|
||||
srcObj["language"].toString(),
|
||||
srcObj["compiler"].toVariant().toStringList(),
|
||||
srcObj["parameters"].toVariant().toStringList(),
|
||||
srcObj["sources"].toVariant().toStringList(),
|
||||
srcObj["generated_sources"].toVariant().toStringList()};
|
||||
srcObj["generated_sources"].toVariant().toStringList()
|
||||
};
|
||||
}
|
||||
|
||||
static inline Target::SourceGroupList extract_sources(const QJsonArray &sources)
|
||||
static Target::SourceGroupList extract_sources(const QJsonArray &sources)
|
||||
{
|
||||
Target::SourceGroupList res;
|
||||
std::transform(std::cbegin(sources),
|
||||
std::cend(sources),
|
||||
std::back_inserter(res),
|
||||
extract_source);
|
||||
std::transform(std::cbegin(sources), std::cend(sources), std::back_inserter(res), extract_source);
|
||||
return res;
|
||||
}
|
||||
|
||||
static inline Target extract_target(const QJsonValue &target)
|
||||
static Target extract_target(const QJsonValue &target)
|
||||
{
|
||||
auto targetObj = target.toObject();
|
||||
Target t{targetObj["type"].toString(),
|
||||
return {
|
||||
targetObj["type"].toString(),
|
||||
targetObj["name"].toString(),
|
||||
targetObj["id"].toString(),
|
||||
targetObj["defined_in"].toString(),
|
||||
targetObj["filename"].toVariant().toStringList(),
|
||||
targetObj["extra_files"].toVariant().toStringList(),
|
||||
targetObj["subproject"].toString(),
|
||||
extract_sources(targetObj["target_sources"].toArray())};
|
||||
return t;
|
||||
extract_sources(targetObj["target_sources"].toArray())
|
||||
};
|
||||
}
|
||||
|
||||
static inline TargetsList load_targets(const QJsonArray &arr)
|
||||
static TargetsList load_targets(const QJsonArray &arr)
|
||||
{
|
||||
TargetsList targets;
|
||||
std::transform(std::cbegin(arr),
|
||||
std::cend(arr),
|
||||
std::back_inserter(targets),
|
||||
extract_target);
|
||||
std::transform(std::cbegin(arr), std::cend(arr), std::back_inserter(targets), extract_target);
|
||||
return targets;
|
||||
}
|
||||
|
||||
public:
|
||||
static TargetsList targetList(const QJsonDocument &js)
|
||||
static TargetsList targetsList(const QJsonDocument &js)
|
||||
{
|
||||
if (auto obj = get<QJsonArray>(js.object(), "targets"))
|
||||
return load_targets(*obj);
|
||||
return {};
|
||||
}
|
||||
|
||||
static TargetsList targetList(const FilePath &buildDir)
|
||||
static TargetsList targetsList(const FilePath &buildDir)
|
||||
{
|
||||
const FilePath path = buildDir / Constants::MESON_INFO_DIR / Constants::MESON_INTRO_TARGETS;
|
||||
if (auto arr = load<QJsonArray>(path.toFSPathString()))
|
||||
return load_targets(*arr);
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
class BuildSystemFilesParser
|
||||
{
|
||||
static void appendFiles(const std::optional<QJsonArray> &arr, FilePaths &dest)
|
||||
{
|
||||
if (arr)
|
||||
std::transform(std::cbegin(*arr),
|
||||
std::cend(*arr),
|
||||
std::back_inserter(dest),
|
||||
[](const auto &file) {
|
||||
if (!arr)
|
||||
return;
|
||||
std::transform(std::cbegin(*arr), std::cend(*arr), std::back_inserter(dest), [](const auto &file) {
|
||||
return FilePath::fromString(file.toString());
|
||||
});
|
||||
}
|
||||
|
||||
public:
|
||||
static inline FilePaths files(const FilePath &buildDir)
|
||||
static FilePaths files(const FilePath &buildDir)
|
||||
{
|
||||
FilePaths files;
|
||||
FilePath path = buildDir / Constants::MESON_INFO_DIR / Constants::MESON_INTRO_BUILDSYSTEM_FILES;
|
||||
@@ -181,7 +160,7 @@ public:
|
||||
return files;
|
||||
}
|
||||
|
||||
static inline FilePaths files(const QJsonDocument &js)
|
||||
static FilePaths files(const QJsonDocument &js)
|
||||
{
|
||||
FilePaths files;
|
||||
auto arr = get<QJsonArray>(js.object(), "projectinfo", "buildsystem_files");
|
||||
@@ -193,33 +172,27 @@ public:
|
||||
}
|
||||
return files;
|
||||
}
|
||||
};
|
||||
|
||||
Result parse(const FilePath &buildDir)
|
||||
{
|
||||
return {TargetParser::targetList(buildDir),
|
||||
BuildOptionsParser{buildDir}.takeBuildOptions(),
|
||||
BuildSystemFilesParser::files(buildDir)};
|
||||
return {targetsList(buildDir), buildOptionsList(buildDir), files(buildDir)};
|
||||
}
|
||||
|
||||
Result parse(const QByteArray &data)
|
||||
{
|
||||
auto json = QJsonDocument::fromJson(data);
|
||||
return {TargetParser::targetList(json),
|
||||
BuildOptionsParser{json}.takeBuildOptions(),
|
||||
BuildSystemFilesParser::files(json)};
|
||||
const auto json = QJsonDocument::fromJson(data);
|
||||
return {targetsList(json), buildOptionsList(json), files(json)};
|
||||
}
|
||||
|
||||
Result parse(QIODevice *introFile)
|
||||
{
|
||||
if (introFile) {
|
||||
if (!introFile)
|
||||
return {};
|
||||
if (!introFile->isOpen())
|
||||
introFile->open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
introFile->seek(0);
|
||||
auto data = introFile->readAll();
|
||||
return parse(data);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace MesonProjectManager::Internal::MesonInfoParser
|
||||
|
||||
Reference in New Issue
Block a user