From dd1882b8177a8059a159f52d22ea73c66f31427c Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Fri, 12 Nov 2021 10:05:42 +0100 Subject: [PATCH] WebAssembly: fix the running of targets with name != project.name The new QtQuick application wizard for Qt 6.2-based applications now uses different names for the project and for the main target. The WebAssembly plugin cannot construct the html file name for launching like .html, anymore. It instead would need to use .html for that. The author of this patch did not manage to programmatically retrieve the target name or buildkey. So, as a hack, we simply chose the first html file that we find in the build directory. Fixes: QTCREATORBUG-26562 Change-Id: I7e929fe265a15501c7275e2c76b7f5fa4ed1e6b5 Reviewed-by: hjk Reviewed-by: Alessandro Portale --- .../webassemblyrunconfiguration.cpp | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/plugins/webassembly/webassemblyrunconfiguration.cpp b/src/plugins/webassembly/webassemblyrunconfiguration.cpp index 123887caf7b..29bd1b5d047 100644 --- a/src/plugins/webassembly/webassemblyrunconfiguration.cpp +++ b/src/plugins/webassembly/webassemblyrunconfiguration.cpp @@ -55,14 +55,20 @@ static FilePath pythonInterpreter(const Environment &env) return {}; } -static CommandLine emrunCommand(Target *target, const QString &browser, const QString &port) +static FilePath htmlFileInDir(const FilePath &dir) { - if (BuildConfiguration *bc = target->activeBuildConfiguration()) { + const FilePaths htmlFiles = dir.dirEntries(QStringList("*.html"), QDir::Files); + return htmlFiles.isEmpty() ? FilePath() : htmlFiles.first(); +} + +static CommandLine emrunCommand(const RunConfiguration *rc, const QString &browser, + const QString &port) +{ + if (BuildConfiguration *bc = rc->target()->activeBuildConfiguration()) { const Environment env = bc->environment(); const FilePath emrun = env.searchInPath("emrun"); const FilePath emrunPy = emrun.absolutePath().pathAppended(emrun.baseName() + ".py"); - const FilePath html = - bc->buildDirectory().pathAppended(target->project()->displayName() + ".html"); + const FilePath html = htmlFileInDir(bc->buildDirectory()); return CommandLine(pythonInterpreter(env), { emrunPy.path(), @@ -91,8 +97,8 @@ public: effectiveEmrunCall->setDisplayStyle(StringAspect::TextEditDisplay); effectiveEmrunCall->setReadOnly(true); - setUpdater([target, effectiveEmrunCall, webBrowserAspect] { - effectiveEmrunCall->setValue(emrunCommand(target, + setUpdater([this, effectiveEmrunCall, webBrowserAspect] { + effectiveEmrunCall->setValue(emrunCommand(this, webBrowserAspect->currentBrowser(), "").toUserOutput()); }); @@ -122,7 +128,7 @@ public: setStarter([this, runControl, portsGatherer] { Runnable r; - r.command = emrunCommand(runControl->target(), + r.command = emrunCommand(runControl->runConfiguration(), runControl->aspect()->currentBrowser(), QString::number(portsGatherer->findEndPoint().port())); SimpleTargetRunner::doStart(r, {});