main: try to load plugin from build bin folder

first when debug

This will make debug plugin more easy.

Signed-off-by: Hongfei Shang <shanghongfei@kylinos.cn>
This commit is contained in:
Hongfei Shang 2022-06-04 08:37:27 +08:00
parent 8eac0b1356
commit 205b84c4cd
2 changed files with 42 additions and 0 deletions

View File

@ -500,6 +500,27 @@ int main(int argc, char * argv[])
// reset QT_QPA_PLATFORM so we don't propagate it to our children (e.g. apps launched from the overview effect)
qunsetenv("QT_QPA_PLATFORM");
#if !defined(QT_NO_DEBUG)
QStringList newLibPaths(a.applicationDirPath());
const QStringList oldLibPaths = QCoreApplication::libraryPaths();
if (newLibPaths.contains("/usr/local/bin")) {
// when do “make install”, we need add plugins directory before normal qt plugins directory.
// we can get arch lib directory name from qt plugins directory and do a replace
// from "/usr/lib/x86_64-linux-gnu/qt5/plugins" to "/usr/local/lib/x86_64-linux-gnu/plugins"
// then kwin will load the right plugins.
QRegularExpression re("^/usr/lib/(.*)/qt.*$");
QStringList plugins = oldLibPaths.filter(QRegularExpression("^/usr/lib/"))
.replaceInStrings(re, "/usr/local/lib/\\1/plugins");
newLibPaths.append(plugins);
}
newLibPaths.append(oldLibPaths);
QCoreApplication::setLibraryPaths(newLibPaths);
qDebug() << "debug mode:";
qDebug() << " set application dir path to be the first of libraryPaths,";
qDebug() << " so we can be happy to debug kwin plugins.";
qDebug() << " libraryPaths:" << newLibPaths;
#endif
KWin::Application::createAboutData();
KQuickAddons::QtQuickSettings::init();

View File

@ -537,6 +537,27 @@ int main(int argc, char * argv[])
KWin::ApplicationX11 a(argc, argv);
a.setupTranslator();
#if !defined(QT_NO_DEBUG)
QStringList newLibPaths(a.applicationDirPath());
const QStringList oldLibPaths = QCoreApplication::libraryPaths();
if (newLibPaths.contains("/usr/local/bin")) {
// when do “make install”, we need add plugins directory before normal qt plugins directory.
// we can get arch lib directory name from qt plugins directory and do a replace
// from "/usr/lib/x86_64-linux-gnu/qt5/plugins" to "/usr/local/lib/x86_64-linux-gnu/plugins"
// then kwin will load the right plugins.
QRegularExpression re("^/usr/lib/(.*)/qt.*$");
QStringList plugins = oldLibPaths.filter(QRegularExpression("^/usr/lib/"))
.replaceInStrings(re, "/usr/local/lib/\\1/plugins");
newLibPaths.append(plugins);
}
newLibPaths.append(oldLibPaths);
QCoreApplication::setLibraryPaths(newLibPaths);
qDebug() << "debug mode:";
qDebug() << " set application dir path to be the first of libraryPaths,";
qDebug() << " so we can be happy to debug kwin plugins.";
qDebug() << " libraryPaths:" << newLibPaths;
#endif
KWin::Application::createAboutData();
KQuickAddons::QtQuickSettings::init();