From c5ba2e7599359dd542d64b54d96b5668d38bc377 Mon Sep 17 00:00:00 2001 From: probonopd Date: Fri, 10 Nov 2017 16:14:42 +0100 Subject: [PATCH] Deploy copyright files along with libraries copied from the host system This is only implemented for Debian-like systems. Generalizations welcome. --- tools/linuxdeployqt/shared.cpp | 75 ++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/tools/linuxdeployqt/shared.cpp b/tools/linuxdeployqt/shared.cpp index bec3a09..239e5eb 100644 --- a/tools/linuxdeployqt/shared.cpp +++ b/tools/linuxdeployqt/shared.cpp @@ -244,6 +244,11 @@ bool copyFilePrintStatus(const QString &from, const QString &to) } } + QDir dir(to + "/../"); + if (!dir.exists()) { + dir.mkpath("."); + } + if (QFile::copy(from, to)) { QFile dest(to); dest.setPermissions(dest.permissions() | QFile::WriteOwner | QFile::WriteUser); @@ -270,6 +275,68 @@ bool copyFilePrintStatus(const QString &from, const QString &to) } } +bool copyCopyrightFile(QString libPath){ + + /* When deploying files (e.g., libraries) from the + * system, then try to also deploy their copyright file. + * This is currently only implemented for dpkg-based, + * Debian-like systems. Pull requests welcome for other + * systems. */ + + QString dpkgPath; + dpkgPath = QStandardPaths::findExecutable("dpkg"); + if(dpkgPath == ""){ + LogNormal() << "dpkg not found, hence not deploying copyright files"; + return false; + } + + QString copyrightFilePath; + + /* Find out which package the file being deployed belongs to */ + + QString program = "dpkg"; + QStringList arguments; + arguments << "-S" << libPath; + QProcess *myProcess = new QProcess(); + myProcess->start(program, arguments); + myProcess->waitForFinished(); + QString strOut = myProcess->readAllStandardOutput().split(':')[0]; + if(strOut == "") return false; + + /* Find out the copyright file in that package */ + + arguments << "-S" << strOut; + myProcess->start(program, arguments); + myProcess->waitForFinished(); + strOut = myProcess->readAllStandardOutput(); + + QStringList outputLines = strOut.split("\n", QString::SkipEmptyParts); + + foreach (QString outputLine, outputLines) { + if((outputLine.contains("usr/share/doc")) && (outputLine.contains("/copyright"))){ + copyrightFilePath = outputLine.split(' ')[1]; + } + } + + if(copyrightFilePath == "") return false; + + LogDebug() << "copyrightFilePath:" << copyrightFilePath; + + /* Where should we copy this file to? We are assuming the Debian-like path contains + * the name of the package like so: copyrightFilePath: "/usr/share/doc/libpcre3/copyright" + * this assumption is most likely only true for Debian-like systems */ + QString packageName = copyrightFilePath.split("/")[copyrightFilePath.split("/").length()-2]; + QString copyrightFileTargetPath; + if(fhsLikeMode){ + copyrightFileTargetPath = QDir::cleanPath(appBinaryPath + "/../../share/doc/" + packageName + "/copyright"); + } else { + copyrightFileTargetPath = QDir::cleanPath(appBinaryPath + "/../doc/" + packageName + "/copyright"); + } + + /* Do the actual copying */ + return(copyFilePrintStatus(copyrightFilePath, copyrightFileTargetPath)); +} + LddInfo findDependencyInfo(const QString &binaryPath) { LddInfo info; @@ -600,6 +667,8 @@ bool recursiveCopy(const QString &sourcePath, const QString &destinationPath) const QString fileSourcePath = sourcePath + "/" + file; const QString fileDestinationPath = destinationPath + "/" + file; copyFilePrintStatus(fileSourcePath, fileDestinationPath); + LogDebug() << "copyCopyrightFile:" << fileSourcePath; + copyCopyrightFile(fileSourcePath); } QStringList subdirs = QDir(sourcePath).entryList(QStringList() << "*", QDir::Dirs | QDir::NoDotAndDotDot); @@ -621,6 +690,8 @@ void recursiveCopyAndDeploy(const QString &appDirPath, const QSet &rpat QString fileDestinationPath = destinationPath + QLatin1Char('/') + file; copyFilePrintStatus(fileSourcePath, fileDestinationPath); + LogDebug() << "copyCopyrightFile:" << fileSourcePath; + copyCopyrightFile(fileSourcePath); if(fileDestinationPath.endsWith(".so")){ @@ -676,6 +747,8 @@ QString copyDylib(const LibraryInfo &library, const QString path) // Copy dylib binary copyFilePrintStatus(library.sourceFilePath, dylibDestinationBinaryPath); + LogDebug() << "copyCopyrightFile:" << library.sourceFilePath; + copyCopyrightFile(library.sourceFilePath); return dylibDestinationBinaryPath; } @@ -1263,6 +1336,8 @@ void deployPlugins(const AppDirInfo &appDirInfo, const QString &pluginSourcePath changeIdentification("$ORIGIN/" + relativePath, QFileInfo(destinationPath).canonicalFilePath()); } + LogDebug() << "copyCopyrightFile:" << sourcePath; + copyCopyrightFile(sourcePath); } }