summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qlibraryinfo.cpp
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2022-04-28 14:37:15 +0200
committerJoerg Bornemann <joerg.bornemann@qt.io>2022-05-09 08:32:04 +0200
commitfc16855eaa393bc00c41c99bd967bc736939850d (patch)
tree25a3c74830fba7a8bcc5cde6f333ed6d732c84bf /src/corelib/global/qlibraryinfo.cpp
parent277c23956cd4a298a57dad9e777259680a520730 (diff)
Fix qmake/qtpaths -query for static relocatable builds
The install prefix was determined incorrectly for static relocatable builds. The reason was that for those builds, QLibraryInfo::path() returns the application directory, which is <prefix>/bin for qmake and qtpaths. Fix this by removing the bin directory part from the installation prefix that QLibraryInfo returns if qmake/qtpaths are used. Fixes: QTBUG-102877 Change-Id: I2e9ff96ded0ee2a7802b265741a3cfbe2bf0a4ba Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/corelib/global/qlibraryinfo.cpp')
-rw-r--r--src/corelib/global/qlibraryinfo.cpp40
1 files changed, 31 insertions, 9 deletions
diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp
index 1cec39ec3b..b3ea6f8756 100644
--- a/src/corelib/global/qlibraryinfo.cpp
+++ b/src/corelib/global/qlibraryinfo.cpp
@@ -369,7 +369,7 @@ static HMODULE getWindowsModuleHandle()
}
#endif // Q_OS_WIN
-static QString getRelocatablePrefix()
+static QString getRelocatablePrefix(QLibraryInfoPrivate::UsageMode usageMode)
{
QString prefixPath;
@@ -377,7 +377,14 @@ static QString getRelocatablePrefix()
// For regular builds, the prefix will be relative to the location of the QtCore shared library.
#if defined(QT_STATIC)
prefixPath = prefixFromAppDirHelper();
+ if (usageMode == QLibraryInfoPrivate::UsedFromQtBinDir) {
+ // For Qt tools in a static build, we must chop off the bin directory.
+ constexpr QByteArrayView binDir = qt_configure_strs.viewAt(QLibraryInfo::BinariesPath - 1);
+ constexpr size_t binDirLength = binDir.size() + 1;
+ prefixPath.chop(binDirLength);
+ }
#elif defined(Q_OS_DARWIN) && QT_CONFIG(framework)
+ Q_UNUSED(usageMode);
#ifndef QT_LIBINFIX
#define QT_LIBINFIX ""
#endif
@@ -416,11 +423,13 @@ static QString getRelocatablePrefix()
prefixPath = QDir::cleanPath(prefixDir);
#elif QT_CONFIG(dlopen)
+ Q_UNUSED(usageMode);
Dl_info info;
int result = dladdr(reinterpret_cast<void *>(&QLibraryInfo::isDebugBuild), &info);
if (result > 0 && info.dli_fname)
prefixPath = prefixFromQtCoreLibraryHelper(QString::fromLocal8Bit(info.dli_fname));
#elif defined(Q_OS_WIN)
+ Q_UNUSED(usageMode);
HMODULE hModule = getWindowsModuleHandle();
const int kBufferSize = 4096;
wchar_t buffer[kBufferSize];
@@ -484,11 +493,12 @@ static QString getRelocatablePrefix()
}
#endif
-static QString getPrefix()
+static QString getPrefix(QLibraryInfoPrivate::UsageMode usageMode)
{
#if QT_CONFIG(relocatable)
- return getRelocatablePrefix();
+ return getRelocatablePrefix(usageMode);
#else
+ Q_UNUSED(usageMode);
return QString::fromLocal8Bit(QT_CONFIGURE_PREFIX_PATH);
#endif
}
@@ -555,7 +565,19 @@ QLibraryInfoPrivate::LocationInfo QLibraryInfoPrivate::locationInfo(QLibraryInfo
*/
QString QLibraryInfo::path(LibraryPath p)
{
- const LibraryPath loc = p;
+ return QLibraryInfoPrivate::path(p);
+}
+
+
+/*
+ Returns the path specified by \a p.
+
+ The usage mode can be set to UsedFromQtBinDir to enable special handling for executables that
+ live in <install-prefix>/bin.
+ */
+QString QLibraryInfoPrivate::path(QLibraryInfo::LibraryPath p, UsageMode usageMode)
+{
+ const QLibraryInfo::LibraryPath loc = p;
QString ret;
bool fromConf = false;
#if QT_CONFIG(settings)
@@ -605,12 +627,12 @@ QString QLibraryInfo::path(LibraryPath p)
#endif // settings
if (!fromConf) {
- if (loc == PrefixPath) {
- ret = getPrefix();
+ if (loc == QLibraryInfo::PrefixPath) {
+ ret = getPrefix(usageMode);
} else if (int(loc) <= qt_configure_strs.count()) {
ret = QString::fromLocal8Bit(qt_configure_strs.viewAt(loc - 1));
#ifndef Q_OS_WIN // On Windows we use the registry
- } else if (loc == SettingsPath) {
+ } else if (loc == QLibraryInfo::SettingsPath) {
// Use of volatile is a hack to discourage compilers from calling
// strlen(), in the inlined fromLocal8Bit(const char *)'s body, at
// compile-time, as Qt installers binary-patch the path, replacing
@@ -623,11 +645,11 @@ QString QLibraryInfo::path(LibraryPath p)
if (!ret.isEmpty() && QDir::isRelativePath(ret)) {
QString baseDir;
- if (loc == PrefixPath) {
+ if (loc == QLibraryInfo::PrefixPath) {
baseDir = prefixFromAppDirHelper();
} else {
// we make any other path absolute to the prefix directory
- baseDir = path(PrefixPath);
+ baseDir = path(QLibraryInfo::PrefixPath, usageMode);
}
ret = QDir::cleanPath(baseDir + u'/' + ret);
}