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>
This commit is contained in:
parent
277c23956c
commit
fc16855eaa
@ -169,17 +169,22 @@ static QLibraryInfoPrivate::LocationInfo defaultLocationInfo(int loc)
|
||||
return result;
|
||||
}
|
||||
|
||||
static QString libraryInfoPath(QLibraryInfo::LibraryPath location)
|
||||
{
|
||||
return QLibraryInfoPrivate::path(location, QLibraryInfoPrivate::UsedFromQtBinDir);
|
||||
}
|
||||
|
||||
static QString storedPath(int loc)
|
||||
{
|
||||
QString result;
|
||||
if (loc < QMakeLibraryInfo::FirstHostPath) {
|
||||
result = QLibraryInfo::path(static_cast<QLibraryInfo::LibraryPath>(loc));
|
||||
result = libraryInfoPath(static_cast<QLibraryInfo::LibraryPath>(loc));
|
||||
} else if (loc <= QMakeLibraryInfo::LastHostPath) {
|
||||
if (loc == QMakeLibraryInfo::HostDataPath) {
|
||||
// Handle QT_HOST_DATADIR specially. It is not necessarily equal to QT_INSTALL_DATA.
|
||||
result = QT_HOST_DATADIR;
|
||||
} else {
|
||||
result = QLibraryInfo::path(hostToTargetPathEnum(loc));
|
||||
result = libraryInfoPath(hostToTargetPathEnum(loc));
|
||||
}
|
||||
} else if (loc == QMakeLibraryInfo::SysrootPath) {
|
||||
// empty result
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -79,6 +79,13 @@ public:
|
||||
};
|
||||
|
||||
static LocationInfo locationInfo(QLibraryInfo::LibraryPath loc);
|
||||
|
||||
enum UsageMode {
|
||||
RegularUsage,
|
||||
UsedFromQtBinDir
|
||||
};
|
||||
|
||||
static QString path(QLibraryInfo::LibraryPath p, UsageMode usageMode = RegularUsage);
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
Loading…
x
Reference in New Issue
Block a user