WebAssembly: Provide diagnostics for an unsuccessful emsdk detection

Setting up a working emsdk requires a couple of steps:

1) Installation/clone of emsdk
2) Installation of an SDK
3) Activation of an SDK

If the setup is incomplete, Qt Creator cannot use the emsdk. Until now,
users got no explicit indication of an unsuccessful emsdk detection and
no hint of what could be wrong. This change adds visual diagnostics of
potentially missing emsdk setup steps.

Fixes: QTCREATORBUG-30057
Change-Id: I2dc2d3388be75e8586dc18d24b0a5b57bcffaadb
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
Alessandro Portale
2024-07-23 12:49:51 +02:00
parent 72509fbe10
commit 62f68a2f99
4 changed files with 52 additions and 1 deletions

View File

@@ -14,5 +14,7 @@ const char WEBASSEMBLY_DEVICE_DEVICE_ID[] = "WebAssembly Device";
const char WEBASSEMBLY_QT_VERSION[] = "Qt4ProjectManager.QtVersion.WebAssembly";
const char WEBASSEMBLY_RUNCONFIGURATION_EMRUN[] = "WebAssembly.RunConfiguration.Emrun";
const char WEBASSEMBLY_EMSDK_CONFIG_FILE[] = ".emscripten";
} // namespace WebAssembly
} // namespace Constants

View File

@@ -3,6 +3,8 @@
#include "webassemblyemsdk.h"
#include "webassemblyconstants.h"
#include <coreplugin/icore.h>
#include <coreplugin/settingsdatabase.h>
@@ -26,7 +28,7 @@ const char emSdkVersionKey[] = "WebAssembly/emSdkVersion1";
const FilePath timeStampFile(const FilePath &sdkRoot)
{
return sdkRoot / ".emscripten";
return sdkRoot / Constants::WEBASSEMBLY_EMSDK_CONFIG_FILE;
}
static QString emSdkEnvOutput(const FilePath &sdkRoot)

View File

@@ -73,6 +73,13 @@ WebAssemblySettings::WebAssemblySettings()
instruction->setOpenExternalLinks(true);
instruction->setWordWrap(true);
m_statusIsEmsdkDir = new InfoLabel(Tr::tr("The chosen directory is an emsdk location."));
m_statusSdkInstalled = new InfoLabel(Tr::tr("An SDK is installed."));
m_statusSdkActivated = new InfoLabel(Tr::tr("An SDK is activated."));
m_statusSdkValid = new InfoLabel(Tr::tr("The activated SDK is usable by %1.")
.arg(QGuiApplication::applicationDisplayName()),
InfoLabel::NotOk);
m_emSdkVersionDisplay = new InfoLabel;
m_emSdkVersionDisplay->setElideMode(Qt::ElideNone);
m_emSdkVersionDisplay->setWordWrap(true);
@@ -98,6 +105,10 @@ WebAssemblySettings::WebAssemblySettings()
Column {
instruction,
emSdk,
m_statusIsEmsdkDir,
m_statusSdkInstalled,
m_statusSdkActivated,
m_statusSdkValid,
m_emSdkVersionDisplay,
},
},
@@ -122,6 +133,27 @@ WebAssemblySettings::WebAssemblySettings()
readSettings();
}
enum EmsdkError {
EmsdkErrorUnknown,
EmsdkErrorNoDir,
EmsdkErrorNoEmsdkDir,
EmsdkErrorNoSdkInstalled,
EmsdkErrorNoSdkActivated,
};
static EmsdkError emsdkError(const Utils::FilePath &sdkRoot)
{
if (!sdkRoot.exists())
return EmsdkErrorNoDir;
if (!(sdkRoot / "emsdk").refersToExecutableFile(FilePath::WithBatSuffix))
return EmsdkErrorNoEmsdkDir;
if (!(sdkRoot / "upstream/.emsdk_version").isReadableFile())
return EmsdkErrorNoSdkInstalled;
if (!(sdkRoot / Constants::WEBASSEMBLY_EMSDK_CONFIG_FILE).isReadableFile())
return EmsdkErrorNoSdkActivated;
return EmsdkErrorUnknown;
}
void WebAssemblySettings::updateStatus()
{
WebAssemblyEmSdk::clearCaches();
@@ -129,6 +161,10 @@ void WebAssemblySettings::updateStatus()
const Utils::FilePath newEmSdk = emSdk.pathChooser()->filePath();
const bool sdkValid = newEmSdk.exists() && WebAssemblyEmSdk::isValid(newEmSdk);
m_statusIsEmsdkDir->setVisible(!sdkValid);
m_statusSdkInstalled->setVisible(!sdkValid);
m_statusSdkActivated->setVisible(!sdkValid);
m_statusSdkValid->setVisible(!sdkValid);
m_emSdkVersionDisplay->setVisible(sdkValid);
m_emSdkEnvDisplay->setEnabled(sdkValid);
@@ -148,6 +184,13 @@ void WebAssemblySettings::updateStatus()
.arg(bold(sdkVersion.toString())));
m_emSdkEnvDisplay->setText(environmentDisplay(newEmSdk));
} else {
const EmsdkError error = emsdkError(newEmSdk);
const bool isEmsdkDir = error != EmsdkErrorNoDir && error != EmsdkErrorNoEmsdkDir;
m_statusIsEmsdkDir->setType(isEmsdkDir ? InfoLabel::Ok : InfoLabel::NotOk);
const bool sdkInstalled = isEmsdkDir && error != EmsdkErrorNoSdkInstalled;
m_statusSdkInstalled->setType(sdkInstalled ? InfoLabel::Ok : InfoLabel::NotOk);
const bool sdkActivated = sdkInstalled && error != EmsdkErrorNoSdkActivated;
m_statusSdkActivated->setType(sdkActivated ? InfoLabel::Ok : InfoLabel::NotOk);
m_emSdkEnvDisplay->clear();
}

View File

@@ -21,6 +21,10 @@ public:
Utils::FilePathAspect emSdk{this};
private:
Utils::InfoLabel *m_statusIsEmsdkDir = nullptr;
Utils::InfoLabel *m_statusSdkInstalled = nullptr;
Utils::InfoLabel *m_statusSdkActivated = nullptr;
Utils::InfoLabel *m_statusSdkValid = nullptr;
Utils::InfoLabel *m_emSdkVersionDisplay = nullptr;
QTextBrowser *m_emSdkEnvDisplay = nullptr;
Utils::InfoLabel *m_qtVersionDisplay = nullptr;