From 947f0f3a30fd5604bbb788c3c8268c3cf614c1fa Mon Sep 17 00:00:00 2001
From: Christian Kandeler <christian.kandeler@nokia.com>
Date: Mon, 13 Sep 2010 16:50:30 +0200
Subject: [PATCH] Maemo: source all relevant profiles and ignore non-existing
 ones.

Reviewed-by: kh1
---
 .../qt-maemo/maemodeviceenvreader.cpp              |  4 ++--
 .../qt4projectmanager/qt-maemo/maemoglobal.cpp     | 14 ++++++++++++--
 .../qt4projectmanager/qt-maemo/maemoglobal.h       |  1 +
 .../qt-maemo/maemoremotemounter.cpp                |  4 +++-
 4 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemodeviceenvreader.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemodeviceenvreader.cpp
index 10df061e708..b562aea94ce 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemodeviceenvreader.cpp
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemodeviceenvreader.cpp
@@ -34,6 +34,7 @@
 
 #include "maemodeviceenvreader.h"
 
+#include "maemoglobal.h"
 #include "maemorunconfiguration.h"
 
 #include <coreplugin/ssh/sshconnection.h>
@@ -101,8 +102,7 @@ void MaemoDeviceEnvReader::executeRemoteCall()
     if (m_stop)
         return;
 
-    const QByteArray remoteCall("test -f /etc/profile && source /etc/profile; "
-        "test -f ~/.profile && source ~/.profile; env");
+    const QByteArray remoteCall = MaemoGlobal::remoteSourceProfilesCommand().toUtf8() + "; env";
     m_remoteProcess = m_connection->createRemoteProcess(remoteCall);
 
     connect(m_remoteProcess.data(), SIGNAL(closed(int)), this,
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemoglobal.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemoglobal.cpp
index 8a1ee88a6c7..c07fd5cd59f 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemoglobal.cpp
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemoglobal.cpp
@@ -48,8 +48,18 @@ QString MaemoGlobal::remoteSudo()
 
 QString MaemoGlobal::remoteCommandPrefix(const QString &commandFilePath)
 {
-    return QString::fromLocal8Bit("%1 chmod a+x %2 && source /etc/profile; "
-        "source /home/user/.profile; ").arg(remoteSudo(), commandFilePath);
+    return QString::fromLocal8Bit("%1 chmod a+x %2; %3; ")
+        .arg(remoteSudo(), commandFilePath, remoteSourceProfilesCommand());
+}
+
+QString MaemoGlobal::remoteSourceProfilesCommand()
+{
+    const QList<QByteArray> profiles = QList<QByteArray>() << "/etc/profile"
+        << "/home/user/.profile" << "~/.profile";
+    QByteArray remoteCall(":");
+    foreach (const QByteArray &profile, profiles)
+        remoteCall += "; test -f " + profile + " && source " + profile;
+    return QString::fromAscii(remoteCall);
 }
 
 QString MaemoGlobal::remoteEnvironment(const QList<ProjectExplorer::EnvironmentItem> &list)
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemoglobal.h b/src/plugins/qt4projectmanager/qt-maemo/maemoglobal.h
index a43edb67246..762b67c4f4e 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemoglobal.h
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemoglobal.h
@@ -52,6 +52,7 @@ public:
     static QString remoteCommandPrefix(const QString &commandFilePath);
     static QString remoteEnvironment(const QList<ProjectExplorer::EnvironmentItem> &list);
     static QString remoteProjectSourcesMountPoint();
+    static QString remoteSourceProfilesCommand();
 
     template<class T> static T *buildStep(const ProjectExplorer::DeployConfiguration *dc)
     {
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemoremotemounter.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemoremotemounter.cpp
index e51bc93ec17..22a2e58dc9d 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemoremotemounter.cpp
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemoremotemounter.cpp
@@ -240,7 +240,9 @@ void MaemoRemoteMounter::startUtfsClients()
                   .arg(mountSpec.remoteMountPoint);
         if (mountInfo.mountAsRoot)
             utfsClient.prepend(MaemoGlobal::remoteSudo() + QLatin1Char(' '));
-        remoteCall += andOp + mkdir + andOp + chmod + andOp + utfsClient;
+        QLatin1String seqOp("; ");
+        remoteCall += seqOp + MaemoGlobal::remoteSourceProfilesCommand()
+            + seqOp + mkdir + andOp + chmod + andOp + utfsClient;
     }
 
     emit reportProgress(tr("Starting remote UTFS clients..."));
-- 
GitLab