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 <QLoggingCategory>
#include <QSettings> #include <QSettings>
#include <devicesupport/desktopdevice.h>
#if defined (WITH_JOURNALD) #if defined (WITH_JOURNALD)
#include "journaldwatcher.h" #include "journaldwatcher.h"
#endif #endif
@@ -1098,8 +1100,7 @@ void SimpleTargetRunner::start()
m_launcher.disconnect(this); m_launcher.disconnect(this);
m_launcher.setUseTerminal(m_useTerminal); m_launcher.setUseTerminal(m_useTerminal);
const bool isDesktop = m_device.isNull() const bool isDesktop = m_device.isNull() || m_device.dynamicCast<const DesktopDevice>();
|| m_device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE;
const QString rawDisplayName = m_runnable.displayName(); const QString rawDisplayName = m_runnable.displayName();
const QString displayName = isDesktop const QString displayName = isDesktop
? QDir::toNativeSeparators(rawDisplayName) ? QDir::toNativeSeparators(rawDisplayName)

View File

@@ -26,6 +26,12 @@
#include "webassemblyconstants.h" #include "webassemblyconstants.h"
#include "webassemblydevice.h" #include "webassemblydevice.h"
#include <projectexplorer/devicesupport/deviceprocess.h>
#include <projectexplorer/runcontrol.h>
using namespace ProjectExplorer;
using namespace Utils;
namespace WebAssembly { namespace WebAssembly {
namespace Internal { namespace Internal {
@@ -51,15 +57,6 @@ Utils::OsType WebAssemblyDevice::osType() const
return Utils::OsTypeOther; return Utils::OsTypeOther;
} }
ProjectExplorer::IDeviceWidget *WebAssemblyDevice::createWidget()
{
return nullptr;
}
ProjectExplorer::DeviceProcessSignalOperation::Ptr WebAssemblyDevice::signalOperation() const
{
return {};
}
WebAssemblyDeviceFactory::WebAssemblyDeviceFactory() WebAssemblyDeviceFactory::WebAssemblyDeviceFactory()
: ProjectExplorer::IDeviceFactory(Constants::WEBASSEMBLY_DEVICE_TYPE) : ProjectExplorer::IDeviceFactory(Constants::WEBASSEMBLY_DEVICE_TYPE)

View File

@@ -25,15 +25,14 @@
#pragma once #pragma once
#include <projectexplorer/devicesupport/idevice.h> #include <projectexplorer/devicesupport/desktopdevice.h>
#include <projectexplorer/devicesupport/idevicefactory.h>
#include <QCoreApplication> #include <QCoreApplication>
namespace WebAssembly { namespace WebAssembly {
namespace Internal { namespace Internal {
class WebAssemblyDevice : public ProjectExplorer::IDevice class WebAssemblyDevice : public ProjectExplorer::DesktopDevice
{ {
Q_DECLARE_TR_FUNCTIONS(WebAssembly::Internal::WebAssemblyDevice) Q_DECLARE_TR_FUNCTIONS(WebAssembly::Internal::WebAssemblyDevice)
@@ -42,9 +41,6 @@ public:
Utils::OsType osType() const override; Utils::OsType osType() const override;
ProjectExplorer::IDeviceWidget *createWidget() override;
ProjectExplorer::DeviceProcessSignalOperation::Ptr signalOperation() const override;
private: private:
WebAssemblyDevice(); WebAssemblyDevice();
}; };

View File

@@ -36,9 +36,6 @@
#include <projectexplorer/devicesupport/devicemanager.h> #include <projectexplorer/devicesupport/devicemanager.h>
#include <QMenu>
#include <QMessageBox>
namespace WebAssembly { namespace WebAssembly {
namespace Internal { namespace Internal {
@@ -49,6 +46,7 @@ public:
WebAssemblyDeviceFactory deviceFactory; WebAssemblyDeviceFactory deviceFactory;
WebAssemblyQtVersionFactory qtVersionFactory; WebAssemblyQtVersionFactory qtVersionFactory;
EmrunRunConfigurationFactory emrunRunConfigurationFactory; EmrunRunConfigurationFactory emrunRunConfigurationFactory;
EmrunRunWorkerFactory emrunRunWorkerFactory;
}; };
static WebAssemblyPluginPrivate *dd = nullptr; static WebAssemblyPluginPrivate *dd = nullptr;

View File

@@ -28,63 +28,103 @@
#include "webassemblyconstants.h" #include "webassemblyconstants.h"
#include <projectexplorer/buildconfiguration.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 <projectexplorer/target.h>
#include <QDir> using namespace ProjectExplorer;
using namespace Utils;
namespace WebAssembly { namespace WebAssembly {
namespace Internal { namespace Internal {
EmrunRunConfiguration::EmrunRunConfiguration(ProjectExplorer::Target *target, static CommandLine emrunCommand(Target *target, const QString &browser, const QString &port)
Core::Id id)
: ProjectExplorer::CustomExecutableRunConfiguration(target, id)
{ {
auto executableAspect = aspect<ProjectExplorer::ExecutableAspect>(); BuildConfiguration *bc = target->activeBuildConfiguration();
executableAspect->setExecutable( const QFileInfo emrunScript = bc->environment().searchInPath("emrun").toFileInfo();
target->activeBuildConfiguration()->environment().searchInPath("python")); auto html = bc->buildDirectory().pathAppended(target->project()->displayName() + ".html");
executableAspect->setVisible(false);
auto workingDirectoryAspect = aspect<ProjectExplorer::WorkingDirectoryAspect>(); return CommandLine(bc->environment().searchInPath("python"), {
workingDirectoryAspect->setVisible(false); emrunScript.absolutePath() + "/" + emrunScript.baseName() + ".py",
"--browser", browser,
auto terminalAspect = aspect<ProjectExplorer::TerminalAspect>(); "--port", port,
terminalAspect->setVisible(false); "--no_emrun_detect",
html.toString()
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();
} }
// 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() EmrunRunConfigurationFactory::EmrunRunConfigurationFactory()
: ProjectExplorer::FixedRunConfigurationFactory( : FixedRunConfigurationFactory(EmrunRunConfiguration::tr("Launch with emrun"))
EmrunRunConfiguration::tr("Launch with emrun"))
{ {
registerRunConfiguration<EmrunRunConfiguration>(Constants::WEBASSEMBLY_RUNCONFIGURATION_EMRUN); registerRunConfiguration<EmrunRunConfiguration>(Constants::WEBASSEMBLY_RUNCONFIGURATION_EMRUN);
addSupportedTargetDeviceType(Constants::WEBASSEMBLY_DEVICE_TYPE); addSupportedTargetDeviceType(Constants::WEBASSEMBLY_DEVICE_TYPE);
} }
void EmrunRunConfiguration::updateConfiguration() EmrunRunWorkerFactory::EmrunRunWorkerFactory()
{ {
const QFileInfo emrunScript = setProducer([](RunControl *rc) { return new EmrunRunWorker(rc); });
target()->activeBuildConfiguration()->environment().searchInPath("emrun").toFileInfo(); addSupportedRunMode(ProjectExplorer::Constants::NORMAL_RUN_MODE);
const QString arguments = addSupportedRunConfiguration(Constants::WEBASSEMBLY_RUNCONFIGURATION_EMRUN);
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());
} }
} // namespace Internal } // namespace Internal

View File

@@ -25,31 +25,23 @@
#pragma once #pragma once
#include <projectexplorer/customexecutablerunconfiguration.h> #include <projectexplorer/runconfiguration.h>
#include <projectexplorer/runcontrol.h>
namespace ProjectExplorer {
class Target;
}
namespace WebAssembly { namespace WebAssembly {
namespace Internal { 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 class EmrunRunConfigurationFactory : public ProjectExplorer::FixedRunConfigurationFactory
{ {
public: public:
EmrunRunConfigurationFactory(); EmrunRunConfigurationFactory();
}; };
class EmrunRunWorkerFactory : public ProjectExplorer::RunWorkerFactory
{
public:
EmrunRunWorkerFactory();
};
} // namespace Internal } // namespace Internal
} // namespace Webassembly } // namespace Webassembly

View File

@@ -103,12 +103,5 @@ QString WebBrowserSelectionAspect::currentBrowser() const
return m_currentBrowser; return m_currentBrowser;
} }
EffectiveEmrunCallAspect::EffectiveEmrunCallAspect()
{
setLabelText(tr("Effective emrun call:"));
setDisplayStyle(BaseStringAspect::TextEditDisplay);
setReadOnly(true);
}
} // namespace Internal } // namespace Internal
} // namespace Webassembly } // namespace Webassembly