diff options
author | kh1 <qt-info@nokia.com> | 2011-06-22 19:50:10 +0200 |
---|---|---|
committer | kh1 <qt-info@nokia.com> | 2011-06-22 19:50:10 +0200 |
commit | 530292ec64a2f223c5ec541e5b4b60d0a00662f1 (patch) | |
tree | 156acc48a7ebbbe2885efd9e55390cd453908878 | |
parent | 38e010d9333a9234c31c68ceff1d2b2071ba600d (diff) | |
parent | 82a05168be98cf1c39a17c702043767a322c15be (diff) |
Merge branch 'master' into refactor
Conflicts:
installerbuilder/libinstaller/macrelocateqt.cpp
installerbuilder/libinstaller/macreplaceinstallnamesoperation.cpp
7 files changed, 138 insertions, 230 deletions
diff --git a/installerbuilder/libinstaller/environmentvariablesoperation.cpp b/installerbuilder/libinstaller/environmentvariablesoperation.cpp index 4381cd387..96446f748 100644 --- a/installerbuilder/libinstaller/environmentvariablesoperation.cpp +++ b/installerbuilder/libinstaller/environmentvariablesoperation.cpp @@ -171,6 +171,7 @@ bool EnvironmentVariableOperation::performOperation() } #endif Q_ASSERT( !isPersistent ); + Q_UNUSED(isPersistent) setValue( QLatin1String( "oldvalue" ), Environment::instance().value( name ) ); Environment::instance().setTemporaryValue( name, value ); diff --git a/installerbuilder/libinstaller/macrelocateqt.cpp b/installerbuilder/libinstaller/macrelocateqt.cpp index d04d86c78..717619f56 100644 --- a/installerbuilder/libinstaller/macrelocateqt.cpp +++ b/installerbuilder/libinstaller/macrelocateqt.cpp @@ -31,13 +31,12 @@ ** **************************************************************************/ #include "macrelocateqt.h" + #include "common/utils.h" -#include "fsengineclient.h" -#include "qprocesswrapper.h" +#include "macreplaceinstallnamesoperation.h" + +#include <QtCore/QFile> -#include <QtCore/QDirIterator> -#include <QtCore/QDebug> -#include <QtCore/QBuffer> using namespace QInstaller; @@ -47,178 +46,48 @@ Relocator::Relocator() bool Relocator::apply(const QString &qtInstallDir, const QString &targetDir) { - verbose() << "Relocator::apply(" << qtInstallDir << ')' << std::endl; - - mErrorMessage.clear(); - mOriginalInstallDir.clear(); - - { - QFile buildRootFile(qtInstallDir + QLatin1String("/.orig_build_root")); - if (buildRootFile.exists() && buildRootFile.open(QFile::ReadOnly)) { - mOriginalInstallDir = QString::fromLocal8Bit(buildRootFile.readAll()).trimmed(); - if (!mOriginalInstallDir.endsWith(QLatin1Char('/'))) - mOriginalInstallDir += QLatin1Char('/'); - } - } - - mInstallDir = targetDir; - if (!mInstallDir.endsWith(QLatin1Char('/'))) - mInstallDir.append(QLatin1Char('/')); - if (!QFile::exists(qtInstallDir + QLatin1String("/bin/qmake"))) { - mErrorMessage = QLatin1String("This is not a Qt installation directory."); +// Relocator::apply(/Users/rakeller/QtSDKtest2/Simulator/Qt/gcc) +// Relocator uses indicator: /QtSDKtest2operation 'QtPatch' with arguments: 'mac; /Users/rakeller/QtSDKtest2/Simulator/Qt/gcc' failed: Error while relocating Qt: "ReplaceInsta + if (qtInstallDir.isEmpty()) { + m_errorMessage = QLatin1String("qtInstallDir can't be empty"); return false; } - - { - QDirIterator dirIterator(qtInstallDir + QLatin1String("/lib"), QDirIterator::Subdirectories | QDirIterator::FollowSymlinks); - while (dirIterator.hasNext()) { - QString dirName = dirIterator.next(); - if (dirName.endsWith(QLatin1String(".framework"))) - relocateFramework(dirName); - } - } - - QStringList dyLibDirs; - dyLibDirs << QLatin1String("/plugins") << QLatin1String("/lib") << QLatin1String("/imports"); - foreach (QString dylibItem, dyLibDirs){ - QDirIterator dirIterator(qtInstallDir + dylibItem, QDirIterator::Subdirectories | QDirIterator::FollowSymlinks); - while (dirIterator.hasNext()) { - QString fileName = dirIterator.next(); - if (fileName.endsWith(QLatin1String(".dylib"))) { - relocateBinary(fileName); - } - } - } - - // We should not iterate over each file, but to be sure check each of those in relocate - { - QDirIterator dirIterator(qtInstallDir + QLatin1String("/bin"), QDir::Files | QDir::NoDotAndDotDot, QDirIterator::Subdirectories | QDirIterator::FollowSymlinks); - while (dirIterator.hasNext()) { - QString fileName = dirIterator.next(); - if (fileName.contains(QLatin1String("app/Contents")) && !fileName.contains(QLatin1String("/MacOS"))) - continue; - relocateBinary(fileName); - } + if (targetDir.isEmpty()) { + m_errorMessage = QLatin1String("targetDir can't be empty"); + return false; } + verbose() << "Relocator::apply(" << qtInstallDir << ")" << std::endl; - return mErrorMessage.isNull(); -} + m_errorMessage.clear(); + m_installDir.clear(); -bool Relocator::containsOriginalBuildDir(const QString &dirName) -{ - int idx = dirName.indexOf(QLatin1String("_BUILD_")); - if (idx < 0) + m_installDir = targetDir; + if (!m_installDir.endsWith(QLatin1Char('/'))) + m_installDir.append(QLatin1Char('/')); + if (!QFile::exists(qtInstallDir + QLatin1String("/bin/qmake"))) { + m_errorMessage = QLatin1String("This is not a Qt installation directory."); return false; - return dirName.indexOf(QLatin1String("_PADDED_"), idx) >= 0; -} - -void Relocator::extractExecutableInfo(const QString& fileName, QStringList& frameworks) -{ - verbose() << "Relocator calling otool -l for " << fileName << std::endl; - QProcessWrapper otool; - otool.start(QLatin1String("otool"), QStringList() << QLatin1String("-l") << fileName); - if (!otool.waitForStarted()) { - mErrorMessage = QLatin1String("Can't start otool. Is Xcode installed?"); - return; - } - otool.waitForFinished(); - enum State { - State_Start, - State_LC_ID_DYLIB, - State_LC_LOAD_DYLIB - }; - State state = State_Start; - QByteArray outputData = otool.readAllStandardOutput(); - QBuffer output(&outputData); - output.open(QBuffer::ReadOnly); - while (!output.atEnd()) { - QString line = QString::fromLocal8Bit(output.readLine()); - line = line.trimmed(); -// qDebug() << line; - if (line.startsWith(QLatin1String("cmd "))) { - line.remove(0, 4); - if (line == QLatin1String("LC_LOAD_DYLIB")) - state = State_LC_LOAD_DYLIB; - else if (line == QLatin1String("LC_ID_DYLIB")) - state = State_LC_ID_DYLIB; - else - state = State_Start; - } else if (state == State_LC_LOAD_DYLIB && line.startsWith(QLatin1String("name "))) { - line.remove(0, 5); - int idx = line.indexOf(QLatin1String("(offset")); - if (idx > 0) - line.truncate(idx); - line = line.trimmed(); - if (containsOriginalBuildDir(line)) - frameworks.append(line); - } else if (state == State_LC_ID_DYLIB && mOriginalInstallDir.isNull() && line.startsWith(QLatin1String("name "))) { - line.remove(0, 5); - if (containsOriginalBuildDir(line)) { - mOriginalInstallDir = line; - const QString lastBuildDirPart = QLatin1String("/ndk/"); - int idx = mOriginalInstallDir.indexOf(lastBuildDirPart); - if (idx < 0) - continue; - mOriginalInstallDir.truncate(idx + lastBuildDirPart.length()); - } - } } -} -void Relocator::relocateBinary(const QString& fileName) -{ - QStringList frameworks; - extractExecutableInfo(fileName, frameworks); + QString indicator = qtInstallDir; + indicator = indicator.replace(targetDir, QString()); - QStringList args; - args << QLatin1String("-id") << fileName << fileName; - if (!execCommand(QLatin1String("install_name_tool"), args)) - return; + verbose() << "Relocator uses indicator: " << indicator << std::endl; + QString replacement = targetDir; - foreach (const QString& fw, frameworks) { - if (!fw.startsWith(mOriginalInstallDir)) - continue; - QString newPath = mInstallDir; - newPath += fw.mid(mOriginalInstallDir.length()); + MacReplaceInstallNamesOperation operation; + QStringList arguments; + arguments << indicator + << replacement + << qtInstallDir + QLatin1String("/plugins") + << qtInstallDir + QLatin1String("/lib") + << qtInstallDir + QLatin1String("/imports") + << qtInstallDir + QLatin1String("/bin"); - args.clear(); - args << QLatin1String("-change") << fw << newPath << fileName; - if (!execCommand(QLatin1String("install_name_tool"), args)) - return; - } -} + operation.setArguments(arguments); + operation.performOperation(); -void Relocator::relocateFramework(const QString& directoryName) -{ - QFileInfo fi(directoryName); - QString frameworkName = fi.baseName(); - fi.setFile(directoryName + QLatin1String("/Versions/Current/") + frameworkName); - if (fi.exists()) { - QString fileName = fi.isSymLink() ? fi.symLinkTarget() : fi.absoluteFilePath(); - relocateBinary(fileName); - } - fi.setFile(directoryName + QLatin1String("/Versions/Current/") + frameworkName + QLatin1String("_debug")); - if (fi.exists()) { - QString fileName = fi.isSymLink() ? fi.symLinkTarget() : fi.absoluteFilePath(); - relocateBinary(fileName); - } -} - -bool Relocator::execCommand(const QString& cmd, const QStringList& args) -{ - verbose() << "Relocator::execCommand " << cmd << " " << args << std::endl; - QProcessWrapper process; - process.start(cmd, args); - if (!process.waitForStarted()) { - mErrorMessage = QLatin1String("Can't start process ") + cmd + QLatin1String("."); - return false; - } - process.waitForFinished(); - if (process.exitCode() != 0) { - mErrorMessage = QLatin1String("Command %1 failed.\nArguments: %2\nOutput: %3\n"); - mErrorMessage = mErrorMessage.arg(cmd, args.join(QLatin1String(" ")), QString::fromLocal8Bit(process.readAll())); - return false; - } - return true; + m_errorMessage = operation.errorString(); + return m_errorMessage.isNull(); } diff --git a/installerbuilder/libinstaller/macrelocateqt.h b/installerbuilder/libinstaller/macrelocateqt.h index 977385463..0f334dd3c 100644 --- a/installerbuilder/libinstaller/macrelocateqt.h +++ b/installerbuilder/libinstaller/macrelocateqt.h @@ -36,19 +36,11 @@ public: Relocator(); bool apply(const QString &qtInstallDir, const QString &targetDir); - QString errorMessage() const { return mErrorMessage; } + QString errorMessage() const { return m_errorMessage; } private: - bool containsOriginalBuildDir(const QString &dirName); - void extractExecutableInfo(const QString& fileName, QStringList& frameworks); - void relocateFramework(const QString& directoryName); - void relocateBinary(const QString& fileName); - bool execCommand(const QString& cmd, const QStringList& args); - -private: - QString mErrorMessage; - QString mOriginalInstallDir; - QString mInstallDir; + QString m_errorMessage; + QString m_installDir; }; } // namespace QInstaller diff --git a/installerbuilder/libinstaller/macreplaceinstallnamesoperation.cpp b/installerbuilder/libinstaller/macreplaceinstallnamesoperation.cpp index 652540fa8..3f33e18a0 100644 --- a/installerbuilder/libinstaller/macreplaceinstallnamesoperation.cpp +++ b/installerbuilder/libinstaller/macreplaceinstallnamesoperation.cpp @@ -31,12 +31,13 @@ ** **************************************************************************/ #include "macreplaceinstallnamesoperation.h" -#include "fsengineclient.h" + +#include "common/utils.h" #include "qprocesswrapper.h" -#include <QtCore/QDirIterator> -#include <QtCore/QDebug> #include <QtCore/QBuffer> +#include <QtCore/QDirIterator> + using namespace QInstaller; @@ -52,21 +53,31 @@ void MacReplaceInstallNamesOperation::backup() bool MacReplaceInstallNamesOperation::performOperation() { // Arguments: - // 1. indicator to find the original build directory - // 2. new build directory + // 1. indicator to find the original build directory, + // means the path till this will be used to replace it with 2. + // 2. new/current target install directory(the replacement) // 3. directory containing frameworks - - if( arguments().count() != 3 ) { - setError( InvalidArguments ); - setErrorString( tr("Invalid arguments in %0: %1 arguments given, 3 expected.") - .arg(name()).arg( arguments().count() ) ); + // 4. other directory containing frameworks + // 5. other directory containing frameworks + // 6. ... + + verbose() << arguments().join(QLatin1String(";")) << std::endl; + if (arguments().count() < 3) { + setError(InvalidArguments); + setErrorString(tr("Invalid arguments in %0: %1 arguments given, 3 expected.").arg(name()) + .arg(arguments().count())); return false; } QString indicator = arguments().at(0); QString installationDir = arguments().at(1); - QString searchDir = arguments().at(2); - return apply(indicator, installationDir, searchDir); + QStringList searchDirList = arguments().mid(2); + foreach (const QString &searchDir, searchDirList) { + if (!apply(indicator, installationDir, searchDir)) + return false; + } + + return true; } bool MacReplaceInstallNamesOperation::undoOperation() @@ -84,30 +95,41 @@ KDUpdater::UpdateOperation* MacReplaceInstallNamesOperation::clone() const return new MacReplaceInstallNamesOperation; } -bool MacReplaceInstallNamesOperation::apply(const QString& indicator, const QString& installationDir, const QString& searchDir) +bool MacReplaceInstallNamesOperation::apply(const QString &indicator, const QString &installationDir, + const QString &searchDir) { - mOriginalBuildDir.clear(); mIndicator = indicator; mInstallationDir = installationDir; - { - QDirIterator dirIterator(searchDir, QDirIterator::Subdirectories | QDirIterator::FollowSymlinks); - while (dirIterator.hasNext()) { - QString dirName = dirIterator.next(); - if (dirName.endsWith(QLatin1String(".framework"))) - relocateFramework(dirName); + QDirIterator dirIterator(searchDir, QDirIterator::Subdirectories | QDirIterator::FollowSymlinks); + while (dirIterator.hasNext()) { + QString fileName = dirIterator.next(); + if (dirIterator.fileInfo().isDir()) + continue; + + if (fileName.endsWith(QLatin1String(".dylib"))) + relocateBinary(fileName); + else if (fileName.endsWith(QLatin1String(".framework"))) + relocateFramework(fileName); + else if (dirIterator.fileInfo().isExecutable() && !fileName.endsWith(QLatin1String(".h")) + && !fileName.endsWith(QLatin1String(".cpp")) && !fileName.endsWith(QLatin1String(".pro")) + && !fileName.endsWith(QLatin1String(".pri"))) { + //the endsWith check are here because there were wrongly commited files in the repositories + relocateBinary(fileName); } } return error() == NoError; } -void MacReplaceInstallNamesOperation::extractExecutableInfo(const QString& fileName, QString& frameworkId, QStringList& frameworks) +void MacReplaceInstallNamesOperation::extractExecutableInfo(const QString &fileName, QString& frameworkId, + QStringList &frameworks, QString &originalBuildDir) { + verbose() << "Relocator calling otool -l for " << fileName << std::endl; QProcessWrapper otool; otool.start(QLatin1String("otool"), QStringList() << QLatin1String("-l") << fileName); if (!otool.waitForStarted()) { - setError(UserDefinedError, tr("Can't invoke otool.")); + setError(UserDefinedError, tr("Can't invoke otool. Is Xcode installed?")); return; } otool.waitForFinished(); @@ -123,7 +145,6 @@ void MacReplaceInstallNamesOperation::extractExecutableInfo(const QString& fileN while (!output.atEnd()) { QString line = QString::fromLocal8Bit(output.readLine()); line = line.trimmed(); -// qDebug() << line; if (line.startsWith(QLatin1String("cmd "))) { line.remove(0, 4); if (line == QLatin1String("LC_LOAD_DYLIB")) @@ -147,47 +168,58 @@ void MacReplaceInstallNamesOperation::extractExecutableInfo(const QString& fileN line = line.trimmed(); frameworkId = line; - mOriginalBuildDir = frameworkId; - idx = mOriginalBuildDir.indexOf(mIndicator); + originalBuildDir = frameworkId; + idx = originalBuildDir.indexOf(mIndicator); if (idx < 0) { - mOriginalBuildDir.clear(); + originalBuildDir.clear(); } else { - mOriginalBuildDir.truncate(idx); + originalBuildDir.truncate(idx); } - if (mOriginalBuildDir.endsWith(QLatin1Char('/'))) - mOriginalBuildDir.chop(1); + if (originalBuildDir.endsWith(QLatin1Char('/'))) + originalBuildDir.chop(1); + verbose() << "originalBuildDir is: " << originalBuildDir << std::endl; } } + verbose() << "END - Relocator calling otool -l for " << fileName << std::endl; } -void MacReplaceInstallNamesOperation::relocateBinary(const QString& fileName) +void MacReplaceInstallNamesOperation::relocateBinary(const QString &fileName) { QString frameworkId; QStringList frameworks; - extractExecutableInfo(fileName, frameworkId, frameworks); + QString originalBuildDir; + extractExecutableInfo(fileName, frameworkId, frameworks, originalBuildDir); + + verbose() << "got following informations(fileName, frameworkId, frameworks, orginalBuildDir): " << std::endl; + verbose() << fileName << ", " << frameworkId << ", " << frameworks.join(QLatin1String("|")) << ", " + << originalBuildDir << std::endl; QStringList args; - if (frameworkId.contains(mIndicator)) { + if (frameworkId.contains(mIndicator) || QFileInfo(frameworkId).fileName() == frameworkId) { args << QLatin1String("-id") << fileName << fileName; - execCommand(QLatin1String("install_name_tool"), args); + if (!execCommand(QLatin1String("install_name_tool"), args)) + return; } - foreach (const QString& fw, frameworks) { - if (!fw.contains(mOriginalBuildDir)) - continue; + foreach (const QString &fw, frameworks) { + if (originalBuildDir.isEmpty() && fw.contains(mIndicator)) { + originalBuildDir = fw.left(fw.indexOf(mIndicator)); + } + if (originalBuildDir.isEmpty() || !fw.contains(originalBuildDir)) + continue; QString newPath = fw; - newPath.replace(mOriginalBuildDir, mInstallationDir); + newPath.replace(originalBuildDir, mInstallationDir); args.clear(); args << QLatin1String("-change") << fw << newPath << fileName; - execCommand(QLatin1String("install_name_tool"), args); + if (!execCommand(QLatin1String("install_name_tool"), args)) + return; } } -void MacReplaceInstallNamesOperation::relocateFramework(const QString& directoryName) +void MacReplaceInstallNamesOperation::relocateFramework(const QString &directoryName) { - //qDebug() << "relocateFramework" << directoryName; QFileInfo fi(directoryName); QString frameworkName = fi.baseName(); fi.setFile(directoryName + QLatin1String("/Versions/Current/") + frameworkName); @@ -202,9 +234,9 @@ void MacReplaceInstallNamesOperation::relocateFramework(const QString& directory } } -bool MacReplaceInstallNamesOperation::execCommand(const QString& cmd, const QStringList& args) +bool MacReplaceInstallNamesOperation::execCommand(const QString &cmd, const QStringList &args) { - //qDebug() << cmd << args; + verbose() << "Relocator::execCommand " << cmd << " " << args << std::endl; QProcessWrapper process; process.start(cmd, args); @@ -213,5 +245,11 @@ bool MacReplaceInstallNamesOperation::execCommand(const QString& cmd, const QStr return false; } process.waitForFinished(); + if (process.exitCode() != 0) { + QString errorMessage = QLatin1String("Command %1 failed.\nArguments: %2\nOutput: %3\n"); + setError(UserDefinedError, errorMessage.arg(cmd, args.join(QLatin1String(" ")), + QString::fromLocal8Bit(process.readAll()))); + return false; + } return true; } diff --git a/installerbuilder/libinstaller/macreplaceinstallnamesoperation.h b/installerbuilder/libinstaller/macreplaceinstallnamesoperation.h index 1e4f6acb1..3f8b03f1a 100644 --- a/installerbuilder/libinstaller/macreplaceinstallnamesoperation.h +++ b/installerbuilder/libinstaller/macreplaceinstallnamesoperation.h @@ -27,7 +27,7 @@ #define MACREPLACEINSTALLNAMEOPERATION_H #include <KDUpdater/UpdateOperation> -#include <QStringList> + namespace QInstaller { @@ -40,20 +40,20 @@ public: bool performOperation(); bool undoOperation(); bool testOperation(); - KDUpdater::UpdateOperation* clone() const; + KDUpdater::UpdateOperation *clone() const; - bool apply(const QString& oldString, const QString& newString, const QString& frameworkDir); + bool apply(const QString &oldString, const QString &newString, const QString &frameworkDir); private: - void extractExecutableInfo(const QString& fileName, QString& frameworkId, QStringList& frameworks); - void relocateFramework(const QString& directoryName); - void relocateBinary(const QString& fileName); - bool execCommand(const QString& cmd, const QStringList& args); + void extractExecutableInfo(const QString &fileName, QString &frameworkId, QStringList &frameworks, + QString &originalBuildDir); + void relocateFramework(const QString &directoryName); + void relocateBinary(const QString &fileName); + bool execCommand(const QString &cmd, const QStringList &args); private: QString mIndicator; QString mInstallationDir; - QString mOriginalBuildDir; }; } // namespace QInstaller diff --git a/installerbuilder/libinstaller/updatecreatorsettingsfrom21to22operation.cpp b/installerbuilder/libinstaller/updatecreatorsettingsfrom21to22operation.cpp index f4e08d107..a3514f866 100644 --- a/installerbuilder/libinstaller/updatecreatorsettingsfrom21to22operation.cpp +++ b/installerbuilder/libinstaller/updatecreatorsettingsfrom21to22operation.cpp @@ -197,6 +197,7 @@ bool convertQtInstallerSettings(QSettings &settings, const QString &toolChainsXm ("x86-windows-msys-pe-32bit")) ); bool result = operation.performOperation(); + Q_UNUSED(result); Q_ASSERT(result); } foreach (const QString gccePath, gcceToolChains) { @@ -214,6 +215,7 @@ bool convertQtInstallerSettings(QSettings &settings, const QString &toolChainsXm "arm-symbian-device-elf-32bit")) ); bool result = operation.performOperation(); + Q_UNUSED(result); Q_ASSERT(result); } return true; @@ -257,6 +259,7 @@ void convertDefaultGDBInstallerSettings(QSettings &settings, QInstaller::Package it.next(); operation.setArguments(QStringList() << it.key() << it.value()); bool result = operation.performOperation(); + Q_UNUSED(result); Q_ASSERT(result); } diff --git a/tools/operationrunner/operationrunner.cpp b/tools/operationrunner/operationrunner.cpp index 623c711c6..b76aed455 100644 --- a/tools/operationrunner/operationrunner.cpp +++ b/tools/operationrunner/operationrunner.cpp @@ -107,8 +107,11 @@ int main(int argc, char **argv) QInstaller::init(); + QInstaller::VerboseWriter::instance(); + QInstaller::setVerbose( true ); + QString operationName = argumentList.takeFirst(); KDUpdater::UpdateOperation* const operation = KDUpdater::UpdateOperationFactory::instance().create(operationName); if (!operation) { @@ -127,10 +130,12 @@ int main(int argc, char **argv) } FakeInstaller fakeInstaller; - fakeInstaller.setTargetDir(sdkTargetDir); + if (!sdkTargetDir.isEmpty()) { + fakeInstaller.setTargetDir(sdkTargetDir); - operation->setValue(QLatin1String("installer"), - QVariant::fromValue(static_cast<QInstaller::Installer*>(&fakeInstaller))); + operation->setValue(QLatin1String("installer"), + QVariant::fromValue(static_cast<QInstaller::Installer*>(&fakeInstaller))); + } operation->setArguments(argumentList); |