Skip to content

Commit

Permalink
Use the original appimage environment for launching perfparser
Browse files Browse the repository at this point in the history
This ensures that it works on systems that don't yet have Qt 5.10
used for building, as we will then properly pickup the Qt bundled
within the appimage.

Fixes: #197
  • Loading branch information
milianw committed Jun 20, 2019
1 parent 89e8c4e commit eeaea2b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@

#include <QApplication>
#include <QCommandLineParser>
#include <QProcessEnvironment>
#include <QFile>

#include "hotspot-config.h"
#include "mainwindow.h"
#include "models/data.h"
#include "util.h"

#include <ThreadWeaver/ThreadWeaver>
#include <QThread>
Expand All @@ -44,6 +46,20 @@ int main(int argc, char** argv)
QCoreApplication::setApplicationVersion(QStringLiteral(HOTSPOT_VERSION_STRING));

QApplication app(argc, argv);

// init
Util::appImageEnvironment();

#if APPIMAGE_BUILD

// cleanup the environment when we are running from within the AppImage
// to allow launching system applications using Qt without them loading
// the bundled Qt we ship in the AppImage
auto LD_LIBRARY_PATH = qgetenv("LD_LIBRARY_PATH");
LD_LIBRARY_PATH.remove(0, LD_LIBRARY_PATH.indexOf(':') + 1);
qputenv("LD_LIBRARY_PATH", LD_LIBRARY_PATH);
#endif

app.setWindowIcon(QIcon(QStringLiteral(":/images/icons/512-hotspot_app_icon.png")));
qRegisterMetaType<Data::Summary>();
qRegisterMetaType<Data::BottomUp>();
Expand Down Expand Up @@ -150,14 +166,5 @@ int main(int argc, char** argv)
window->show();
}

#if APPIMAGE_BUILD
// cleanup the environment when we are running from within the AppImage
// to allow launching system applications using Qt without them loading
// the bundled Qt we ship in the AppImage
auto LD_LIBRARY_PATH = qgetenv("LD_LIBRARY_PATH");
LD_LIBRARY_PATH.remove(0, LD_LIBRARY_PATH.indexOf(':') + 1);
qputenv("LD_LIBRARY_PATH", LD_LIBRARY_PATH);
#endif

return app.exec();
}
1 change: 1 addition & 0 deletions src/parsers/perf/perfparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ class PerfParserPrivate : public QObject
buffer.buffer().reserve(1024);
buffer.open(QIODevice::ReadOnly);
stream.setDevice(&buffer);
process.setProcessEnvironment(Util::appImageEnvironment());
process.setProcessChannelMode(QProcess::ForwardedErrorChannel);

if (qEnvironmentVariableIntValue("HOTSPOT_GENERATE_SCRIPT_OUTPUT")) {
Expand Down
7 changes: 7 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <QDebug>
#include <QDir>
#include <QFileInfo>
#include <QProcessEnvironment>

#include <initializer_list>

Expand Down Expand Up @@ -225,3 +226,9 @@ QString Util::formatTooltip(const QString& location, const Data::LocationCost& c
}
return QString(QLatin1String("<qt>") + toolTip + QLatin1String("</qt>"));
}

QProcessEnvironment Util::appImageEnvironment()
{
static const auto env = QProcessEnvironment::systemEnvironment();
return env;
}
5 changes: 5 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <QtGlobal>

class QString;
class QProcessEnvironment;

namespace Data {
struct Symbol;
Expand Down Expand Up @@ -69,4 +70,8 @@ QString formatTooltip(int id, const Data::Symbol& symbol, const Data::Costs& sel
const Data::Costs& inclusiveCosts);
QString formatTooltip(const Data::Symbol& symbol, const Data::ItemCost& itemCost, const Data::Costs& totalCosts);
QString formatTooltip(const QString& location, const Data::LocationCost& cost, const Data::Costs& totalCosts);

// the process environment including the custom AppImage-specific LD_LIBRARY_PATH
// this is initialized on the first call and cached internally afterwards
QProcessEnvironment appImageEnvironment();
}

0 comments on commit eeaea2b

Please sign in to comment.