aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/webassembly
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2019-08-01 17:57:52 +0200
committerhjk <hjk@qt.io>2019-08-07 10:53:21 +0000
commit399f8d2dfff5801fb98a38a35f597ef2f57e4b05 (patch)
tree6b4c5cd93f4f37f4f792650d304b06efa699e0ff /src/plugins/webassembly
parentb6a5de1bb04e7abba9622cf8c6506db83eded4f5 (diff)
WebAssembly: Drop run config inheritance from CustomExecutable
Also, auto-detect free port. Change-Id: I377956ef20a928f1877d702162792e7cae75a202 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Diffstat (limited to 'src/plugins/webassembly')
-rw-r--r--src/plugins/webassembly/webassemblydevice.cpp15
-rw-r--r--src/plugins/webassembly/webassemblydevice.h8
-rw-r--r--src/plugins/webassembly/webassemblyplugin.cpp4
-rw-r--r--src/plugins/webassembly/webassemblyrunconfiguration.cpp112
-rw-r--r--src/plugins/webassembly/webassemblyrunconfiguration.h20
-rw-r--r--src/plugins/webassembly/webassemblyrunconfigurationaspects.cpp7
6 files changed, 91 insertions, 75 deletions
diff --git a/src/plugins/webassembly/webassemblydevice.cpp b/src/plugins/webassembly/webassemblydevice.cpp
index 6f3404990f..e79d67a0f4 100644
--- a/src/plugins/webassembly/webassemblydevice.cpp
+++ b/src/plugins/webassembly/webassemblydevice.cpp
@@ -26,6 +26,12 @@
#include "webassemblyconstants.h"
#include "webassemblydevice.h"
+#include <projectexplorer/devicesupport/deviceprocess.h>
+#include <projectexplorer/runcontrol.h>
+
+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 a231cb66e2..114800f8aa 100644
--- a/src/plugins/webassembly/webassemblydevice.h
+++ b/src/plugins/webassembly/webassemblydevice.h
@@ -25,15 +25,14 @@
#pragma once
-#include <projectexplorer/devicesupport/idevice.h>
-#include <projectexplorer/devicesupport/idevicefactory.h>
+#include <projectexplorer/devicesupport/desktopdevice.h>
#include <QCoreApplication>
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 840381c02b..5fa3c4a983 100644
--- a/src/plugins/webassembly/webassemblyplugin.cpp
+++ b/src/plugins/webassembly/webassemblyplugin.cpp
@@ -36,9 +36,6 @@
#include <projectexplorer/devicesupport/devicemanager.h>
-#include <QMenu>
-#include <QMessageBox>
-
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 563133b9bb..a2b5a7fb50 100644
--- a/src/plugins/webassembly/webassemblyrunconfiguration.cpp
+++ b/src/plugins/webassembly/webassemblyrunconfiguration.cpp
@@ -28,63 +28,103 @@
#include "webassemblyconstants.h"
#include <projectexplorer/buildconfiguration.h>
+#include <projectexplorer/devicesupport/devicemanager.h>
+#include <projectexplorer/devicesupport/deviceusedportsgatherer.h>
+#include <projectexplorer/project.h>
+#include <projectexplorer/runcontrol.h>
#include <projectexplorer/target.h>
-#include <QDir>
+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<ProjectExplorer::ExecutableAspect>();
- 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<ProjectExplorer::WorkingDirectoryAspect>();
- workingDirectoryAspect->setVisible(false);
+ return CommandLine(bc->environment().searchInPath("python"), {
+ emrunScript.absolutePath() + "/" + emrunScript.baseName() + ".py",
+ "--browser", browser,
+ "--port", port,
+ "--no_emrun_detect",
+ html.toString()
+ });
+}
- auto terminalAspect = aspect<ProjectExplorer::TerminalAspect>();
- terminalAspect->setVisible(false);
+// 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<WebBrowserSelectionAspect>(target);
- auto argumentsAspect = aspect<ProjectExplorer::ArgumentsAspect>();
- argumentsAspect->setVisible(false);
+ auto effectiveEmrunCall = addAspect<BaseStringAspect>();
+ effectiveEmrunCall->setLabelText(tr("Effective emrun call:"));
+ effectiveEmrunCall->setDisplayStyle(BaseStringAspect::TextEditDisplay);
+ effectiveEmrunCall->setReadOnly(true);
- auto webBrowserAspect = addAspect<WebBrowserSelectionAspect>(target);
- connect(webBrowserAspect, &WebBrowserSelectionAspect::changed,
- this, &EmrunRunConfiguration::updateConfiguration);
- connect(target->activeBuildConfiguration(),
- &ProjectExplorer::BuildConfiguration::buildDirectoryChanged,
- this, &EmrunRunConfiguration::updateConfiguration);
+ auto updateConfiguration = [target, effectiveEmrunCall, webBrowserAspect] {
+ effectiveEmrunCall->setValue(emrunCommand(target,
+ webBrowserAspect->currentBrowser(),
+ "<port>").toUserOutput());
+ };
- addAspect<EffectiveEmrunCallAspect>();
+ updateConfiguration();
- 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<WebBrowserSelectionAspect>()->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<EmrunRunConfiguration>(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<WebBrowserSelectionAspect>()->currentBrowser())
- + "--no_emrun_detect "
- + target()->activeBuildConfiguration()->buildDirectory().toString()
- + macroExpander()->expandProcessArgs("/%{CurrentProject:Name}.html");
- aspect<ProjectExplorer::ArgumentsAspect>()->setArguments(arguments);
- aspect<EffectiveEmrunCallAspect>()->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 df59c24180..68bc2ae6c2 100644
--- a/src/plugins/webassembly/webassemblyrunconfiguration.h
+++ b/src/plugins/webassembly/webassemblyrunconfiguration.h
@@ -25,30 +25,22 @@
#pragma once
-#include <projectexplorer/customexecutablerunconfiguration.h>
-
-namespace ProjectExplorer {
-class Target;
-}
+#include <projectexplorer/runconfiguration.h>
+#include <projectexplorer/runcontrol.h>
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
+class EmrunRunConfigurationFactory : public ProjectExplorer::FixedRunConfigurationFactory
{
public:
- EmrunRunConfiguration(ProjectExplorer::Target *target, Core::Id id);
-
-private:
- void updateConfiguration();
+ EmrunRunConfigurationFactory();
};
-class EmrunRunConfigurationFactory : public ProjectExplorer::FixedRunConfigurationFactory
+class EmrunRunWorkerFactory : public ProjectExplorer::RunWorkerFactory
{
public:
- EmrunRunConfigurationFactory();
+ EmrunRunWorkerFactory();
};
} // namespace Internal
diff --git a/src/plugins/webassembly/webassemblyrunconfigurationaspects.cpp b/src/plugins/webassembly/webassemblyrunconfigurationaspects.cpp
index 0cee86531d..aacbc67750 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