WebAssembly: Call emrun.py directly instead of via the wrapper script

From now on do on Linux and macOS what was already done on Windows in
order to launch a WebAssembly program: Directly call the emrun.py python
script instead of indirectly via the wrapper shell script.

The wrapper was too fragile. Also, this change consolidates the code
paths on the three host platforms a bit.

Fixes: QTCREATORBUG-25905
Fixes: QTCREATORBUG-26189
Change-Id: If79567e4dc688de460b38daa479becb53d3c5f03
Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Alessandro Portale
2021-10-13 19:54:42 +02:00
parent 40f863b9cf
commit cab210ad36

View File

@@ -40,25 +40,32 @@ using namespace Utils;
namespace WebAssembly {
namespace Internal {
static FilePath pythonInterpreter(const Environment &env)
{
const QString emsdkPythonEnvVarKey("EMSDK_PYTHON");
if (env.hasKey(emsdkPythonEnvVarKey))
return FilePath::fromUserInput(env.value(emsdkPythonEnvVarKey));
// FIXME: Centralize addPythonsFromPath() from the Python plugin and use that
for (const char *interpreterCandidate : {"python3", "python", "python2"}) {
const FilePath interpereter = env.searchInPath(QLatin1String(interpreterCandidate));
if (interpereter.isExecutableFile())
return interpereter;
}
return {};
}
static CommandLine emrunCommand(Target *target, const QString &browser, const QString &port)
{
if (BuildConfiguration *bc = target->activeBuildConfiguration()) {
const QFileInfo emrun = bc->environment().searchInPath("emrun").toFileInfo();
auto html = bc->buildDirectory().pathAppended(target->project()->displayName() + ".html");
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");
// On Windows, we need to use the python interpreter (it comes with the emsdk) to ensure
// that the web server is killed when the application is stopped in Qt Creator.
// On Non-windows, we prefer using the shell script, because that knows how to find the
// right python (not part of emsdk). The shell script stays attached to the server process.
const FilePath interpreter = HostOsInfo::isWindowsHost()
? FilePath::fromUserInput(bc->environment().value("EMSDK_PYTHON"))
: bc->environment().searchInPath("sh");
const QString emrunLaunchScript = HostOsInfo::isWindowsHost()
? emrun.absolutePath() + "/" + emrun.baseName() + ".py"
: emrun.absoluteFilePath();
return CommandLine(interpreter, {
emrunLaunchScript,
return CommandLine(pythonInterpreter(env), {
emrunPy.path(),
"--browser", browser,
"--port", port,
"--no_emrun_detect",