Browse Source

Set "qt_prfxpath=." or "qt_prfxpath=../../", closes #12

master
probonopd 8 years ago
parent
commit
792c5cc9d5
  1. 73
      shared/shared.cpp
  2. 1
      shared/shared.h

73
shared/shared.cpp

@ -534,12 +534,9 @@ void recursiveCopyAndDeploy(const QString &appDirPath, const QSet<QString> &rpat
foreach (QString file, files) {
const QString fileSourcePath = sourcePath + QLatin1Char('/') + file;
if (file.endsWith("_debug.dylib")) {
continue; // Skip debug versions
} else {
QString fileDestinationPath = destinationPath + QLatin1Char('/') + file;
copyFilePrintStatus(fileSourcePath, fileDestinationPath);
}
}
QStringList subdirs = QDir(sourcePath).entryList(QStringList() << QStringLiteral("*"), QDir::Dirs | QDir::NoDotAndDotDot);
@ -603,6 +600,16 @@ void changeIdentification(const QString &id, const QString &binaryPath)
LogDebug() << " change rpath in" << binaryPath;
LogDebug() << " to" << id;
runPatchelf(QStringList() << "--set-rpath" << id << binaryPath);
// qt_prfxpath:
if (binaryPath.contains("libQt5Core")) {
LogDebug() << "libQt5Core detected, patching its qt_prfxpath";
QString* errorMessage;
if (!patchQtCore(binaryPath, errorMessage))
LogError() << errorMessage;
return;
}
}
void runStrip(const QString &binaryPath)
@ -1231,6 +1238,64 @@ void changeQtLibraries(const QString appPath, const QString &qtPath)
}
}
/* https://codereview.qt-project.org/gitweb?p=qt/qttools.git;a=blob_plain;f=src/windeployqt/utils.cpp;h=e89496ea1f371ed86f6937284c1c801daf576572;hb=7be81b804da102b374c2089aac38353a0383c254
* Search for "qt_prfxpath=<xxx>" in a path, and replace it with "qt_prfxpath=." or "qt_prfxpath=../../" */
bool patchQtCore(const QString &path, QString *errorMessage)
{
LogNormal() << "Patching " << QFileInfo(path).fileName() << "...\n";
QFile file(path);
if (!file.open(QIODevice::ReadWrite)) {
*errorMessage = QString::fromLatin1("Unable to patch %1: %2").arg(
QDir::toNativeSeparators(path), file.errorString());
return false;
}
QByteArray content = file.readAll();
if (content.isEmpty()) {
*errorMessage = QString::fromLatin1("Unable to patch %1: Could not read file content").arg(
QDir::toNativeSeparators(path));
return false;
}
QByteArray prfxpath("qt_prfxpath=");
int startPos = content.indexOf(prfxpath);
if (startPos == -1) {
*errorMessage = QString::fromLatin1(
"Unable to patch %1: Could not locate pattern \"qt_prfxpath=\"").arg(
QDir::toNativeSeparators(path));
return false;
}
startPos += prfxpath.length();
int endPos = content.indexOf(char(0), startPos);
if (endPos == -1) {
*errorMessage = QString::fromLatin1("Unable to patch %1: Internal error").arg(
QDir::toNativeSeparators(path));
return false;
}
QByteArray replacement = QByteArray(endPos - startPos, char(0));
if(fhsLikeMode == true){
replacement[0] = '.';
replacement[1] = '.';
replacement[2] = '/';
replacement[3] = '.';
replacement[4] = '.';
replacement[5] = '/';
} else {
replacement[0] = '.';
}
content.replace(startPos, endPos - startPos, replacement);
if (!file.seek(0)
|| (file.write(content) != content.size())) {
*errorMessage = QString::fromLatin1("Unable to patch %1: Could not write to file").arg(
QDir::toNativeSeparators(path));
return false;
}
return true;
}
bool checkAppImagePrerequisites(const QString &appDirPath)
{
if(fhsLikeMode == true){

1
shared/shared.h

@ -124,6 +124,7 @@ void runStrip(const QString &binaryPath);
void stripAppBinary(const QString &bundlePath);
QString findAppBinary(const QString &appDirPath);
QStringList findAppLibraries(const QString &appDirPath);
bool patchQtCore(const QString &path, QString *errorMessage);
int createAppImage(const QString &appBundlePath);
bool checkAppImagePrerequisites(const QString &appBundlePath);

Loading…
Cancel
Save