forked from qt-creator/qt-creator
Docker: validate clangd version
Do not automatically setup a clangd that is too old and mark them as invalid if they are manually selected. Change-Id: Ie9662a8821df8fc678eabc4b8a08375723b4d1c3 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -21,6 +21,7 @@ add_qtc_library(Utils
|
|||||||
changeset.cpp changeset.h
|
changeset.cpp changeset.h
|
||||||
checkablemessagebox.cpp checkablemessagebox.h
|
checkablemessagebox.cpp checkablemessagebox.h
|
||||||
classnamevalidatinglineedit.cpp classnamevalidatinglineedit.h
|
classnamevalidatinglineedit.cpp classnamevalidatinglineedit.h
|
||||||
|
clangutils.cpp clangutils.h
|
||||||
codegeneration.cpp codegeneration.h
|
codegeneration.cpp codegeneration.h
|
||||||
commandline.cpp commandline.h
|
commandline.cpp commandline.h
|
||||||
completinglineedit.cpp completinglineedit.h
|
completinglineedit.cpp completinglineedit.h
|
||||||
|
66
src/libs/utils/clangutils.cpp
Normal file
66
src/libs/utils/clangutils.cpp
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
// Copyright (C) 2023 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#include "clangutils.h"
|
||||||
|
|
||||||
|
#include "filepath.h"
|
||||||
|
#include "qtcprocess.h"
|
||||||
|
#include "utilstr.h"
|
||||||
|
|
||||||
|
#include <QVersionNumber>
|
||||||
|
|
||||||
|
namespace Utils {
|
||||||
|
|
||||||
|
static QVersionNumber getClangdVersion(const FilePath &clangdFilePath)
|
||||||
|
{
|
||||||
|
QtcProcess clangdProc;
|
||||||
|
clangdProc.setCommand({clangdFilePath, {"--version"}});
|
||||||
|
clangdProc.runBlocking();
|
||||||
|
if (clangdProc.result() != ProcessResult::FinishedWithSuccess)
|
||||||
|
return {};
|
||||||
|
const QString output = clangdProc.allOutput();
|
||||||
|
static const QString versionPrefix = "clangd version ";
|
||||||
|
const int prefixOffset = output.indexOf(versionPrefix);
|
||||||
|
if (prefixOffset == -1)
|
||||||
|
return {};
|
||||||
|
return QVersionNumber::fromString(output.mid(prefixOffset + versionPrefix.length()));
|
||||||
|
}
|
||||||
|
|
||||||
|
QVersionNumber clangdVersion(const FilePath &clangd)
|
||||||
|
{
|
||||||
|
static QHash<FilePath, QPair<QDateTime, QVersionNumber>> versionCache;
|
||||||
|
const QDateTime timeStamp = clangd.lastModified();
|
||||||
|
const auto it = versionCache.find(clangd);
|
||||||
|
if (it == versionCache.end()) {
|
||||||
|
const QVersionNumber version = getClangdVersion(clangd);
|
||||||
|
versionCache.insert(clangd, {timeStamp, version});
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
if (it->first != timeStamp) {
|
||||||
|
it->first = timeStamp;
|
||||||
|
it->second = getClangdVersion(clangd);
|
||||||
|
}
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool checkClangdVersion(const FilePath &clangd, QString *error)
|
||||||
|
{
|
||||||
|
const QVersionNumber version = clangdVersion(clangd);
|
||||||
|
if (version >= minimumClangdVersion())
|
||||||
|
return true;
|
||||||
|
if (error) {
|
||||||
|
*error = version.isNull()
|
||||||
|
? Tr::tr("Failed to retrieve clangd version: Unexpected clangd output.")
|
||||||
|
: Tr::tr("The clangd version is %1, but %2 or greater is required.")
|
||||||
|
.arg(version.toString())
|
||||||
|
.arg(minimumClangdVersion().majorVersion());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVersionNumber minimumClangdVersion()
|
||||||
|
{
|
||||||
|
return QVersionNumber(14);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Utils
|
20
src/libs/utils/clangutils.h
Normal file
20
src/libs/utils/clangutils.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
// Copyright (C) 2023 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "utils_global.h"
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QVersionNumber;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
namespace Utils {
|
||||||
|
|
||||||
|
class FilePath;
|
||||||
|
|
||||||
|
QTCREATOR_UTILS_EXPORT QVersionNumber clangdVersion(const FilePath &clangd);
|
||||||
|
QTCREATOR_UTILS_EXPORT bool checkClangdVersion(const FilePath &clangd, QString *error = nullptr);
|
||||||
|
QTCREATOR_UTILS_EXPORT QVersionNumber minimumClangdVersion();
|
||||||
|
|
||||||
|
} // namespace Utils
|
@@ -64,6 +64,8 @@ Project {
|
|||||||
"changeset.h",
|
"changeset.h",
|
||||||
"checkablemessagebox.cpp",
|
"checkablemessagebox.cpp",
|
||||||
"checkablemessagebox.h",
|
"checkablemessagebox.h",
|
||||||
|
"clangutils.cpp",
|
||||||
|
"clangutils.h",
|
||||||
"classnamevalidatinglineedit.cpp",
|
"classnamevalidatinglineedit.cpp",
|
||||||
"classnamevalidatinglineedit.h",
|
"classnamevalidatinglineedit.h",
|
||||||
"codegeneration.cpp",
|
"codegeneration.cpp",
|
||||||
|
@@ -332,38 +332,6 @@ void ClangdSettings::setData(const Data &data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static QVersionNumber getClangdVersion(const FilePath &clangdFilePath)
|
|
||||||
{
|
|
||||||
Utils::QtcProcess clangdProc;
|
|
||||||
clangdProc.setCommand({clangdFilePath, {"--version"}});
|
|
||||||
clangdProc.start();
|
|
||||||
if (!clangdProc.waitForFinished())
|
|
||||||
return{};
|
|
||||||
const QString output = clangdProc.allOutput();
|
|
||||||
static const QString versionPrefix = "clangd version ";
|
|
||||||
const int prefixOffset = output.indexOf(versionPrefix);
|
|
||||||
if (prefixOffset == -1)
|
|
||||||
return {};
|
|
||||||
return QVersionNumber::fromString(output.mid(prefixOffset + versionPrefix.length()));
|
|
||||||
}
|
|
||||||
|
|
||||||
QVersionNumber ClangdSettings::clangdVersion(const FilePath &clangdFilePath)
|
|
||||||
{
|
|
||||||
static QHash<Utils::FilePath, QPair<QDateTime, QVersionNumber>> versionCache;
|
|
||||||
const QDateTime timeStamp = clangdFilePath.lastModified();
|
|
||||||
const auto it = versionCache.find(clangdFilePath);
|
|
||||||
if (it == versionCache.end()) {
|
|
||||||
const QVersionNumber version = getClangdVersion(clangdFilePath);
|
|
||||||
versionCache.insert(clangdFilePath, {timeStamp, version});
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
if (it->first != timeStamp) {
|
|
||||||
it->first = timeStamp;
|
|
||||||
it->second = getClangdVersion(clangdFilePath);
|
|
||||||
}
|
|
||||||
return it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
static FilePath getClangHeadersPathFromClang(const FilePath &clangdFilePath)
|
static FilePath getClangHeadersPathFromClang(const FilePath &clangdFilePath)
|
||||||
{
|
{
|
||||||
const FilePath clangFilePath = clangdFilePath.absolutePath().pathAppended("clang")
|
const FilePath clangFilePath = clangdFilePath.absolutePath().pathAppended("clang")
|
||||||
@@ -391,7 +359,7 @@ static FilePath getClangHeadersPath(const FilePath &clangdFilePath)
|
|||||||
if (!headersPath.isEmpty())
|
if (!headersPath.isEmpty())
|
||||||
return headersPath;
|
return headersPath;
|
||||||
|
|
||||||
const QVersionNumber version = ClangdSettings::clangdVersion(clangdFilePath);
|
const QVersionNumber version = Utils::clangdVersion(clangdFilePath);
|
||||||
QTC_ASSERT(!version.isNull(), return {});
|
QTC_ASSERT(!version.isNull(), return {});
|
||||||
static const QStringList libDirs{"lib", "lib64"};
|
static const QStringList libDirs{"lib", "lib64"};
|
||||||
for (const QString &libDir : libDirs) {
|
for (const QString &libDir : libDirs) {
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
#include "clangdiagnosticconfig.h"
|
#include "clangdiagnosticconfig.h"
|
||||||
#include "cppeditor_global.h"
|
#include "cppeditor_global.h"
|
||||||
|
|
||||||
|
#include <utils/clangutils.h>
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <utils/id.h>
|
#include <utils/id.h>
|
||||||
|
|
||||||
@@ -159,8 +160,7 @@ public:
|
|||||||
void setData(const Data &data);
|
void setData(const Data &data);
|
||||||
Data data() const { return m_data; }
|
Data data() const { return m_data; }
|
||||||
|
|
||||||
static QVersionNumber clangdVersion(const Utils::FilePath &clangdFilePath);
|
QVersionNumber clangdVersion() const { return Utils::clangdVersion(clangdFilePath()); }
|
||||||
QVersionNumber clangdVersion() const { return clangdVersion(clangdFilePath()); }
|
|
||||||
Utils::FilePath clangdIncludePath() const;
|
Utils::FilePath clangdIncludePath() const;
|
||||||
static Utils::FilePath clangdUserConfigFilePath();
|
static Utils::FilePath clangdUserConfigFilePath();
|
||||||
|
|
||||||
|
@@ -441,17 +441,9 @@ ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsD
|
|||||||
if (!d->clangdChooser.isValid())
|
if (!d->clangdChooser.isValid())
|
||||||
return;
|
return;
|
||||||
const Utils::FilePath clangdPath = d->clangdChooser.filePath();
|
const Utils::FilePath clangdPath = d->clangdChooser.filePath();
|
||||||
const QVersionNumber clangdVersion = ClangdSettings::clangdVersion(clangdPath);
|
QString errorMessage;
|
||||||
if (clangdVersion.isNull()) {
|
if (!Utils::checkClangdVersion(clangdPath, &errorMessage))
|
||||||
labelSetter.setWarning(Tr::tr("Failed to retrieve clangd version: "
|
labelSetter.setWarning(errorMessage);
|
||||||
"Unexpected clangd output."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (clangdVersion < QVersionNumber(14)) {
|
|
||||||
labelSetter.setWarning(Tr::tr("The clangd version is %1, but %2 or greater is required.")
|
|
||||||
.arg(clangdVersion.toString()).arg(14));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
connect(&d->clangdChooser, &Utils::PathChooser::textChanged, this, updateWarningLabel);
|
connect(&d->clangdChooser, &Utils::PathChooser::textChanged, this, updateWarningLabel);
|
||||||
updateWarningLabel();
|
updateWarningLabel();
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
#include "dockertr.h"
|
#include "dockertr.h"
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
|
#include <utils/clangutils.h>
|
||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/layoutbuilder.h>
|
#include <utils/layoutbuilder.h>
|
||||||
@@ -108,6 +109,10 @@ DockerDeviceWidget::DockerDeviceWidget(const IDevice::Ptr &device)
|
|||||||
m_clangdExecutable->setHistoryCompleter("Docker.ClangdExecutable.History");
|
m_clangdExecutable->setHistoryCompleter("Docker.ClangdExecutable.History");
|
||||||
m_clangdExecutable->setAllowPathFromDevice(true);
|
m_clangdExecutable->setAllowPathFromDevice(true);
|
||||||
m_clangdExecutable->setFilePath(m_data.clangdExecutable);
|
m_clangdExecutable->setFilePath(m_data.clangdExecutable);
|
||||||
|
m_clangdExecutable->setValidationFunction(
|
||||||
|
[chooser = m_clangdExecutable](FancyLineEdit *, QString *error) {
|
||||||
|
return Utils::checkClangdVersion(chooser->filePath(), error);
|
||||||
|
});
|
||||||
|
|
||||||
connect(m_clangdExecutable, &PathChooser::rawPathChanged, this, [this, dockerDevice] {
|
connect(m_clangdExecutable, &PathChooser::rawPathChanged, this, [this, dockerDevice] {
|
||||||
m_data.clangdExecutable = m_clangdExecutable->filePath();
|
m_data.clangdExecutable = m_clangdExecutable->filePath();
|
||||||
@@ -177,7 +182,10 @@ DockerDeviceWidget::DockerDeviceWidget(const IDevice::Ptr &device)
|
|||||||
logView->clear();
|
logView->clear();
|
||||||
dockerDevice->updateContainerAccess();
|
dockerDevice->updateContainerAccess();
|
||||||
|
|
||||||
const FilePath clangdPath = dockerDevice->rootPath().withNewPath("clangd").searchInPath();
|
const FilePath clangdPath = dockerDevice->systemEnvironment()
|
||||||
|
.searchInPath("clangd", {}, [](const FilePath &clangd) {
|
||||||
|
return Utils::checkClangdVersion(clangd);
|
||||||
|
});
|
||||||
if (!clangdPath.isEmpty())
|
if (!clangdPath.isEmpty())
|
||||||
m_clangdExecutable->setFilePath(clangdPath);
|
m_clangdExecutable->setFilePath(clangdPath);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user