diff --git a/src/plugins/projectexplorer/runcontrol.cpp b/src/plugins/projectexplorer/runcontrol.cpp index 0af6282b1c3..5c1cec77e44 100644 --- a/src/plugins/projectexplorer/runcontrol.cpp +++ b/src/plugins/projectexplorer/runcontrol.cpp @@ -55,6 +55,8 @@ #include #include +#include + #if defined (WITH_JOURNALD) #include "journaldwatcher.h" #endif @@ -1098,8 +1100,7 @@ void SimpleTargetRunner::start() m_launcher.disconnect(this); m_launcher.setUseTerminal(m_useTerminal); - const bool isDesktop = m_device.isNull() - || m_device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE; + const bool isDesktop = m_device.isNull() || m_device.dynamicCast(); const QString rawDisplayName = m_runnable.displayName(); const QString displayName = isDesktop ? QDir::toNativeSeparators(rawDisplayName) diff --git a/src/plugins/webassembly/webassemblydevice.cpp b/src/plugins/webassembly/webassemblydevice.cpp index 6f3404990f8..e79d67a0f41 100644 --- a/src/plugins/webassembly/webassemblydevice.cpp +++ b/src/plugins/webassembly/webassemblydevice.cpp @@ -26,6 +26,12 @@ #include "webassemblyconstants.h" #include "webassemblydevice.h" +#include +#include + +using namespace ProjectExplorer; +using namespace Utils; + namespace WebAssembly { namespace Internal { @@ -51,15 +57,6 @@ Utils::OsType WebAssemblyDevice::osType() const return Utils::OsTypeOther; } -ProjectExplorer::IDeviceWidget *WebAssemblyDevice::createWidget() -{ - return nullptr; -} - -ProjectExplorer::DeviceProcessSignalOperation::Ptr WebAssemblyDevice::signalOperation() const -{ - return {}; -} WebAssemblyDeviceFactory::WebAssemblyDeviceFactory() : ProjectExplorer::IDeviceFactory(Constants::WEBASSEMBLY_DEVICE_TYPE) diff --git a/src/plugins/webassembly/webassemblydevice.h b/src/plugins/webassembly/webassemblydevice.h index a231cb66e27..114800f8aac 100644 --- a/src/plugins/webassembly/webassemblydevice.h +++ b/src/plugins/webassembly/webassemblydevice.h @@ -25,15 +25,14 @@ #pragma once -#include -#include +#include #include namespace WebAssembly { namespace Internal { -class WebAssemblyDevice : public ProjectExplorer::IDevice +class WebAssemblyDevice : public ProjectExplorer::DesktopDevice { Q_DECLARE_TR_FUNCTIONS(WebAssembly::Internal::WebAssemblyDevice) @@ -42,9 +41,6 @@ public: Utils::OsType osType() const override; - ProjectExplorer::IDeviceWidget *createWidget() override; - ProjectExplorer::DeviceProcessSignalOperation::Ptr signalOperation() const override; - private: WebAssemblyDevice(); }; diff --git a/src/plugins/webassembly/webassemblyplugin.cpp b/src/plugins/webassembly/webassemblyplugin.cpp index 840381c02be..5fa3c4a9836 100644 --- a/src/plugins/webassembly/webassemblyplugin.cpp +++ b/src/plugins/webassembly/webassemblyplugin.cpp @@ -36,9 +36,6 @@ #include -#include -#include - namespace WebAssembly { namespace Internal { @@ -49,6 +46,7 @@ public: WebAssemblyDeviceFactory deviceFactory; WebAssemblyQtVersionFactory qtVersionFactory; EmrunRunConfigurationFactory emrunRunConfigurationFactory; + EmrunRunWorkerFactory emrunRunWorkerFactory; }; static WebAssemblyPluginPrivate *dd = nullptr; diff --git a/src/plugins/webassembly/webassemblyrunconfiguration.cpp b/src/plugins/webassembly/webassemblyrunconfiguration.cpp index 563133b9bbd..a2b5a7fb500 100644 --- a/src/plugins/webassembly/webassemblyrunconfiguration.cpp +++ b/src/plugins/webassembly/webassemblyrunconfiguration.cpp @@ -28,63 +28,103 @@ #include "webassemblyconstants.h" #include +#include +#include +#include +#include #include -#include +using namespace ProjectExplorer; +using namespace Utils; namespace WebAssembly { namespace Internal { -EmrunRunConfiguration::EmrunRunConfiguration(ProjectExplorer::Target *target, - Core::Id id) - : ProjectExplorer::CustomExecutableRunConfiguration(target, id) +static CommandLine emrunCommand(Target *target, const QString &browser, const QString &port) { - auto executableAspect = aspect(); - executableAspect->setExecutable( - target->activeBuildConfiguration()->environment().searchInPath("python")); - executableAspect->setVisible(false); + BuildConfiguration *bc = target->activeBuildConfiguration(); + const QFileInfo emrunScript = bc->environment().searchInPath("emrun").toFileInfo(); + auto html = bc->buildDirectory().pathAppended(target->project()->displayName() + ".html"); - auto workingDirectoryAspect = aspect(); - workingDirectoryAspect->setVisible(false); - - auto terminalAspect = aspect(); - terminalAspect->setVisible(false); - - auto argumentsAspect = aspect(); - argumentsAspect->setVisible(false); - - auto webBrowserAspect = addAspect(target); - connect(webBrowserAspect, &WebBrowserSelectionAspect::changed, - this, &EmrunRunConfiguration::updateConfiguration); - connect(target->activeBuildConfiguration(), - &ProjectExplorer::BuildConfiguration::buildDirectoryChanged, - this, &EmrunRunConfiguration::updateConfiguration); - - addAspect(); - - updateConfiguration(); + return CommandLine(bc->environment().searchInPath("python"), { + emrunScript.absolutePath() + "/" + emrunScript.baseName() + ".py", + "--browser", browser, + "--port", port, + "--no_emrun_detect", + html.toString() + }); } +// Runs a webassembly application via emscripten's "emrun" tool +// https://emscripten.org/docs/compiling/Running-html-files-with-emrun.html +class EmrunRunConfiguration : public ProjectExplorer::RunConfiguration +{ +public: + EmrunRunConfiguration(Target *target, Core::Id id) + : RunConfiguration(target, id) + { + auto webBrowserAspect = addAspect(target); + + auto effectiveEmrunCall = addAspect(); + effectiveEmrunCall->setLabelText(tr("Effective emrun call:")); + effectiveEmrunCall->setDisplayStyle(BaseStringAspect::TextEditDisplay); + effectiveEmrunCall->setReadOnly(true); + + auto updateConfiguration = [target, effectiveEmrunCall, webBrowserAspect] { + effectiveEmrunCall->setValue(emrunCommand(target, + webBrowserAspect->currentBrowser(), + "").toUserOutput()); + }; + + updateConfiguration(); + + connect(webBrowserAspect, &WebBrowserSelectionAspect::changed, + this, updateConfiguration); + connect(target->activeBuildConfiguration(), &BuildConfiguration::buildDirectoryChanged, + this, updateConfiguration); + } +}; + +class EmrunRunWorker : public SimpleTargetRunner +{ +public: + EmrunRunWorker(RunControl *runControl) + : SimpleTargetRunner(runControl) + { + m_portsGatherer = new PortsGatherer(runControl); + addStartDependency(m_portsGatherer); + } + + void start() final + { + CommandLine cmd = emrunCommand(runControl()->target(), + runControl()->aspect()->currentBrowser(), + m_portsGatherer->findPort().toString()); + Runnable r; + r.setCommandLine(cmd); + setRunnable(r); + + SimpleTargetRunner::start(); + } + + PortsGatherer *m_portsGatherer; +}; + + +// Factories + EmrunRunConfigurationFactory::EmrunRunConfigurationFactory() - : ProjectExplorer::FixedRunConfigurationFactory( - EmrunRunConfiguration::tr("Launch with emrun")) + : FixedRunConfigurationFactory(EmrunRunConfiguration::tr("Launch with emrun")) { registerRunConfiguration(Constants::WEBASSEMBLY_RUNCONFIGURATION_EMRUN); addSupportedTargetDeviceType(Constants::WEBASSEMBLY_DEVICE_TYPE); } -void EmrunRunConfiguration::updateConfiguration() +EmrunRunWorkerFactory::EmrunRunWorkerFactory() { - const QFileInfo emrunScript = - target()->activeBuildConfiguration()->environment().searchInPath("emrun").toFileInfo(); - const QString arguments = - emrunScript.absolutePath() + "/" + emrunScript.baseName() + ".py " - + QString("--browser %1 ").arg(aspect()->currentBrowser()) - + "--no_emrun_detect " - + target()->activeBuildConfiguration()->buildDirectory().toString() - + macroExpander()->expandProcessArgs("/%{CurrentProject:Name}.html"); - aspect()->setArguments(arguments); - aspect()->setValue(commandLine().toUserOutput()); + setProducer([](RunControl *rc) { return new EmrunRunWorker(rc); }); + addSupportedRunMode(ProjectExplorer::Constants::NORMAL_RUN_MODE); + addSupportedRunConfiguration(Constants::WEBASSEMBLY_RUNCONFIGURATION_EMRUN); } } // namespace Internal diff --git a/src/plugins/webassembly/webassemblyrunconfiguration.h b/src/plugins/webassembly/webassemblyrunconfiguration.h index df59c241802..68bc2ae6c25 100644 --- a/src/plugins/webassembly/webassemblyrunconfiguration.h +++ b/src/plugins/webassembly/webassemblyrunconfiguration.h @@ -25,31 +25,23 @@ #pragma once -#include - -namespace ProjectExplorer { -class Target; -} +#include +#include namespace WebAssembly { namespace Internal { -// Runs a webassembly application via emscripten's "emrun" tool -// https://emscripten.org/docs/compiling/Running-html-files-with-emrun.html -class EmrunRunConfiguration : public ProjectExplorer::CustomExecutableRunConfiguration -{ -public: - EmrunRunConfiguration(ProjectExplorer::Target *target, Core::Id id); - -private: - void updateConfiguration(); -}; - class EmrunRunConfigurationFactory : public ProjectExplorer::FixedRunConfigurationFactory { public: EmrunRunConfigurationFactory(); }; +class EmrunRunWorkerFactory : public ProjectExplorer::RunWorkerFactory +{ +public: + EmrunRunWorkerFactory(); +}; + } // namespace Internal } // namespace Webassembly diff --git a/src/plugins/webassembly/webassemblyrunconfigurationaspects.cpp b/src/plugins/webassembly/webassemblyrunconfigurationaspects.cpp index 0cee86531d0..aacbc677509 100644 --- a/src/plugins/webassembly/webassemblyrunconfigurationaspects.cpp +++ b/src/plugins/webassembly/webassemblyrunconfigurationaspects.cpp @@ -103,12 +103,5 @@ QString WebBrowserSelectionAspect::currentBrowser() const return m_currentBrowser; } -EffectiveEmrunCallAspect::EffectiveEmrunCallAspect() -{ - setLabelText(tr("Effective emrun call:")); - setDisplayStyle(BaseStringAspect::TextEditDisplay); - setReadOnly(true); -} - } // namespace Internal } // namespace Webassembly