Merge pull request #893 from Scrumplex/refactor-env-handling
This commit is contained in:
commit
6aad750fe0
@ -18,13 +18,17 @@ LAUNCHER_NAME=@Launcher_APP_BINARY_NAME@
|
|||||||
LAUNCHER_DIR="$(dirname "$(readlink -f "$0")")"
|
LAUNCHER_DIR="$(dirname "$(readlink -f "$0")")"
|
||||||
echo "Launcher Dir: ${LAUNCHER_DIR}"
|
echo "Launcher Dir: ${LAUNCHER_DIR}"
|
||||||
|
|
||||||
# Set up env - filter out input LD_ variables but pass them in under different names
|
# Set up env.
|
||||||
export GAME_LIBRARY_PATH=${GAME_LIBRARY_PATH-${LD_LIBRARY_PATH}}
|
# Pass our custom variables separately so that the launcher can remove them for child processes
|
||||||
export GAME_PRELOAD=${GAME_PRELOAD-${LD_PRELOAD}}
|
export LAUNCHER_LD_LIBRARY_PATH="${LAUNCHER_DIR}/lib@LIB_SUFFIX@"
|
||||||
export LD_LIBRARY_PATH="${LAUNCHER_DIR}/lib@LIB_SUFFIX@":$LAUNCHER_LIBRARY_PATH
|
export LAUNCHER_LD_PRELOAD=""
|
||||||
export LD_PRELOAD=$LAUNCHER_PRELOAD
|
export LAUNCHER_QT_PLUGIN_PATH="${LAUNCHER_DIR}/plugins"
|
||||||
export QT_PLUGIN_PATH="${LAUNCHER_DIR}/plugins"
|
export LAUNCHER_QT_FONTPATH="${LAUNCHER_DIR}/fonts"
|
||||||
export QT_FONTPATH="${LAUNCHER_DIR}/fonts"
|
|
||||||
|
export LD_LIBRARY_PATH="$LAUNCHER_LD_LIBRARY_PATH:$LD_LIBRARY_PATH"
|
||||||
|
export LD_PRELOAD="$LAUNCHER_LD_PRELOAD:$LD_PRELOAD"
|
||||||
|
export QT_PLUGIN_PATH="$LAUNCHER_QT_PLUGIN_PATH:$QT_PLUGIN_PATH"
|
||||||
|
export QT_FONTPATH="$LAUNCHER_QT_FONTPATH:$QT_FONTPATH"
|
||||||
|
|
||||||
# Detect missing dependencies...
|
# Detect missing dependencies...
|
||||||
DEPS_LIST=`ldd "${LAUNCHER_DIR}"/plugins/*/*.so 2>/dev/null | grep "not found" | sort -u | awk -vORS=", " '{ print $1 }'`
|
DEPS_LIST=`ldd "${LAUNCHER_DIR}"/plugins/*/*.so 2>/dev/null | grep "not found" | sort -u | awk -vORS=", " '{ print $1 }'`
|
||||||
|
@ -52,26 +52,25 @@ JavaUtils::JavaUtils()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
|
QString stripVariableEntries(QString name, QString target, QString remove)
|
||||||
static QString processLD_LIBRARY_PATH(const QString & LD_LIBRARY_PATH)
|
|
||||||
{
|
{
|
||||||
QDir mmcBin(QCoreApplication::applicationDirPath());
|
char delimiter = ':';
|
||||||
auto items = LD_LIBRARY_PATH.split(':');
|
#ifdef Q_OS_WIN32
|
||||||
QStringList final;
|
delimiter = ';';
|
||||||
for(auto & item: items)
|
|
||||||
{
|
|
||||||
QDir test(item);
|
|
||||||
if(test == mmcBin)
|
|
||||||
{
|
|
||||||
qDebug() << "Env:LD_LIBRARY_PATH ignoring path" << item;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
final.append(item);
|
|
||||||
}
|
|
||||||
return final.join(':');
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
auto targetItems = target.split(delimiter);
|
||||||
|
auto toRemove = remove.split(delimiter);
|
||||||
|
|
||||||
|
for (QString item : toRemove) {
|
||||||
|
bool removed = targetItems.removeOne(item);
|
||||||
|
if (!removed)
|
||||||
|
qWarning() << "Entry" << item
|
||||||
|
<< "could not be stripped from variable" << name;
|
||||||
|
}
|
||||||
|
return targetItems.join(delimiter);
|
||||||
|
}
|
||||||
|
|
||||||
QProcessEnvironment CleanEnviroment()
|
QProcessEnvironment CleanEnviroment()
|
||||||
{
|
{
|
||||||
// prepare the process environment
|
// prepare the process environment
|
||||||
@ -89,6 +88,16 @@ QProcessEnvironment CleanEnviroment()
|
|||||||
"JAVA_OPTIONS",
|
"JAVA_OPTIONS",
|
||||||
"JAVA_TOOL_OPTIONS"
|
"JAVA_TOOL_OPTIONS"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QStringList stripped =
|
||||||
|
{
|
||||||
|
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD)
|
||||||
|
"LD_LIBRARY_PATH",
|
||||||
|
"LD_PRELOAD",
|
||||||
|
#endif
|
||||||
|
"QT_PLUGIN_PATH",
|
||||||
|
"QT_FONTPATH"
|
||||||
|
};
|
||||||
for(auto key: rawenv.keys())
|
for(auto key: rawenv.keys())
|
||||||
{
|
{
|
||||||
auto value = rawenv.value(key);
|
auto value = rawenv.value(key);
|
||||||
@ -98,19 +107,22 @@ QProcessEnvironment CleanEnviroment()
|
|||||||
qDebug() << "Env: ignoring" << key << value;
|
qDebug() << "Env: ignoring" << key << value;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// filter PolyMC-related things
|
|
||||||
if(key.startsWith("QT_"))
|
// These are used to strip the original variables
|
||||||
|
// If there is "LD_LIBRARY_PATH" and "LAUNCHER_LD_LIBRARY_PATH", we want to
|
||||||
|
// remove all values in "LAUNCHER_LD_LIBRARY_PATH" from "LD_LIBRARY_PATH"
|
||||||
|
if(key.startsWith("LAUNCHER_"))
|
||||||
{
|
{
|
||||||
qDebug() << "Env: ignoring" << key << value;
|
qDebug() << "Env: ignoring" << key << value;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
|
if(stripped.contains(key))
|
||||||
// Do not pass LD_* variables to java. They were intended for PolyMC
|
|
||||||
if(key.startsWith("LD_"))
|
|
||||||
{
|
{
|
||||||
qDebug() << "Env: ignoring" << key << value;
|
QString newValue = stripVariableEntries(key, value, rawenv.value("LAUNCHER_" + key));
|
||||||
continue;
|
|
||||||
|
qDebug() << "Env: stripped" << key << value << "to" << newValue;
|
||||||
}
|
}
|
||||||
|
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD)
|
||||||
// Strip IBus
|
// Strip IBus
|
||||||
// IBus is a Linux IME framework. For some reason, it breaks MC?
|
// IBus is a Linux IME framework. For some reason, it breaks MC?
|
||||||
if (key == "XMODIFIERS" && value.contains(IBUS))
|
if (key == "XMODIFIERS" && value.contains(IBUS))
|
||||||
@ -119,22 +131,12 @@ QProcessEnvironment CleanEnviroment()
|
|||||||
value.replace(IBUS, "");
|
value.replace(IBUS, "");
|
||||||
qDebug() << "Env: stripped" << IBUS << "from" << save << ":" << value;
|
qDebug() << "Env: stripped" << IBUS << "from" << save << ":" << value;
|
||||||
}
|
}
|
||||||
if(key == "GAME_PRELOAD")
|
|
||||||
{
|
|
||||||
env.insert("LD_PRELOAD", value);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(key == "GAME_LIBRARY_PATH")
|
|
||||||
{
|
|
||||||
env.insert("LD_LIBRARY_PATH", processLD_LIBRARY_PATH(value));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
// qDebug() << "Env: " << key << value;
|
// qDebug() << "Env: " << key << value;
|
||||||
env.insert(key, value);
|
env.insert(key, value);
|
||||||
}
|
}
|
||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
// HACK: Workaround for QTBUG42500
|
// HACK: Workaround for QTBUG-42500
|
||||||
if(!env.contains("LD_LIBRARY_PATH"))
|
if(!env.contains("LD_LIBRARY_PATH"))
|
||||||
{
|
{
|
||||||
env.insert("LD_LIBRARY_PATH", "");
|
env.insert("LD_LIBRARY_PATH", "");
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
QString stripVariableEntries(QString name, QString target, QString remove);
|
||||||
QProcessEnvironment CleanEnviroment();
|
QProcessEnvironment CleanEnviroment();
|
||||||
|
|
||||||
class JavaUtils : public QObject
|
class JavaUtils : public QObject
|
||||||
|
@ -71,8 +71,8 @@ stdenv.mkDerivation rec {
|
|||||||
postInstall = ''
|
postInstall = ''
|
||||||
# xorg.xrandr needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128
|
# xorg.xrandr needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128
|
||||||
wrapQtApp $out/bin/polymc \
|
wrapQtApp $out/bin/polymc \
|
||||||
--run '[ -f /etc/NIXOS ] && export GAME_LIBRARY_PATH="${stdenv.cc.cc.lib}/lib"' \
|
--run '[ -f /etc/NIXOS ] && export LD_LIBRARY_PATH="${stdenv.cc.cc.lib}/lib:$LD_LIBRARY_PATH"' \
|
||||||
--prefix GAME_LIBRARY_PATH : ${gameLibraryPath} \
|
--prefix LD_LIBRARY_PATH : ${gameLibraryPath} \
|
||||||
--prefix POLYMC_JAVA_PATHS : ${javaPaths} \
|
--prefix POLYMC_JAVA_PATHS : ${javaPaths} \
|
||||||
--prefix PATH : ${lib.makeBinPath [ xorg.xrandr ]}
|
--prefix PATH : ${lib.makeBinPath [ xorg.xrandr ]}
|
||||||
'';
|
'';
|
||||||
@ -88,7 +88,7 @@ stdenv.mkDerivation rec {
|
|||||||
their associated options with a simple interface.
|
their associated options with a simple interface.
|
||||||
'';
|
'';
|
||||||
platforms = platforms.unix;
|
platforms = platforms.unix;
|
||||||
license = licenses.gpl3Plus;
|
license = licenses.gpl3Only;
|
||||||
maintainers = with maintainers; [ starcraft66 kloenk ];
|
maintainers = with maintainers; [ starcraft66 kloenk ];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user