From dd666a3af41b21c780c9ede91bf25069744891a8 Mon Sep 17 00:00:00 2001 From: ck Date: Tue, 22 Jun 2010 14:40:08 +0200 Subject: [PATCH] Maemo: Add option to disable packaging. Task-number: QTCREATORBUG-1636 Reviewed-by: kh1 --- .../qt-maemo/maemoconstants.h | 1 + .../qt-maemo/maemopackagecontents.cpp | 12 +-- .../qt-maemo/maemopackagecontents.h | 42 +++++---- .../qt-maemo/maemopackagecreationstep.cpp | 3 +- .../qt-maemo/maemopackagecreationwidget.cpp | 5 +- .../qt-maemo/maemopackagecreationwidget.ui | 5 +- .../qt-maemo/maemorunconfiguration.cpp | 28 +++--- .../qt-maemo/maemorunconfiguration.h | 9 +- .../qt-maemo/maemoruncontrol.cpp | 87 ++++++++++++++----- .../qt-maemo/maemoruncontrol.h | 13 ++- 10 files changed, 126 insertions(+), 79 deletions(-) diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemoconstants.h b/src/plugins/qt4projectmanager/qt-maemo/maemoconstants.h index 0696d187a80..54973696e60 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemoconstants.h +++ b/src/plugins/qt4projectmanager/qt-maemo/maemoconstants.h @@ -63,6 +63,7 @@ static const QLatin1String SimulatorPathKey(PREFIX ".Simulator"); static const QLatin1String DeviceIdKey(PREFIX ".DeviceId"); static const QLatin1String LastDeployedHostsKey(PREFIX ".LastDeployedHosts"); static const QLatin1String LastDeployedFilesKey(PREFIX ".LastDeployedFiles"); +static const QLatin1String LastDeployedRemotePathsKey(PREFIX ".LastDeployedRemotePaths"); static const QLatin1String LastDeployedTimesKey(PREFIX ".LastDeployedTimes"); static const QLatin1String ProFileKey(".ProFile"); diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecontents.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecontents.cpp index 583552a8621..a62c40609ba 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecontents.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecontents.cpp @@ -58,16 +58,16 @@ MaemoPackageContents::MaemoPackageContents(MaemoPackageCreationStep *packageStep { } -MaemoPackageContents::Deployable MaemoPackageContents::deployableAt(int row) const +MaemoDeployable MaemoPackageContents::deployableAt(int row) const { Q_ASSERT(row >= 0 && row < rowCount()); return row == 0 - ? Deployable(m_packageStep->localExecutableFilePath(), + ? MaemoDeployable(m_packageStep->localExecutableFilePath(), remoteExecutableFilePath()) : m_deployables.at(row - 1); } -bool MaemoPackageContents::addDeployable(const Deployable &deployable) +bool MaemoPackageContents::addDeployable(const MaemoDeployable &deployable) { if (m_deployables.contains(deployable) || deployableAt(0) == deployable) return false; @@ -103,7 +103,7 @@ QVariant MaemoPackageContents::data(const QModelIndex &index, int role) const if (!index.isValid() || index.row() >= rowCount()) return QVariant(); - const Deployable &d = deployableAt(index.row()); + const MaemoDeployable &d = deployableAt(index.row()); if (index.column() == 0 && role == Qt::DisplayRole) return d.localFilePath; if (role == Qt::DisplayRole || role == Qt::EditRole) @@ -151,7 +151,7 @@ QVariantMap MaemoPackageContents::toMap() const map.insert(REMOTE_EXE_KEY, m_remoteExecutableFilePath); QStringList localFiles; QStringList remoteFiles; - foreach (const Deployable &p, m_deployables) { + foreach (const MaemoDeployable &p, m_deployables) { localFiles << p.localFilePath; remoteFiles << p.remoteFilePath; } @@ -170,7 +170,7 @@ void MaemoPackageContents::fromMap(const QVariantMap &map) qWarning("%s: serialized data inconsistent", Q_FUNC_INFO); const int count = qMin(localFiles.count(), remoteFiles.count()); for (int i = 0; i < count; ++i) - m_deployables << Deployable(localFiles.at(i), remoteFiles.at(i)); + m_deployables << MaemoDeployable(localFiles.at(i), remoteFiles.at(i)); } QString MaemoPackageContents::remoteExecutableFilePath() const diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecontents.h b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecontents.h index 2f039f71764..a6cb5bec890 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecontents.h +++ b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecontents.h @@ -31,6 +31,7 @@ #define MAEMOPACKAGECONTENTS_H #include +#include #include #include #include @@ -38,27 +39,32 @@ namespace Qt4ProjectManager { namespace Internal { +struct MaemoDeployable +{ + MaemoDeployable(const QString &localFilePath, const QString &remoteFilePath) + : localFilePath(localFilePath), remoteFilePath(remoteFilePath) {} + + bool operator==(const MaemoDeployable &other) const + { + return localFilePath == other.localFilePath + && remoteFilePath == other.remoteFilePath; + } + + QString localFilePath; + QString remoteFilePath; +}; +inline uint qHash(const MaemoDeployable &d) +{ + return qHash(qMakePair(d.localFilePath, d.remoteFilePath)); +} + + class MaemoPackageCreationStep; class MaemoPackageContents : public QAbstractTableModel { Q_OBJECT public: - struct Deployable - { - Deployable(const QString &localFilePath, const QString &remoteFilePath) - : localFilePath(localFilePath), remoteFilePath(remoteFilePath) {} - - bool operator==(const Deployable &other) const - { - return localFilePath == other.localFilePath - && remoteFilePath == other.remoteFilePath; - } - - QString localFilePath; - QString remoteFilePath; - }; - MaemoPackageContents(MaemoPackageCreationStep *packageStep); virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; @@ -66,8 +72,8 @@ public: QVariantMap toMap() const; void fromMap(const QVariantMap &map); - Deployable deployableAt(int row) const; - bool addDeployable(const Deployable &deployable); + MaemoDeployable deployableAt(int row) const; + bool addDeployable(const MaemoDeployable &deployable); void removeDeployableAt(int row); bool isModified() const { return m_modified; } void setUnModified() { m_modified = false; } @@ -85,7 +91,7 @@ private: private: const MaemoPackageCreationStep * const m_packageStep; - QList m_deployables; + QList m_deployables; bool m_modified; mutable QString m_remoteExecutableFilePath; }; diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationstep.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationstep.cpp index b63822b5721..fdd0ad07108 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationstep.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationstep.cpp @@ -186,8 +186,7 @@ bool MaemoPackageCreationStep::createPackage() const QDir debianRoot = QDir(buildDir % QLatin1String("/debian/") % executableFileName().toLower()); for (int i = 0; i < m_packageContents->rowCount(); ++i) { - const MaemoPackageContents::Deployable &d - = m_packageContents->deployableAt(i); + const MaemoDeployable &d = m_packageContents->deployableAt(i); const QString targetFile = debianRoot.path() + '/' + d.remoteFilePath; const QString absTargetDir = QFileInfo(targetFile).dir().path(); const QString relTargetDir = debianRoot.relativeFilePath(absTargetDir); diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.cpp index 8f1005f1aad..6306e910cec 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.cpp @@ -65,7 +65,6 @@ MaemoPackageCreationWidget::MaemoPackageCreationWidget(MaemoPackageCreationStep { m_ui->setupUi(this); m_ui->skipCheckBox->setChecked(!m_step->isPackagingEnabled()); - m_ui->packageContentsView->setEnabled(m_step->isPackagingEnabled()); m_ui->packageContentsView->setModel(step->packageContents()); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); connect(step->packageContents(), SIGNAL(dataChanged(QModelIndex,QModelIndex)), @@ -104,8 +103,7 @@ void MaemoPackageCreationWidget::addFile() const QString localFile = QFileDialog::getOpenFileName(this, title, baseDir); if (localFile.isEmpty()) return; - const MaemoPackageContents::Deployable - deployable(QFileInfo(localFile).absoluteFilePath(), "/"); + const MaemoDeployable deployable(QFileInfo(localFile).absoluteFilePath(), "/"); MaemoPackageContents * const contents = m_step->packageContents(); if (!contents->addDeployable(deployable)) { QMessageBox::information(this, tr("File already in package"), @@ -141,7 +139,6 @@ void MaemoPackageCreationWidget::enableOrDisableRemoveButton() void MaemoPackageCreationWidget::handleSkipButtonToggled(bool checked) { m_step->setPackagingEnabled(!checked); - m_ui->packageContentsView->setEnabled(m_step->isPackagingEnabled()); } } // namespace Internal diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.ui b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.ui index ef1ed2334d1..6d72b7433b3 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.ui +++ b/src/plugins/qt4projectmanager/qt-maemo/maemopackagecreationwidget.ui @@ -23,8 +23,7 @@ - Check this if you build the package externally. It still needs to be at the location listed above -and the remote executable is assumed to be in the directory mentioned below. + Check this if you want the files below to be deployed directly. Skip Packaging Step @@ -40,7 +39,7 @@ and the remote executable is assumed to be in the directory mentioned below. - Package contents: + Files to deploy: diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.cpp index b408f038ab1..db90c406dd8 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.cpp @@ -134,15 +134,18 @@ void MaemoRunConfiguration::addDeployTimesToMap(QVariantMap &map) const { QVariantList hostList; QVariantList fileList; + QVariantList remotePathList; QVariantList timeList; - typedef QMap::ConstIterator DepIt; + typedef QHash::ConstIterator DepIt; for (DepIt it = m_lastDeployed.begin(); it != m_lastDeployed.end(); ++it) { - hostList << it.key().first; + hostList << it.key().first.localFilePath; + remotePathList << it.key().first.remoteFilePath; fileList << it.key().second; timeList << it.value(); } map.insert(LastDeployedHostsKey, hostList); map.insert(LastDeployedFilesKey, fileList); + map.insert(LastDeployedRemotePathsKey, remotePathList); map.insert(LastDeployedTimesKey, timeList); } @@ -165,28 +168,33 @@ void MaemoRunConfiguration::getDeployTimesFromMap(const QVariantMap &map) { const QVariantList &hostList = map.value(LastDeployedHostsKey).toList(); const QVariantList &fileList = map.value(LastDeployedFilesKey).toList(); + const QVariantList &remotePathList + = map.value(LastDeployedRemotePathsKey).toList(); const QVariantList &timeList = map.value(LastDeployedTimesKey).toList(); const int elemCount - = qMin(qMin(hostList.size(), fileList.size()), timeList.size()); + = qMin(qMin(hostList.size(), fileList.size()), + qMin(remotePathList.size(), timeList.size())); for (int i = 0; i < elemCount; ++i) { - m_lastDeployed.insert(DeployablePerHost(hostList.at(i).toString(), - fileList.at(i).toString()), timeList.at(i).toDateTime()); + const MaemoDeployable d(fileList.at(i).toString(), + remotePathList.at(i).toString()); + m_lastDeployed.insert(DeployablePerHost(d, hostList.at(i).toString()), + timeList.at(i).toDateTime()); } } bool MaemoRunConfiguration::currentlyNeedsDeployment(const QString &host, - const QString &file) const + const MaemoDeployable &deployable) const { const QDateTime &lastDeployed - = m_lastDeployed.value(DeployablePerHost(host, file)); + = m_lastDeployed.value(DeployablePerHost(deployable, host)); return !lastDeployed.isValid() - || QFileInfo(file).lastModified() > lastDeployed; + || QFileInfo(deployable.localFilePath).lastModified() > lastDeployed; } void MaemoRunConfiguration::setDeployed(const QString &host, - const QString &file) + const MaemoDeployable &deployable) { - m_lastDeployed.insert(DeployablePerHost(host, file), + m_lastDeployed.insert(DeployablePerHost(deployable, host), QDateTime::currentDateTime()); } diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.h b/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.h index 26abb766496..3bf21336e2c 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.h +++ b/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.h @@ -32,6 +32,7 @@ #include "maemoconstants.h" #include "maemodeviceconfigurations.h" +#include "maemopackagecontents.h" #include @@ -70,8 +71,8 @@ public: Qt4BuildConfiguration *activeQt4BuildConfiguration() const; bool currentlyNeedsDeployment(const QString &host, - const QString &file) const; - void setDeployed(const QString &host, const QString &file); + const MaemoDeployable &deployable) const; + void setDeployed(const QString &host, const MaemoDeployable &deployable); const MaemoPackageCreationStep *packageStep() const; @@ -118,8 +119,8 @@ private: MaemoDeviceConfig m_devConfig; QStringList m_arguments; - typedef QPair DeployablePerHost; - QMap m_lastDeployed; + typedef QPair DeployablePerHost; + QHash m_lastDeployed; }; } // namespace Internal diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemoruncontrol.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemoruncontrol.cpp index 37635de223f..80861bab93d 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemoruncontrol.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemoruncontrol.cpp @@ -34,7 +34,6 @@ #include "maemoruncontrol.h" -#include "maemopackagecontents.h" #include "maemopackagecreationstep.h" #include "maemosshthread.h" #include "maemorunconfiguration.h" @@ -46,6 +45,7 @@ #include #include +#include #include #include #include @@ -123,27 +123,55 @@ void AbstractMaemoRunControl::startDeployment(bool forDebugging) if (m_stoppedByUser) { emit finished(); } else { + m_needsInstall = false; m_deployables.clear(); - if (m_runConfig->currentlyNeedsDeployment(m_devConfig.server.host, - packageFilePath())) { - m_deployables.append(Deployable(packageFileName(), - QFileInfo(executableOnHost()).canonicalPath())); - m_needsInstall = true; + m_remoteLinks.clear(); + const MaemoPackageCreationStep * const packageStep + = m_runConfig->packageStep(); + if (packageStep->isPackagingEnabled()) { + const MaemoDeployable d(packageFilePath(), + remoteDir() + '/' + packageFileName()); + m_needsInstall = addDeployableIfNeeded(d); } else { - m_needsInstall = false; + const MaemoPackageContents * const packageContents + = packageStep->packageContents(); + for (int i = 0; i < packageContents->rowCount(); ++i) { + const MaemoDeployable &d = packageContents->deployableAt(i); + if (addDeployableIfNeeded(d)) + m_needsInstall = true; + } } + if (forDebugging) { - const QFileInfo info(m_runConfig->dumperLib()); - if (info.exists() - && m_runConfig->currentlyNeedsDeployment(m_devConfig.server.host, - info.filePath())) { - m_deployables.append(Deployable(info.fileName(), info.canonicalPath())); + QFileInfo dumperInfo(m_runConfig->dumperLib()); + if (dumperInfo.exists()) { + const MaemoDeployable d(m_runConfig->dumperLib(), + remoteDir() + '/' + dumperInfo.fileName()); + m_needsInstall = addDeployableIfNeeded(d); } } deploy(); } } +bool AbstractMaemoRunControl::addDeployableIfNeeded(const MaemoDeployable &deployable) +{ + if (m_runConfig->currentlyNeedsDeployment(m_devConfig.server.host, + deployable)) { + const QString fileName + = QFileInfo(deployable.remoteFilePath).fileName(); + const QString sftpTargetFilePath = remoteDir() + '/' + fileName + '.' + + QCryptographicHash::hash(deployable.remoteFilePath.toUtf8(), + QCryptographicHash::Md5).toHex(); + m_deployables.append(MaemoDeployable(deployable.localFilePath, + sftpTargetFilePath)); + m_remoteLinks.insert(sftpTargetFilePath, deployable.remoteFilePath); + return true; + } else { + return false; + } +} + void AbstractMaemoRunControl::deploy() { Core::ICore::instance()->progressManager() @@ -152,14 +180,11 @@ void AbstractMaemoRunControl::deploy() if (!m_deployables.isEmpty()) { QList deploySpecs; QStringList files; - foreach (const Deployable &deployable, m_deployables) { - const QString srcFilePath - = deployable.dir % QDir::separator() % deployable.fileName; - const QString tgtFilePath - = remoteDir() % QDir::separator() % deployable.fileName; - files << srcFilePath; - deploySpecs << Core::SftpTransferInfo(srcFilePath, - tgtFilePath.toUtf8(), Core::SftpTransferInfo::Upload); + foreach (const MaemoDeployable &deployable, m_deployables) { + files << deployable.localFilePath; + deploySpecs << Core::SftpTransferInfo(deployable.localFilePath, + deployable.remoteFilePath.toUtf8(), + Core::SftpTransferInfo::Upload); } emit appendMessage(this, tr("Files to deploy: %1.").arg(files.join(" ")), false); m_sshDeployer.reset(new MaemoSshDeployer(m_devConfig.server, deploySpecs)); @@ -179,9 +204,10 @@ void AbstractMaemoRunControl::deploy() void AbstractMaemoRunControl::handleFileCopied() { - Deployable deployable = m_deployables.takeFirst(); + const MaemoDeployable &deployable = m_deployables.takeFirst(); m_runConfig->setDeployed(m_devConfig.server.host, - deployable.dir + QLatin1Char('/') + deployable.fileName); + MaemoDeployable(deployable.localFilePath, + m_remoteLinks.value(deployable.remoteFilePath))); m_progress.setProgressValue(m_progress.progressValue() + 1); } @@ -320,8 +346,21 @@ QString AbstractMaemoRunControl::remoteSudo() const QString AbstractMaemoRunControl::remoteInstallCommand() const { - return QString::fromLocal8Bit("%1 dpkg -i %2").arg(remoteSudo()) - .arg(packageFileName()); + Q_ASSERT(m_needsInstall); + QString cmd; + for (QMap::ConstIterator it = m_remoteLinks.begin(); + it != m_remoteLinks.end(); ++it) { + cmd += QString::fromLocal8Bit("%1 ln -sf %2 %3 && ") + .arg(remoteSudo(), it.key(), it.value()); + } + if (m_runConfig->packageStep()->isPackagingEnabled()) { + cmd += QString::fromLocal8Bit("%1 dpkg -i %2").arg(remoteSudo()) + .arg(packageFileName()); + } else if (!m_remoteLinks.isEmpty()) { + return cmd.remove(cmd.length() - 4, 4); // Trailing " && " + } + + return cmd; } const QString AbstractMaemoRunControl::targetCmdLinePrefix() const diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemoruncontrol.h b/src/plugins/qt4projectmanager/qt-maemo/maemoruncontrol.h index e53a8b456ea..9230bfd6c1c 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemoruncontrol.h +++ b/src/plugins/qt4projectmanager/qt-maemo/maemoruncontrol.h @@ -36,6 +36,7 @@ #define MAEMORUNCONTROL_H #include "maemodeviceconfigurations.h" +#include "maemopackagecontents.h" #include @@ -97,6 +98,8 @@ protected: const MaemoDeviceConfig m_devConfig; private: + bool addDeployableIfNeeded(const MaemoDeployable &deployable); + virtual void startInternal()=0; virtual void stopInternal()=0; virtual QString remoteCall() const=0; @@ -115,14 +118,8 @@ private: QScopedPointer m_initialCleaner; bool m_stoppedByUser; - struct Deployable - { - Deployable(const QString &f, const QString &d) - : fileName(f), dir(d) {} - QString fileName; - QString dir; - }; - QList m_deployables; + QList m_deployables; + QMap m_remoteLinks; bool m_needsInstall; };