From eeaea2bff58bc448ce3ebfe4f6a5fb30a2c4b573 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Thu, 20 Jun 2019 15:04:15 +0200 Subject: [PATCH] Use the original appimage environment for launching perfparser 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: https://github.com/KDAB/hotspot/issues/197 --- src/main.cpp | 25 ++++++++++++++++--------- src/parsers/perf/perfparser.cpp | 1 + src/util.cpp | 7 +++++++ src/util.h | 5 +++++ 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0bc30601b..9d04fa55e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,11 +27,13 @@ #include #include +#include #include #include "hotspot-config.h" #include "mainwindow.h" #include "models/data.h" +#include "util.h" #include #include @@ -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(); qRegisterMetaType(); @@ -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(); } diff --git a/src/parsers/perf/perfparser.cpp b/src/parsers/perf/perfparser.cpp index 1f1b1e3e1..275f0465d 100644 --- a/src/parsers/perf/perfparser.cpp +++ b/src/parsers/perf/perfparser.cpp @@ -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")) { diff --git a/src/util.cpp b/src/util.cpp index e166db114..c8b2fd36f 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include @@ -225,3 +226,9 @@ QString Util::formatTooltip(const QString& location, const Data::LocationCost& c } return QString(QLatin1String("") + toolTip + QLatin1String("")); } + +QProcessEnvironment Util::appImageEnvironment() +{ + static const auto env = QProcessEnvironment::systemEnvironment(); + return env; +} diff --git a/src/util.h b/src/util.h index e5e429e45..bf6f73e8a 100644 --- a/src/util.h +++ b/src/util.h @@ -32,6 +32,7 @@ #include class QString; +class QProcessEnvironment; namespace Data { struct Symbol; @@ -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(); }