~bzoltan/kubuntu-packaging/decouple_cmake_plugin

« back to all changes in this revision

Viewing changes to src/plugins/madde/maemoglobal.cpp

  • Committer: Timo Jyrinki
  • Date: 2013-11-15 12:25:23 UTC
  • mfrom: (1.1.28)
  • Revision ID: timo.jyrinki@canonical.com-20131115122523-i2kyamsu4gs2mu1m
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
**
3
 
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4
 
** Contact: http://www.qt-project.org/legal
5
 
**
6
 
** This file is part of Qt Creator.
7
 
**
8
 
** Commercial License Usage
9
 
** Licensees holding valid commercial Qt licenses may use this file in
10
 
** accordance with the commercial license agreement provided with the
11
 
** Software or, alternatively, in accordance with the terms contained in
12
 
** a written agreement between you and Digia.  For licensing terms and
13
 
** conditions see http://qt.digia.com/licensing.  For further information
14
 
** use the contact form at http://qt.digia.com/contact-us.
15
 
**
16
 
** GNU Lesser General Public License Usage
17
 
** Alternatively, this file may be used under the terms of the GNU Lesser
18
 
** General Public License version 2.1 as published by the Free Software
19
 
** Foundation and appearing in the file LICENSE.LGPL included in the
20
 
** packaging of this file.  Please review the following information to
21
 
** ensure the GNU Lesser General Public License version 2.1 requirements
22
 
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
 
**
24
 
** In addition, as a special exception, Digia gives you certain additional
25
 
** rights.  These rights are described in the Digia Qt LGPL Exception
26
 
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27
 
**
28
 
****************************************************************************/
29
 
#include "maemoglobal.h"
30
 
 
31
 
#include "maemoconstants.h"
32
 
#include "maemoqemumanager.h"
33
 
 
34
 
#include <projectexplorer/devicesupport/idevice.h>
35
 
#include <projectexplorer/kitinformation.h>
36
 
#include <projectexplorer/target.h>
37
 
#include <qt4projectmanager/qt4projectmanagerconstants.h>
38
 
#include <qtsupport/baseqtversion.h>
39
 
#include <qtsupport/qtkitinformation.h>
40
 
#include <remotelinux/remotelinux_constants.h>
41
 
#include <utils/environment.h>
42
 
#include <utils/hostosinfo.h>
43
 
 
44
 
#include <QDir>
45
 
#include <QFileInfo>
46
 
#include <QProcess>
47
 
#include <QString>
48
 
#include <QDesktopServices>
49
 
 
50
 
using namespace ProjectExplorer;
51
 
using namespace Qt4ProjectManager;
52
 
using namespace Qt4ProjectManager::Constants;
53
 
using namespace RemoteLinux;
54
 
using namespace Utils;
55
 
 
56
 
namespace Madde {
57
 
namespace Internal {
58
 
static const QString binQmake = QLatin1String("/bin/qmake" QTC_HOST_EXE_SUFFIX);
59
 
 
60
 
bool MaemoGlobal::hasMaemoDevice(const Kit *k)
61
 
{
62
 
    IDevice::ConstPtr dev = DeviceKitInformation::device(k);
63
 
    if (dev.isNull())
64
 
        return false;
65
 
 
66
 
    const Core::Id type = dev->type();
67
 
    return type == Maemo5OsType || type == HarmattanOsType;
68
 
}
69
 
 
70
 
bool MaemoGlobal::supportsMaemoDevice(const Kit *k)
71
 
{
72
 
    const Core::Id type = DeviceTypeKitInformation::deviceTypeId(k);
73
 
    return type == Maemo5OsType || type == HarmattanOsType;
74
 
}
75
 
 
76
 
bool MaemoGlobal::isValidMaemo5QtVersion(const QString &qmakePath)
77
 
{
78
 
    return isValidMaemoQtVersion(qmakePath, Core::Id(Maemo5OsType));
79
 
}
80
 
 
81
 
bool MaemoGlobal::isValidHarmattanQtVersion(const QString &qmakePath)
82
 
{
83
 
    return isValidMaemoQtVersion(qmakePath, Core::Id(HarmattanOsType));
84
 
}
85
 
 
86
 
bool MaemoGlobal::isValidMaemoQtVersion(const QString &qmakePath, Core::Id deviceType)
87
 
{
88
 
    if (MaemoGlobal::deviceType(qmakePath) != deviceType)
89
 
        return false;
90
 
    QProcess madAdminProc;
91
 
    const QStringList arguments(QLatin1String("list"));
92
 
    if (!callMadAdmin(madAdminProc, arguments, qmakePath, false))
93
 
        return false;
94
 
    if (!madAdminProc.waitForStarted() || !madAdminProc.waitForFinished())
95
 
        return false;
96
 
 
97
 
    madAdminProc.setReadChannel(QProcess::StandardOutput);
98
 
    const QByteArray tgtName = targetName(qmakePath).toLatin1();
99
 
    while (madAdminProc.canReadLine()) {
100
 
        const QByteArray &line = madAdminProc.readLine();
101
 
        if (line.contains(tgtName)
102
 
            && (line.contains("(installed)") || line.contains("(default)")))
103
 
            return true;
104
 
    }
105
 
    return false;
106
 
}
107
 
 
108
 
 
109
 
QString MaemoGlobal::homeDirOnDevice(const QString &uname)
110
 
{
111
 
    return uname == QLatin1String("root")
112
 
        ? QString::fromLatin1("/root")
113
 
        : QLatin1String("/home/") + uname;
114
 
}
115
 
 
116
 
QString MaemoGlobal::devrootshPath()
117
 
{
118
 
    return QLatin1String("/usr/lib/mad-developer/devrootsh");
119
 
}
120
 
 
121
 
int MaemoGlobal::applicationIconSize(const Target *target)
122
 
{
123
 
    Core::Id deviceType = DeviceTypeKitInformation::deviceTypeId(target->kit());
124
 
    return deviceType == HarmattanOsType ? 80 : 64;
125
 
}
126
 
 
127
 
QString MaemoGlobal::remoteSudo(Core::Id deviceType, const QString &uname)
128
 
{
129
 
    if (uname == QLatin1String("root"))
130
 
        return QString();
131
 
    if (deviceType == Maemo5OsType || deviceType == HarmattanOsType)
132
 
        return devrootshPath();
133
 
    return QString(); // Using sudo would open a can of worms.
134
 
}
135
 
 
136
 
QString MaemoGlobal::remoteSourceProfilesCommand()
137
 
{
138
 
    const QList<QByteArray> profiles = QList<QByteArray>() << "/etc/profile"
139
 
        << "/home/user/.profile" << "~/.profile";
140
 
    QByteArray remoteCall(":");
141
 
    foreach (const QByteArray &profile, profiles)
142
 
        remoteCall += "; test -f " + profile + " && source " + profile;
143
 
    return QString::fromLatin1(remoteCall);
144
 
}
145
 
 
146
 
PortList MaemoGlobal::freePorts(const Kit *k)
147
 
{
148
 
    IDevice::ConstPtr device = DeviceKitInformation::device(k);
149
 
    QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitInformation::qtVersion(k);
150
 
 
151
 
    if (!device || !qtVersion)
152
 
        return PortList();
153
 
    if (device->machineType() == IDevice::Emulator) {
154
 
        MaemoQemuRuntime rt;
155
 
        const int id = qtVersion->uniqueId();
156
 
        if (MaemoQemuManager::instance().runtimeForQtVersion(id, &rt))
157
 
            return rt.m_freePorts;
158
 
    }
159
 
    return device->freePorts();
160
 
}
161
 
 
162
 
QString MaemoGlobal::maddeRoot(const QString &qmakePath)
163
 
{
164
 
    QDir dir(targetRoot(qmakePath));
165
 
    dir.cdUp(); dir.cdUp();
166
 
    return dir.absolutePath();
167
 
}
168
 
 
169
 
FileName MaemoGlobal::maddeRoot(const Kit *k)
170
 
{
171
 
    return SysRootKitInformation::sysRoot(k).parentDir().parentDir();
172
 
}
173
 
 
174
 
QString MaemoGlobal::targetRoot(const QString &qmakePath)
175
 
{
176
 
    return QDir::cleanPath(qmakePath).remove(binQmake, HostOsInfo::fileNameCaseSensitivity());
177
 
}
178
 
 
179
 
QString MaemoGlobal::targetName(const QString &qmakePath)
180
 
{
181
 
    return QDir(targetRoot(qmakePath)).dirName();
182
 
}
183
 
 
184
 
QString MaemoGlobal::madAdminCommand(const QString &qmakePath)
185
 
{
186
 
    return maddeRoot(qmakePath) + QLatin1String("/bin/mad-admin");
187
 
}
188
 
 
189
 
QString MaemoGlobal::madCommand(const QString &qmakePath)
190
 
{
191
 
    return maddeRoot(qmakePath) + QLatin1String("/bin/mad");
192
 
}
193
 
 
194
 
QString MaemoGlobal::madDeveloperUiName(Core::Id deviceType)
195
 
{
196
 
    return deviceType == HarmattanOsType
197
 
        ? tr("SDK Connectivity") : tr("Mad Developer");
198
 
}
199
 
 
200
 
Core::Id MaemoGlobal::deviceType(const QString &qmakePath)
201
 
{
202
 
    const QString &name = targetName(qmakePath);
203
 
    if (name.startsWith(QLatin1String("fremantle")))
204
 
        return Core::Id(Maemo5OsType);
205
 
    if (name.startsWith(QLatin1String("harmattan")))
206
 
        return Core::Id(HarmattanOsType);
207
 
    return Core::Id(RemoteLinux::Constants::GenericLinuxOsType);
208
 
}
209
 
 
210
 
QString MaemoGlobal::architecture(const QString &qmakePath)
211
 
{
212
 
    QProcess proc;
213
 
    const QStringList args = QStringList() << QLatin1String("uname")
214
 
        << QLatin1String("-m");
215
 
    if (!callMad(proc, args, qmakePath, true))
216
 
        return QString();
217
 
    if (!proc.waitForFinished())
218
 
        return QString();
219
 
    QString arch = QString::fromUtf8(proc.readAllStandardOutput());
220
 
    arch.chop(1); // Newline
221
 
    return arch;
222
 
}
223
 
 
224
 
void MaemoGlobal::addMaddeEnvironment(Environment &env, const QString &qmakePath)
225
 
{
226
 
    Environment maddeEnv;
227
 
    if (HostOsInfo::isWindowsHost()) {
228
 
        const QString root = maddeRoot(qmakePath);
229
 
        env.prependOrSetPath(root + QLatin1String("/bin"));
230
 
        env.prependOrSet(QLatin1String("HOME"),
231
 
                QDesktopServices::storageLocation(QDesktopServices::HomeLocation));
232
 
    }
233
 
    for (Environment::const_iterator it = maddeEnv.constBegin(); it != maddeEnv.constEnd(); ++it)
234
 
        env.prependOrSet(it.key(), it.value());
235
 
}
236
 
 
237
 
void MaemoGlobal::transformMaddeCall(QString &command, QStringList &args, const QString &qmakePath)
238
 
{
239
 
    if (HostOsInfo::isWindowsHost()) {
240
 
        const QString root = maddeRoot(qmakePath);
241
 
        args.prepend(command);
242
 
        command = root + QLatin1String("/bin/sh.exe");
243
 
    }
244
 
}
245
 
 
246
 
bool MaemoGlobal::callMad(QProcess &proc, const QStringList &args,
247
 
    const QString &qmakePath, bool useTarget)
248
 
{
249
 
    return callMaddeShellScript(proc, qmakePath, madCommand(qmakePath), args,
250
 
        useTarget);
251
 
}
252
 
 
253
 
bool MaemoGlobal::callMadAdmin(QProcess &proc, const QStringList &args,
254
 
    const QString &qmakePath, bool useTarget)
255
 
{
256
 
    return callMaddeShellScript(proc, qmakePath, madAdminCommand(qmakePath),
257
 
        args, useTarget);
258
 
}
259
 
 
260
 
bool MaemoGlobal::callMaddeShellScript(QProcess &proc,
261
 
    const QString &qmakePath, const QString &command, const QStringList &args,
262
 
    bool useTarget)
263
 
{
264
 
    if (!QFileInfo(command).exists())
265
 
        return false;
266
 
    QString actualCommand = command;
267
 
    QStringList actualArgs = targetArgs(qmakePath, useTarget) + args;
268
 
    Environment env(proc.systemEnvironment());
269
 
    addMaddeEnvironment(env, qmakePath);
270
 
    proc.setEnvironment(env.toStringList());
271
 
    transformMaddeCall(actualCommand, actualArgs, qmakePath);
272
 
    proc.start(actualCommand, actualArgs);
273
 
    return true;
274
 
}
275
 
 
276
 
QStringList MaemoGlobal::targetArgs(const QString &qmakePath, bool useTarget)
277
 
{
278
 
    QStringList args;
279
 
    if (useTarget)
280
 
        args << QLatin1String("-t") << targetName(qmakePath);
281
 
    return args;
282
 
}
283
 
 
284
 
} // namespace Internal
285
 
} // namespace Madde