forked from qt-creator/qt-creator
Meson: Use QVersionNumber instead of self-made substitute
Change-Id: I6d4168a0be3e14f39baf469f47bc292779fe286a Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -54,7 +54,6 @@ add_qtc_plugin(MesonProjectManager
|
||||
toolssettingsaccessor.h
|
||||
toolssettingspage.cpp
|
||||
toolssettingspage.h
|
||||
versionhelper.h
|
||||
)
|
||||
|
||||
file(RELATIVE_PATH RELATIVE_TEST_PATH "${PROJECT_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
@@ -13,18 +13,15 @@
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
|
||||
namespace MesonProjectManager {
|
||||
namespace Internal {
|
||||
namespace MesonProjectManager::Internal {
|
||||
|
||||
class InfoParser
|
||||
{
|
||||
static inline MesonInfo load_info(const QJsonObject &obj)
|
||||
{
|
||||
MesonInfo info;
|
||||
auto version = obj["meson_version"].toObject();
|
||||
info.mesonVersion = Version{version["major"].toInt(),
|
||||
version["minor"].toInt(),
|
||||
version["patch"].toInt()};
|
||||
auto v = obj["meson_version"].toObject();
|
||||
info.mesonVersion = {v["major"].toInt(), v["minor"].toInt(), v["patch"].toInt()};
|
||||
return info;
|
||||
}
|
||||
MesonInfo m_info;
|
||||
@@ -41,5 +38,4 @@ public:
|
||||
MesonInfo info() { return m_info; }
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace MesonProjectManager
|
||||
} // namespace MesonProjectManager::Internal
|
||||
|
||||
@@ -66,9 +66,9 @@ static KitData createKitData(const Kit *kit)
|
||||
data.qmakePath = expander->expand(QString("%{Qt:qmakeExecutable}"));
|
||||
data.qtVersionStr = expander->expand(QString("%{Qt:Version}"));
|
||||
data.qtVersion = Utils::QtMajorVersion::None;
|
||||
auto version = Version::fromString(data.qtVersionStr);
|
||||
if (version.isValid) {
|
||||
switch (version.major) {
|
||||
auto version = QVersionNumber::fromString(data.qtVersionStr);
|
||||
if (!version.isNull()) {
|
||||
switch (version.majorVersion()) {
|
||||
case 4:
|
||||
data.qtVersion = Utils::QtMajorVersion::Qt4;
|
||||
break;
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "versionhelper.h"
|
||||
#include <QVersionNumber>
|
||||
|
||||
namespace MesonProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
struct MesonInfo
|
||||
{
|
||||
Version mesonVersion;
|
||||
QVersionNumber mesonVersion;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -70,7 +70,6 @@ Project {
|
||||
"toolssettingsaccessor.h",
|
||||
"toolssettingspage.cpp",
|
||||
"toolssettingspage.h",
|
||||
"versionhelper.h",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ ToolWrapper::ToolWrapper(ToolType toolType,
|
||||
bool autoDetected)
|
||||
: m_toolType(toolType)
|
||||
, m_version(read_version(path))
|
||||
, m_isValid{path.exists() && m_version.isValid}
|
||||
, m_isValid{path.exists() && !m_version.isNull()}
|
||||
, m_autoDetected{autoDetected}
|
||||
, m_id{Id::generate()}
|
||||
, m_exe{path}
|
||||
@@ -58,7 +58,7 @@ ToolWrapper::ToolWrapper(ToolType toolType,
|
||||
bool autoDetected)
|
||||
: m_toolType(toolType)
|
||||
, m_version(read_version(path))
|
||||
, m_isValid{path.exists() && m_version.isValid}
|
||||
, m_isValid{path.exists() && !m_version.isNull()}
|
||||
, m_autoDetected{autoDetected}
|
||||
, m_id{id}
|
||||
, m_exe{path}
|
||||
@@ -75,14 +75,14 @@ void ToolWrapper::setExe(const FilePath &newExe)
|
||||
m_version = read_version(m_exe);
|
||||
}
|
||||
|
||||
Version ToolWrapper::read_version(const FilePath &toolPath)
|
||||
QVersionNumber ToolWrapper::read_version(const FilePath &toolPath)
|
||||
{
|
||||
if (toolPath.toFileInfo().isExecutable()) {
|
||||
Process process;
|
||||
process.setCommand({ toolPath, { "--version" } });
|
||||
process.start();
|
||||
if (process.waitForFinished())
|
||||
return Version::fromString(process.cleanedStdOut());
|
||||
return QVersionNumber::fromString(process.cleanedStdOut());
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "versionhelper.h"
|
||||
|
||||
#include <utils/commandline.h>
|
||||
#include <utils/id.h>
|
||||
#include <utils/store.h>
|
||||
|
||||
#include <QVersionNumber>
|
||||
|
||||
#include <optional>
|
||||
#include <memory>
|
||||
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
|
||||
~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 autoDetected() const noexcept { return m_autoDetected; }
|
||||
Utils::Id id() const noexcept { return m_id; }
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
void setName(const QString &newName) { m_name = newName; }
|
||||
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;
|
||||
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
|
||||
private:
|
||||
ToolType m_toolType;
|
||||
Version m_version;
|
||||
QVersionNumber m_version;
|
||||
bool m_isValid;
|
||||
bool m_autoDetected;
|
||||
Utils::Id m_id;
|
||||
|
||||
@@ -46,10 +46,10 @@ private slots:
|
||||
{
|
||||
ToolWrapper meson(ToolType::Meson, "name", *findTool(ToolType::Meson));
|
||||
QVERIFY(meson.isValid());
|
||||
QVERIFY(meson.version().major == 0);
|
||||
QVERIFY(meson.version().minor >= 50);
|
||||
QVERIFY(meson.version().minor <= 100);
|
||||
QVERIFY(meson.version().patch >= 0);
|
||||
QVERIFY(meson.version().majorVersion() == 0);
|
||||
QVERIFY(meson.version().minorVersion() >= 50);
|
||||
QVERIFY(meson.version().minorVersion() <= 100);
|
||||
QVERIFY(meson.version().microVersion() >= 0);
|
||||
}
|
||||
|
||||
void shouldSetupGivenProjects_data()
|
||||
|
||||
@@ -34,7 +34,7 @@ ToolTreeItem::ToolTreeItem(const MesonTools::Tool_t &tool)
|
||||
, m_id{tool->id()}
|
||||
, 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();
|
||||
}
|
||||
|
||||
@@ -104,12 +104,12 @@ void ToolTreeItem::self_check()
|
||||
m_pathIsExecutable = m_executable.toFileInfo().isExecutable();
|
||||
}
|
||||
|
||||
void ToolTreeItem::update_tooltip(const Version &version)
|
||||
void ToolTreeItem::update_tooltip(const QVersionNumber &version)
|
||||
{
|
||||
if (version.isValid)
|
||||
m_tooltip = Tr::tr("Version: %1").arg(version.toQString());
|
||||
else
|
||||
if (version.isNull())
|
||||
m_tooltip = Tr::tr("Cannot get tool version.");
|
||||
else
|
||||
m_tooltip = Tr::tr("Version: %1").arg(version.toString());
|
||||
}
|
||||
|
||||
void ToolTreeItem::update_tooltip()
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
|
||||
private:
|
||||
void self_check();
|
||||
void update_tooltip(const Version &version);
|
||||
void update_tooltip(const QVersionNumber &version);
|
||||
void update_tooltip();
|
||||
QString m_name;
|
||||
QString m_tooltip;
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user