WebAssembly: Drop run config inheritance from CustomExecutable

Also, auto-detect free port.

Change-Id: I377956ef20a928f1877d702162792e7cae75a202
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
hjk
2019-08-01 17:57:52 +02:00
parent b6a5de1bb0
commit 399f8d2dff
7 changed files with 100 additions and 83 deletions

View File

@@ -55,6 +55,8 @@
#include <QLoggingCategory>
#include <QSettings>
#include <devicesupport/desktopdevice.h>
#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 DesktopDevice>();
const QString rawDisplayName = m_runnable.displayName();
const QString displayName = isDesktop
? QDir::toNativeSeparators(rawDisplayName)

View File

@@ -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)

View File

@@ -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();
};

View File

@@ -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;

View File

@@ -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);
auto terminalAspect = aspect<ProjectExplorer::TerminalAspect>();
terminalAspect->setVisible(false);
auto argumentsAspect = aspect<ProjectExplorer::ArgumentsAspect>();
argumentsAspect->setVisible(false);
auto webBrowserAspect = addAspect<WebBrowserSelectionAspect>(target);
connect(webBrowserAspect, &WebBrowserSelectionAspect::changed,
this, &EmrunRunConfiguration::updateConfiguration);
connect(target->activeBuildConfiguration(),
&ProjectExplorer::BuildConfiguration::buildDirectoryChanged,
this, &EmrunRunConfiguration::updateConfiguration);
addAspect<EffectiveEmrunCallAspect>();
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<WebBrowserSelectionAspect>(target);
auto effectiveEmrunCall = addAspect<BaseStringAspect>();
effectiveEmrunCall->setLabelText(tr("Effective emrun call:"));
effectiveEmrunCall->setDisplayStyle(BaseStringAspect::TextEditDisplay);
effectiveEmrunCall->setReadOnly(true);
auto updateConfiguration = [target, effectiveEmrunCall, webBrowserAspect] {
effectiveEmrunCall->setValue(emrunCommand(target,
webBrowserAspect->currentBrowser(),
"<port>").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<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

View File

@@ -25,31 +25,23 @@
#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
{
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

View File

@@ -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