Meson: Use QVersionNumber instead of self-made substitute

Change-Id: I6d4168a0be3e14f39baf469f47bc292779fe286a
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2024-07-25 07:05:42 +02:00
parent 319e87fd6c
commit f9bb9feda4
11 changed files with 28 additions and 86 deletions

View File

@@ -54,7 +54,6 @@ add_qtc_plugin(MesonProjectManager
toolssettingsaccessor.h toolssettingsaccessor.h
toolssettingspage.cpp toolssettingspage.cpp
toolssettingspage.h toolssettingspage.h
versionhelper.h
) )
file(RELATIVE_PATH RELATIVE_TEST_PATH "${PROJECT_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}") file(RELATIVE_PATH RELATIVE_TEST_PATH "${PROJECT_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}")

View File

@@ -13,18 +13,15 @@
#include <QJsonObject> #include <QJsonObject>
#include <QJsonValue> #include <QJsonValue>
namespace MesonProjectManager { namespace MesonProjectManager::Internal {
namespace Internal {
class InfoParser class InfoParser
{ {
static inline MesonInfo load_info(const QJsonObject &obj) static inline MesonInfo load_info(const QJsonObject &obj)
{ {
MesonInfo info; MesonInfo info;
auto version = obj["meson_version"].toObject(); auto v = obj["meson_version"].toObject();
info.mesonVersion = Version{version["major"].toInt(), info.mesonVersion = {v["major"].toInt(), v["minor"].toInt(), v["patch"].toInt()};
version["minor"].toInt(),
version["patch"].toInt()};
return info; return info;
} }
MesonInfo m_info; MesonInfo m_info;
@@ -41,5 +38,4 @@ public:
MesonInfo info() { return m_info; } MesonInfo info() { return m_info; }
}; };
} // namespace Internal } // namespace MesonProjectManager::Internal
} // namespace MesonProjectManager

View File

@@ -66,9 +66,9 @@ static KitData createKitData(const Kit *kit)
data.qmakePath = expander->expand(QString("%{Qt:qmakeExecutable}")); data.qmakePath = expander->expand(QString("%{Qt:qmakeExecutable}"));
data.qtVersionStr = expander->expand(QString("%{Qt:Version}")); data.qtVersionStr = expander->expand(QString("%{Qt:Version}"));
data.qtVersion = Utils::QtMajorVersion::None; data.qtVersion = Utils::QtMajorVersion::None;
auto version = Version::fromString(data.qtVersionStr); auto version = QVersionNumber::fromString(data.qtVersionStr);
if (version.isValid) { if (!version.isNull()) {
switch (version.major) { switch (version.majorVersion()) {
case 4: case 4:
data.qtVersion = Utils::QtMajorVersion::Qt4; data.qtVersion = Utils::QtMajorVersion::Qt4;
break; break;

View File

@@ -3,14 +3,14 @@
#pragma once #pragma once
#include "versionhelper.h" #include <QVersionNumber>
namespace MesonProjectManager { namespace MesonProjectManager {
namespace Internal { namespace Internal {
struct MesonInfo struct MesonInfo
{ {
Version mesonVersion; QVersionNumber mesonVersion;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -70,7 +70,6 @@ Project {
"toolssettingsaccessor.h", "toolssettingsaccessor.h",
"toolssettingspage.cpp", "toolssettingspage.cpp",
"toolssettingspage.h", "toolssettingspage.h",
"versionhelper.h",
] ]
} }

View File

@@ -44,7 +44,7 @@ ToolWrapper::ToolWrapper(ToolType toolType,
bool autoDetected) bool autoDetected)
: m_toolType(toolType) : m_toolType(toolType)
, m_version(read_version(path)) , m_version(read_version(path))
, m_isValid{path.exists() && m_version.isValid} , m_isValid{path.exists() && !m_version.isNull()}
, m_autoDetected{autoDetected} , m_autoDetected{autoDetected}
, m_id{Id::generate()} , m_id{Id::generate()}
, m_exe{path} , m_exe{path}
@@ -58,7 +58,7 @@ ToolWrapper::ToolWrapper(ToolType toolType,
bool autoDetected) bool autoDetected)
: m_toolType(toolType) : m_toolType(toolType)
, m_version(read_version(path)) , m_version(read_version(path))
, m_isValid{path.exists() && m_version.isValid} , m_isValid{path.exists() && !m_version.isNull()}
, m_autoDetected{autoDetected} , m_autoDetected{autoDetected}
, m_id{id} , m_id{id}
, m_exe{path} , m_exe{path}
@@ -75,14 +75,14 @@ void ToolWrapper::setExe(const FilePath &newExe)
m_version = read_version(m_exe); m_version = read_version(m_exe);
} }
Version ToolWrapper::read_version(const FilePath &toolPath) QVersionNumber ToolWrapper::read_version(const FilePath &toolPath)
{ {
if (toolPath.toFileInfo().isExecutable()) { if (toolPath.toFileInfo().isExecutable()) {
Process process; Process process;
process.setCommand({ toolPath, { "--version" } }); process.setCommand({ toolPath, { "--version" } });
process.start(); process.start();
if (process.waitForFinished()) if (process.waitForFinished())
return Version::fromString(process.cleanedStdOut()); return QVersionNumber::fromString(process.cleanedStdOut());
} }
return {}; return {};
} }

View File

@@ -3,12 +3,12 @@
#pragma once #pragma once
#include "versionhelper.h"
#include <utils/commandline.h> #include <utils/commandline.h>
#include <utils/id.h> #include <utils/id.h>
#include <utils/store.h> #include <utils/store.h>
#include <QVersionNumber>
#include <optional> #include <optional>
#include <memory> #include <memory>
@@ -40,7 +40,7 @@ public:
~ToolWrapper(); ~ToolWrapper();
const Version &version() const noexcept { return m_version; } const QVersionNumber &version() const noexcept { return m_version; }
bool isValid() const noexcept { return m_isValid; } bool isValid() const noexcept { return m_isValid; }
bool autoDetected() const noexcept { return m_autoDetected; } bool autoDetected() const noexcept { return m_autoDetected; }
Utils::Id id() const noexcept { return m_id; } Utils::Id id() const noexcept { return m_id; }
@@ -50,7 +50,7 @@ public:
void setName(const QString &newName) { m_name = newName; } void setName(const QString &newName) { m_name = newName; }
void setExe(const Utils::FilePath &newExe); void setExe(const Utils::FilePath &newExe);
static Version read_version(const Utils::FilePath &toolPath); static QVersionNumber read_version(const Utils::FilePath &toolPath);
Utils::Store toVariantMap() const; Utils::Store toVariantMap() const;
@@ -69,7 +69,7 @@ public:
private: private:
ToolType m_toolType; ToolType m_toolType;
Version m_version; QVersionNumber m_version;
bool m_isValid; bool m_isValid;
bool m_autoDetected; bool m_autoDetected;
Utils::Id m_id; Utils::Id m_id;

View File

@@ -46,10 +46,10 @@ private slots:
{ {
ToolWrapper meson(ToolType::Meson, "name", *findTool(ToolType::Meson)); ToolWrapper meson(ToolType::Meson, "name", *findTool(ToolType::Meson));
QVERIFY(meson.isValid()); QVERIFY(meson.isValid());
QVERIFY(meson.version().major == 0); QVERIFY(meson.version().majorVersion() == 0);
QVERIFY(meson.version().minor >= 50); QVERIFY(meson.version().minorVersion() >= 50);
QVERIFY(meson.version().minor <= 100); QVERIFY(meson.version().minorVersion() <= 100);
QVERIFY(meson.version().patch >= 0); QVERIFY(meson.version().microVersion() >= 0);
} }
void shouldSetupGivenProjects_data() void shouldSetupGivenProjects_data()

View File

@@ -34,7 +34,7 @@ ToolTreeItem::ToolTreeItem(const MesonTools::Tool_t &tool)
, m_id{tool->id()} , m_id{tool->id()}
, m_autoDetected{tool->autoDetected()} , m_autoDetected{tool->autoDetected()}
{ {
m_tooltip = Tr::tr("Version: %1").arg(tool->version().toQString()); m_tooltip = Tr::tr("Version: %1").arg(tool->version().toString());
self_check(); self_check();
} }
@@ -104,12 +104,12 @@ void ToolTreeItem::self_check()
m_pathIsExecutable = m_executable.toFileInfo().isExecutable(); m_pathIsExecutable = m_executable.toFileInfo().isExecutable();
} }
void ToolTreeItem::update_tooltip(const Version &version) void ToolTreeItem::update_tooltip(const QVersionNumber &version)
{ {
if (version.isValid) if (version.isNull())
m_tooltip = Tr::tr("Version: %1").arg(version.toQString());
else
m_tooltip = Tr::tr("Cannot get tool version."); m_tooltip = Tr::tr("Cannot get tool version.");
else
m_tooltip = Tr::tr("Version: %1").arg(version.toString());
} }
void ToolTreeItem::update_tooltip() void ToolTreeItem::update_tooltip()

View File

@@ -29,7 +29,7 @@ public:
private: private:
void self_check(); void self_check();
void update_tooltip(const Version &version); void update_tooltip(const QVersionNumber &version);
void update_tooltip(); void update_tooltip();
QString m_name; QString m_name;
QString m_tooltip; QString m_tooltip;

View File

@@ -1,52 +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 <QRegularExpression>
namespace MesonProjectManager {
namespace Internal {
struct Version
{
int major = -1;
int minor = -1;
int patch = -1;
bool isValid = false;
Version() = default;
Version(const Version &) = default;
Version(Version &&) = default;
Version &operator=(const Version &) = default;
Version &operator=(Version &&) = default;
bool operator==(const Version &other)
{
return other.isValid && isValid && major == other.major && minor == other.minor
&& patch == other.patch;
}
Version(int major, int minor, int patch)
: major{major}
, minor{minor}
, patch{patch}
, isValid{major != -1 && minor != -1 && patch != -1}
{}
QString toQString() const noexcept
{
return QString("%1.%2.%3").arg(major).arg(minor).arg(patch);
}
static inline Version fromString(const QString &str)
{
QRegularExpression regex{R"((\d+).(\d+).(\d+))"};
auto matched = regex.match(str);
if (matched.hasMatch())
return Version{matched.captured(1).toInt(),
matched.captured(2).toInt(),
matched.captured(3).toInt()};
return Version{};
}
};
} // namespace Internal
} // namespace MesonProjectManager