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,10 +20,8 @@ using namespace Utils;
|
|||||||
|
|
||||||
namespace MesonProjectManager::Internal::MesonInfoParser {
|
namespace MesonProjectManager::Internal::MesonInfoParser {
|
||||||
|
|
||||||
class BuildOptionsParser
|
static std::unique_ptr<BuildOption> loadOption(const QJsonObject &option)
|
||||||
{
|
{
|
||||||
static inline std::unique_ptr<BuildOption> load_option(const QJsonObject &option)
|
|
||||||
{
|
|
||||||
const auto type = option["type"].toString();
|
const auto type = option["type"].toString();
|
||||||
if (type == "string")
|
if (type == "string")
|
||||||
return std::make_unique<StringBuildOption>(option["name"].toString(),
|
return std::make_unique<StringBuildOption>(option["name"].toString(),
|
||||||
@@ -59,130 +57,111 @@ class BuildOptionsParser
|
|||||||
return std::make_unique<UnknownBuildOption>(option["name"].toString(),
|
return std::make_unique<UnknownBuildOption>(option["name"].toString(),
|
||||||
option["section"].toString(),
|
option["section"].toString(),
|
||||||
option["description"].toString());
|
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::vector<std::unique_ptr<BuildOption>> buildOptions;
|
||||||
std::transform(std::cbegin(arr),
|
std::transform(std::cbegin(arr),
|
||||||
std::cend(arr),
|
std::cend(arr),
|
||||||
std::back_inserter(buildOptions),
|
std::back_inserter(buildOptions),
|
||||||
[](const auto &option) { return load_option(option.toObject()); });
|
[](const auto &option) { return loadOption(option.toObject()); });
|
||||||
return buildOptions;
|
return buildOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::unique_ptr<BuildOption>> m_buildOptions;
|
static std::vector<std::unique_ptr<BuildOption>> buildOptionsList(const FilePath &buildDir)
|
||||||
|
{
|
||||||
public:
|
|
||||||
BuildOptionsParser(const FilePath &buildDir)
|
|
||||||
{
|
|
||||||
FilePath path = buildDir / Constants::MESON_INFO_DIR / Constants::MESON_INTRO_BUIDOPTIONS;
|
FilePath path = buildDir / Constants::MESON_INFO_DIR / Constants::MESON_INTRO_BUIDOPTIONS;
|
||||||
auto arr = load<QJsonArray>(path.toFSPathString());
|
auto arr = load<QJsonArray>(path.toFSPathString());
|
||||||
if (arr)
|
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");
|
auto obj = get<QJsonArray>(js.object(), "buildoptions");
|
||||||
if (obj)
|
if (obj)
|
||||||
m_buildOptions = load_options(*obj);
|
return loadOptions(*obj);
|
||||||
}
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
inline std::vector<std::unique_ptr<BuildOption>> takeBuildOptions()
|
static Target::SourceGroup extract_source(const QJsonValue &source)
|
||||||
{
|
|
||||||
return std::move(m_buildOptions);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class TargetParser
|
|
||||||
{
|
{
|
||||||
static inline Target::SourceGroup extract_source(const QJsonValue &source)
|
|
||||||
{
|
|
||||||
const auto srcObj = source.toObject();
|
const auto srcObj = source.toObject();
|
||||||
return {srcObj["language"].toString(),
|
return {
|
||||||
|
srcObj["language"].toString(),
|
||||||
srcObj["compiler"].toVariant().toStringList(),
|
srcObj["compiler"].toVariant().toStringList(),
|
||||||
srcObj["parameters"].toVariant().toStringList(),
|
srcObj["parameters"].toVariant().toStringList(),
|
||||||
srcObj["sources"].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;
|
Target::SourceGroupList res;
|
||||||
std::transform(std::cbegin(sources),
|
std::transform(std::cbegin(sources), std::cend(sources), std::back_inserter(res), extract_source);
|
||||||
std::cend(sources),
|
|
||||||
std::back_inserter(res),
|
|
||||||
extract_source);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Target extract_target(const QJsonValue &target)
|
static Target extract_target(const QJsonValue &target)
|
||||||
{
|
{
|
||||||
auto targetObj = target.toObject();
|
auto targetObj = target.toObject();
|
||||||
Target t{targetObj["type"].toString(),
|
return {
|
||||||
|
targetObj["type"].toString(),
|
||||||
targetObj["name"].toString(),
|
targetObj["name"].toString(),
|
||||||
targetObj["id"].toString(),
|
targetObj["id"].toString(),
|
||||||
targetObj["defined_in"].toString(),
|
targetObj["defined_in"].toString(),
|
||||||
targetObj["filename"].toVariant().toStringList(),
|
targetObj["filename"].toVariant().toStringList(),
|
||||||
targetObj["extra_files"].toVariant().toStringList(),
|
targetObj["extra_files"].toVariant().toStringList(),
|
||||||
targetObj["subproject"].toString(),
|
targetObj["subproject"].toString(),
|
||||||
extract_sources(targetObj["target_sources"].toArray())};
|
extract_sources(targetObj["target_sources"].toArray())
|
||||||
return t;
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline TargetsList load_targets(const QJsonArray &arr)
|
static TargetsList load_targets(const QJsonArray &arr)
|
||||||
{
|
{
|
||||||
TargetsList targets;
|
TargetsList targets;
|
||||||
std::transform(std::cbegin(arr),
|
std::transform(std::cbegin(arr), std::cend(arr), std::back_inserter(targets), extract_target);
|
||||||
std::cend(arr),
|
|
||||||
std::back_inserter(targets),
|
|
||||||
extract_target);
|
|
||||||
return targets;
|
return targets;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
static TargetsList targetsList(const QJsonDocument &js)
|
||||||
static TargetsList targetList(const QJsonDocument &js)
|
{
|
||||||
{
|
|
||||||
if (auto obj = get<QJsonArray>(js.object(), "targets"))
|
if (auto obj = get<QJsonArray>(js.object(), "targets"))
|
||||||
return load_targets(*obj);
|
return load_targets(*obj);
|
||||||
return {};
|
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;
|
const FilePath path = buildDir / Constants::MESON_INFO_DIR / Constants::MESON_INTRO_TARGETS;
|
||||||
if (auto arr = load<QJsonArray>(path.toFSPathString()))
|
if (auto arr = load<QJsonArray>(path.toFSPathString()))
|
||||||
return load_targets(*arr);
|
return load_targets(*arr);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
class BuildSystemFilesParser
|
static void appendFiles(const std::optional<QJsonArray> &arr, FilePaths &dest)
|
||||||
{
|
{
|
||||||
static void appendFiles(const std::optional<QJsonArray> &arr, FilePaths &dest)
|
if (!arr)
|
||||||
{
|
return;
|
||||||
if (arr)
|
std::transform(std::cbegin(*arr), std::cend(*arr), std::back_inserter(dest), [](const auto &file) {
|
||||||
std::transform(std::cbegin(*arr),
|
|
||||||
std::cend(*arr),
|
|
||||||
std::back_inserter(dest),
|
|
||||||
[](const auto &file) {
|
|
||||||
return FilePath::fromString(file.toString());
|
return FilePath::fromString(file.toString());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
static FilePaths files(const FilePath &buildDir)
|
||||||
static inline FilePaths files(const FilePath &buildDir)
|
{
|
||||||
{
|
|
||||||
FilePaths files;
|
FilePaths files;
|
||||||
FilePath path = buildDir / Constants::MESON_INFO_DIR / Constants::MESON_INTRO_BUILDSYSTEM_FILES;
|
FilePath path = buildDir / Constants::MESON_INFO_DIR / Constants::MESON_INTRO_BUILDSYSTEM_FILES;
|
||||||
auto arr = load<QJsonArray>(path.toFSPathString());
|
auto arr = load<QJsonArray>(path.toFSPathString());
|
||||||
appendFiles(arr, files);
|
appendFiles(arr, files);
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline FilePaths files(const QJsonDocument &js)
|
static FilePaths files(const QJsonDocument &js)
|
||||||
{
|
{
|
||||||
FilePaths files;
|
FilePaths files;
|
||||||
auto arr = get<QJsonArray>(js.object(), "projectinfo", "buildsystem_files");
|
auto arr = get<QJsonArray>(js.object(), "projectinfo", "buildsystem_files");
|
||||||
appendFiles(arr, files);
|
appendFiles(arr, files);
|
||||||
@@ -192,34 +171,28 @@ public:
|
|||||||
appendFiles(arr, files);
|
appendFiles(arr, files);
|
||||||
}
|
}
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
Result parse(const FilePath &buildDir)
|
Result parse(const FilePath &buildDir)
|
||||||
{
|
{
|
||||||
return {TargetParser::targetList(buildDir),
|
return {targetsList(buildDir), buildOptionsList(buildDir), files(buildDir)};
|
||||||
BuildOptionsParser{buildDir}.takeBuildOptions(),
|
|
||||||
BuildSystemFilesParser::files(buildDir)};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result parse(const QByteArray &data)
|
Result parse(const QByteArray &data)
|
||||||
{
|
{
|
||||||
auto json = QJsonDocument::fromJson(data);
|
const auto json = QJsonDocument::fromJson(data);
|
||||||
return {TargetParser::targetList(json),
|
return {targetsList(json), buildOptionsList(json), files(json)};
|
||||||
BuildOptionsParser{json}.takeBuildOptions(),
|
|
||||||
BuildSystemFilesParser::files(json)};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result parse(QIODevice *introFile)
|
Result parse(QIODevice *introFile)
|
||||||
{
|
{
|
||||||
if (introFile) {
|
if (!introFile)
|
||||||
|
return {};
|
||||||
if (!introFile->isOpen())
|
if (!introFile->isOpen())
|
||||||
introFile->open(QIODevice::ReadOnly | QIODevice::Text);
|
introFile->open(QIODevice::ReadOnly | QIODevice::Text);
|
||||||
introFile->seek(0);
|
introFile->seek(0);
|
||||||
auto data = introFile->readAll();
|
auto data = introFile->readAll();
|
||||||
return parse(data);
|
return parse(data);
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace MesonProjectManager::Internal::MesonInfoParser
|
} // namespace MesonProjectManager::Internal::MesonInfoParser
|
||||||
|
|||||||
Reference in New Issue
Block a user