WebAssembly: fix crashes

Change-Id: I9a2a44c85a254628f119eb041036492bc3022cdf
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Tim Jenssen
2019-10-25 19:48:48 +02:00
committed by Tim Jenssen
parent e3904f3b13
commit 51991e3a3e
2 changed files with 34 additions and 28 deletions

View File

@@ -42,17 +42,19 @@ namespace Internal {
static CommandLine emrunCommand(Target *target, const QString &browser, const QString &port)
{
BuildConfiguration *bc = target->activeBuildConfiguration();
const QFileInfo emrunScript = bc->environment().searchInPath("emrun").toFileInfo();
auto html = bc->buildDirectory().pathAppended(target->project()->displayName() + ".html");
if (BuildConfiguration *bc = target->activeBuildConfiguration()) {
const QFileInfo emrunScript = bc->environment().searchInPath("emrun").toFileInfo();
auto html = bc->buildDirectory().pathAppended(target->project()->displayName() + ".html");
return CommandLine(bc->environment().searchInPath("python"), {
emrunScript.absolutePath() + "/" + emrunScript.baseName() + ".py",
"--browser", browser,
"--port", port,
"--no_emrun_detect",
html.toString()
});
return CommandLine(bc->environment().searchInPath("python"), {
emrunScript.absolutePath() + "/" + emrunScript.baseName() + ".py",
"--browser", browser,
"--port", port,
"--no_emrun_detect",
html.toString()
});
}
return {};
}
// Runs a webassembly application via emscripten's "emrun" tool

View File

@@ -41,24 +41,26 @@ static QStringList detectedBrowsers(ProjectExplorer::Target *target)
{
static QStringList result;
if (result.isEmpty()) {
const Utils::Environment environment = target->activeBuildConfiguration()->environment();
const Utils::FilePath emrunPath = environment.searchInPath("emrun");
if (auto bc = target->activeBuildConfiguration()) {
const Utils::Environment environment = bc->environment();
const Utils::FilePath emrunPath = environment.searchInPath("emrun");
QProcess browserLister;
browserLister.setProcessEnvironment(environment.toProcessEnvironment());
browserLister.setProgram(emrunPath.toString());
browserLister.setArguments({"--list_browsers"});
browserLister.start(QIODevice::ReadOnly);
QProcess browserLister;
browserLister.setProcessEnvironment(environment.toProcessEnvironment());
browserLister.setProgram(emrunPath.toString());
browserLister.setArguments({"--list_browsers"});
browserLister.start(QIODevice::ReadOnly);
if (browserLister.waitForFinished()) {
const QByteArray output = browserLister.readAllStandardOutput();
QTextStream ts(output);
QString line;
const QRegularExpression regExp(" - (.*):.*");
while (ts.readLineInto(&line)) {
const QRegularExpressionMatch match = regExp.match(line);
if (match.hasMatch())
result << match.captured(1);
if (browserLister.waitForFinished()) {
const QByteArray output = browserLister.readAllStandardOutput();
QTextStream ts(output);
QString line;
const QRegularExpression regExp(" - (.*):.*");
while (ts.readLineInto(&line)) {
const QRegularExpressionMatch match = regExp.match(line);
if (match.hasMatch())
result << match.captured(1);
}
}
}
}
@@ -68,7 +70,8 @@ static QStringList detectedBrowsers(ProjectExplorer::Target *target)
WebBrowserSelectionAspect::WebBrowserSelectionAspect(ProjectExplorer::Target *target)
: m_availableBrowsers(detectedBrowsers(target))
{
m_currentBrowser = m_availableBrowsers.first();
if (!m_availableBrowsers.isEmpty())
m_currentBrowser = m_availableBrowsers.first();
setDisplayName(tr("Web browser"));
setId("WebBrowserAspect");
setSettingsKey("RunConfiguration.WebBrowser");
@@ -90,7 +93,8 @@ void WebBrowserSelectionAspect::addToConfigurationLayout(QFormLayout *layout)
void WebBrowserSelectionAspect::fromMap(const QVariantMap &map)
{
m_currentBrowser = map.value(BROWSER_KEY, m_availableBrowsers.first()).toString();
if (!m_availableBrowsers.isEmpty())
m_currentBrowser = map.value(BROWSER_KEY, m_availableBrowsers.first()).toString();
}
void WebBrowserSelectionAspect::toMap(QVariantMap &map) const