From d79c69918f0b912e737f0bb6b00d39aa5b1fd4ad Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Wed, 4 Oct 2023 10:01:44 +0200 Subject: [PATCH] Docker: Add clangd path to sdktool This patch also allows the user/installer to supply a path without the device root, to make it easier for the installer. Fixes: QTCREATORBUG-29694 Change-Id: I641b06dd2f4a9d94079fb26f2ed949c5246c1c1e Reviewed-by: Reviewed-by: Eike Ziller Reviewed-by: hjk --- src/plugins/docker/dockerdevice.cpp | 25 ++++++++++++++++++++---- src/tools/sdktool/adddeviceoperation.cpp | 15 ++++++++++++-- src/tools/sdktool/adddeviceoperation.h | 1 + 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/plugins/docker/dockerdevice.cpp b/src/plugins/docker/dockerdevice.cpp index 22120f74054..cdb2e8b95e8 100644 --- a/src/plugins/docker/dockerdevice.cpp +++ b/src/plugins/docker/dockerdevice.cpp @@ -232,13 +232,28 @@ DockerDeviceSettings::DockerDeviceSettings() &StringSelectionAspect::refill); clangdExecutable.setValidationFunction( - [](const QString &newValue) -> FancyLineEdit::AsyncValidationFuture { - return asyncRun([newValue]() -> expected_str { + [this](const QString &newValue) -> FancyLineEdit::AsyncValidationFuture { + const FilePath rootPath = FilePath::fromParts(Constants::DOCKER_DEVICE_SCHEME, + repoAndTagEncoded(), + u"/"); + return asyncRun([rootPath, newValue]() -> expected_str { + QString changedValue = newValue; + FilePath path = FilePath::fromUserInput(newValue); + if (!path.needsDevice()) { + const FilePath onDevicePath = rootPath.withNewMappedPath(path); + if (onDevicePath.exists()) { + changedValue = onDevicePath.toUserOutput(); + path = onDevicePath; + } else { + return make_unexpected( + Tr::tr("Path \"%1\" does not exist.").arg(onDevicePath.toUserOutput())); + } + } QString error; - bool result = checkClangdVersion(FilePath::fromUserInput(newValue), &error); + bool result = checkClangdVersion(path, &error); if (!result) return make_unexpected(error); - return newValue; + return changedValue; }); }); @@ -320,6 +335,8 @@ public: { if (deviceSettings->clangdExecutable().isEmpty()) return std::nullopt; + if (!deviceSettings->clangdExecutable().needsDevice()) + return deviceSettings->rootPath().withNewMappedPath(deviceSettings->clangdExecutable()); return deviceSettings->clangdExecutable(); } diff --git a/src/tools/sdktool/adddeviceoperation.cpp b/src/tools/sdktool/adddeviceoperation.cpp index 938ea13cc6d..4838e071058 100644 --- a/src/tools/sdktool/adddeviceoperation.cpp +++ b/src/tools/sdktool/adddeviceoperation.cpp @@ -58,6 +58,7 @@ QString AddDeviceOperation::argumentsHelpText() const " --dockerRepo Docker image repo.\n" " --dockerTag Docker image tag.\n" " --dockerMappedPaths Docker mapped paths (semi-colon separated).\n" + " --dockerClangdExecutable Path to clangd inside the docker " " extra key value pairs\n"); } @@ -219,6 +220,14 @@ bool AddDeviceOperation::setArguments(const QStringList &args) continue; } + if (current == QLatin1String("--dockerClangdExecutable")) { + if (next.isNull()) + return false; + ++i; // skip next; + m_clangdExecutable = next; + continue; + } + if (current == QLatin1String("--dockerRepo")) { if (next.isNull()) return false; @@ -292,14 +301,14 @@ void AddDeviceOperation::unittest() devData.m_dockerMappedPaths = QStringList{"/opt", "/data"}; devData.m_dockerRepo = "repo"; devData.m_dockerTag = "tag"; - + devData.m_clangdExecutable = "clangdexe"; QVariantMap result = devData.addDevice(map); QVariantMap data = result.value(QLatin1String(DEVICEMANAGER_ID)).toMap(); QVariantList devList = data.value(QLatin1String(DEVICE_LIST_ID)).toList(); QCOMPARE(devList.count(), 1); QVariantMap dev = devList.at(0).toMap(); - QCOMPARE(dev.count(), 20); + QCOMPARE(dev.count(), 21); QCOMPARE(dev.value(QLatin1String("Authentication")).toInt(), 2); QCOMPARE(dev.value(QLatin1String("DebugServerKey")).toString(), QLatin1String("debugServer")); QCOMPARE(dev.value(QLatin1String("FreePortsSpec")).toString(), QLatin1String("ports")); @@ -317,6 +326,7 @@ void AddDeviceOperation::unittest() QCOMPARE(dev.value(QLatin1String("Version")).toInt(), 6); QCOMPARE(dev.value(QLatin1String("DockerDeviceDataRepo")).toString(), "repo"); QCOMPARE(dev.value(QLatin1String("DockerDeviceDataTag")).toString(), "tag"); + QCOMPARE(dev.value(QLatin1String("DockerDeviceClangDExecutable")).toString(), "clangdexe"); const QStringList paths = dev.value(QLatin1String("DockerDeviceMappedPaths")).toStringList(); QCOMPARE(paths, QStringList({"/opt", "/data"})); @@ -353,6 +363,7 @@ QVariantMap AddDeviceData::addDevice(const QVariantMap &map) const dev.append(KeyValuePair(QLatin1String("Uname"), QVariant(m_uname))); dev.append(KeyValuePair(QLatin1String("Version"), QVariant(m_version))); dev.append(KeyValuePair(QLatin1String("DockerDeviceMappedPaths"), QVariant(m_dockerMappedPaths))); + dev.append(KeyValuePair(QLatin1String("DockerDeviceClangDExecutable"), QVariant(m_clangdExecutable))); dev.append(KeyValuePair(QLatin1String("DockerDeviceDataRepo"), QVariant(m_dockerRepo))); dev.append(KeyValuePair(QLatin1String("DockerDeviceDataTag"), QVariant(m_dockerTag))); dev.append(m_extra); diff --git a/src/tools/sdktool/adddeviceoperation.h b/src/tools/sdktool/adddeviceoperation.h index d7ae62d235c..8ddbf0069d2 100644 --- a/src/tools/sdktool/adddeviceoperation.h +++ b/src/tools/sdktool/adddeviceoperation.h @@ -43,6 +43,7 @@ public: QStringList m_dockerMappedPaths; QString m_dockerRepo; QString m_dockerTag; + QString m_clangdExecutable; KeyValuePairList m_extra; };