maemoinstalltosysrootstep.cpp 14.5 KB
Newer Older
1
2
3
4
5
6
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
Tobias Hunger's avatar
Tobias Hunger committed
7
** Contact: Nokia Corporation (info@qt.nokia.com)
8
9
10
11
**
**
** GNU Lesser General Public License Usage
**
Tobias Hunger's avatar
Tobias Hunger committed
12
13
14
15
16
17
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18
19
**
** In addition, as a special exception, Nokia gives you certain additional
Tobias Hunger's avatar
Tobias Hunger committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
21
22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
Tobias Hunger's avatar
Tobias Hunger committed
23
24
25
26
27
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
28
** If you have questions regarding the use of this file, please contact
Tobias Hunger's avatar
Tobias Hunger committed
29
** Nokia at info@qt.nokia.com.
30
31
**
**************************************************************************/
Tobias Hunger's avatar
Tobias Hunger committed
32

33
34
35
36
#include "maemoinstalltosysrootstep.h"

#include "maemoglobal.h"
#include "maemopackagecreationstep.h"
37
#include "maemoqtversion.h"
38
#include "qt4maemotarget.h"
39

40
41
#include <utils/fileutils.h>

42
43
#include <qt4projectmanager/qt4buildconfiguration.h>
#include <qt4projectmanager/qt4target.h>
44
#include <qtsupport/baseqtversion.h>
45
46
47
#include <remotelinux/deployablefile.h>
#include <remotelinux/deploymentinfo.h>
#include <remotelinux/remotelinuxdeployconfiguration.h>
48

49
50
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
51
52
#include <QtCore/QLatin1Char>
#include <QtCore/QProcess>
53
#include <QtCore/QWeakPointer>
54
55

using namespace ProjectExplorer;
56
using namespace Qt4ProjectManager;
57
using namespace RemoteLinux;
58

59
namespace Madde {
60
61
62
63
64
65
66
namespace Internal {

class AbstractMaemoInstallPackageToSysrootWidget : public BuildStepConfigWidget
{
    Q_OBJECT
public:
    AbstractMaemoInstallPackageToSysrootWidget(AbstractMaemoInstallPackageToSysrootStep *step)
dt_'s avatar
dt_ committed
67
        : m_step(step)
68
    {
69
70
        BuildStepList * const list
             = qobject_cast<BuildStepList *>(m_step->parent());
71
72
        connect(list, SIGNAL(stepInserted(int)), SIGNAL(updateSummary()));
        connect(list, SIGNAL(stepMoved(int,int)), SIGNAL(updateSummary()));
73
        connect(list, SIGNAL(aboutToRemoveStep(int)), SLOT(handleStepToBeRemoved(int)));
74
75
76
77
78
        connect(list, SIGNAL(stepRemoved(int)), SIGNAL(updateSummary()));
    }

    virtual QString summaryText() const
    {
79
        if (!m_step->deployConfiguration()->earlierBuildStep<AbstractMaemoPackageCreationStep>(m_step)) {
80
81
82
83
84
85
86
87
            return QLatin1String("<font color=\"red\">")
                + tr("Cannot deploy to sysroot: No packaging step found.")
                + QLatin1String("</font>");
        }
        return QLatin1String("<b>") + displayName() + QLatin1String("</b>");
    }

private:
88
89
90
91
92
93
94
95
    Q_SLOT void handleStepToBeRemoved(int step)
    {
        BuildStepList * const list
            = qobject_cast<BuildStepList *>(m_step->parent());
        if (list->steps().at(step) == m_step)
            disconnect(list, 0, this, 0);
    }

96
97
98
99
100
101
102
103
104
105
106
    const AbstractMaemoInstallPackageToSysrootStep * const m_step;
};


class MaemoInstallDebianPackageToSysrootWidget : public AbstractMaemoInstallPackageToSysrootWidget
{
    Q_OBJECT
public:
    MaemoInstallDebianPackageToSysrootWidget(AbstractMaemoInstallPackageToSysrootStep *step)
        : AbstractMaemoInstallPackageToSysrootWidget(step) {}

Friedemann Kleint's avatar
Friedemann Kleint committed
107
    virtual QString displayName() const { return MaemoInstallDebianPackageToSysrootStep::displayName(); }
108
109
110
111
112
113
114
115
116
};

class MaemoInstallRpmPackageToSysrootWidget : public AbstractMaemoInstallPackageToSysrootWidget
{
    Q_OBJECT
public:
    MaemoInstallRpmPackageToSysrootWidget(AbstractMaemoInstallPackageToSysrootStep *step)
        : AbstractMaemoInstallPackageToSysrootWidget(step) {}

Friedemann Kleint's avatar
Friedemann Kleint committed
117
    virtual QString displayName() const { return MaemoInstallRpmPackageToSysrootStep::displayName(); }
118
119
120
121
122
123
};

class MaemoCopyFilesToSysrootWidget : public BuildStepConfigWidget
{
    Q_OBJECT
public:
124
    MaemoCopyFilesToSysrootWidget(const BuildStep *buildStep)
dt_'s avatar
dt_ committed
125
        : m_buildStep(buildStep)
126
127
128
129
130
131
    {
        if (m_buildStep) {
            connect(m_buildStep.data(), SIGNAL(displayNameChanged()),
                SIGNAL(updateSummary()));
        }
    }
132
133
    virtual QString summaryText() const {
        return QLatin1String("<b>") + displayName() + QLatin1String("</b>"); }
134
135
136
137
138
    virtual QString displayName() const {
        return m_buildStep ? m_buildStep.data()->displayName() : QString();
    }
private:
    const QWeakPointer<const BuildStep> m_buildStep;
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
};


AbstractMaemoInstallPackageToSysrootStep::AbstractMaemoInstallPackageToSysrootStep(BuildStepList *bsl,
    const QString &id)
        : BuildStep(bsl, id)
{
}

AbstractMaemoInstallPackageToSysrootStep::AbstractMaemoInstallPackageToSysrootStep(BuildStepList *bsl,
    AbstractMaemoInstallPackageToSysrootStep *other)
        : BuildStep(bsl, other)
{
}

154
155
156
157
158
RemoteLinuxDeployConfiguration *AbstractMaemoInstallPackageToSysrootStep::deployConfiguration() const
{
    return qobject_cast<RemoteLinuxDeployConfiguration *>(BuildStep::deployConfiguration());
}

159
bool AbstractMaemoInstallPackageToSysrootStep::init()
160
161
{
    const Qt4BuildConfiguration * const bc
162
        = qobject_cast<Qt4BaseTarget *>(target())->activeQt4BuildConfiguration();
163
    if (!bc) {
164
        addOutput(tr("Cannot install to sysroot without build configuration."),
165
            ErrorMessageOutput);
166
        return false;
167
168
169
    }

    const AbstractMaemoPackageCreationStep * const pStep
170
        = deployConfiguration()->earlierBuildStep<AbstractMaemoPackageCreationStep>(this);
171
    if (!pStep) {
172
        addOutput(tr("Cannot install package to sysroot without packaging step."),
173
            ErrorMessageOutput);
174
        return false;
175
176
    }

dt's avatar
dt committed
177
    if (!bc->qtVersion()) {
178
        addOutput(tr("Cannot install package to sysroot without a Qt version."),
dt's avatar
dt committed
179
            ErrorMessageOutput);
180
        return false;
dt's avatar
dt committed
181
182
    }

183
184
185
186
187
188
189
    m_qmakeCommand = bc->qtVersion()->qmakeCommand();
    m_packageFilePath = pStep->packageFilePath();
    return true;
}

void AbstractMaemoInstallPackageToSysrootStep::run(QFutureInterface<bool> &fi)
{
190
191
192
193
194
195
196
    m_installerProcess = new QProcess;
    connect(m_installerProcess, SIGNAL(readyReadStandardOutput()),
        SLOT(handleInstallerStdout()));
    connect(m_installerProcess, SIGNAL(readyReadStandardError()),
        SLOT(handleInstallerStderr()));

    emit addOutput(tr("Installing package to sysroot ..."), MessageOutput);
197
198
199
    const int packageFileSize = QFileInfo(m_packageFilePath).size() / (1024*1024);
    const QStringList args = madArguments() << m_packageFilePath;
    MaemoGlobal::callMadAdmin(*m_installerProcess, args, m_qmakeCommand, true);
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
    if (!m_installerProcess->waitForFinished((2*packageFileSize + 10)*1000)
            || m_installerProcess->exitStatus() != QProcess::NormalExit
            || m_installerProcess->exitCode() != 0) {
        emit addOutput(tr("Installation to sysroot failed, continuing anyway."),
            ErrorMessageOutput);
        if (m_installerProcess->state() != QProcess::NotRunning) {
            m_installerProcess->terminate();
            m_installerProcess->waitForFinished();
            m_installerProcess->kill();
        }
        fi.reportResult(true);
        return;
    }

    fi.reportResult(true);
    m_installerProcess->deleteLater();
    m_installerProcess = 0;
}

void AbstractMaemoInstallPackageToSysrootStep::handleInstallerStdout()
{
    if (m_installerProcess)
        emit addOutput(QString::fromLocal8Bit(m_installerProcess->readAllStandardOutput()), NormalOutput);
}

void AbstractMaemoInstallPackageToSysrootStep::handleInstallerStderr()
{
    if (m_installerProcess)
        emit addOutput(QString::fromLocal8Bit(m_installerProcess->readAllStandardError()), ErrorOutput);
}


MaemoInstallDebianPackageToSysrootStep::MaemoInstallDebianPackageToSysrootStep(BuildStepList *bsl)
    : AbstractMaemoInstallPackageToSysrootStep(bsl, Id)
{
Friedemann Kleint's avatar
Friedemann Kleint committed
235
    setDisplayName(displayName());
236
237
238
239
240
241
}

MaemoInstallDebianPackageToSysrootStep::MaemoInstallDebianPackageToSysrootStep(BuildStepList *bsl,
    MaemoInstallDebianPackageToSysrootStep *other)
        : AbstractMaemoInstallPackageToSysrootStep(bsl, other)
{
Friedemann Kleint's avatar
Friedemann Kleint committed
242
    setDisplayName(displayName());
243
244
245
246
247
248
249
250
251
}

BuildStepConfigWidget *MaemoInstallDebianPackageToSysrootStep::createConfigWidget()
{
    return new MaemoInstallDebianPackageToSysrootWidget(this);
}

QStringList MaemoInstallDebianPackageToSysrootStep::madArguments() const
{
252
253
254
255
256
257
    QStringList args;
    args << QLatin1String("xdpkg");
    if (qobject_cast<Qt4HarmattanTarget *>(target()))
        args << QLatin1String("--no-force-downgrade");
    args << QLatin1String("-i");
    return args;
258
259
260
261
}

const QString MaemoInstallDebianPackageToSysrootStep::Id
    = QLatin1String("MaemoInstallDebianPackageToSysrootStep");
Friedemann Kleint's avatar
Friedemann Kleint committed
262
263
264
265
266

QString MaemoInstallDebianPackageToSysrootStep::displayName()
{
    return tr("Install Debian package to sysroot");
}
267
268
269
270

MaemoInstallRpmPackageToSysrootStep::MaemoInstallRpmPackageToSysrootStep(BuildStepList *bsl)
    : AbstractMaemoInstallPackageToSysrootStep(bsl, Id)
{
Friedemann Kleint's avatar
Friedemann Kleint committed
271
    setDisplayName(displayName());
272
273
274
275
276
277
}

MaemoInstallRpmPackageToSysrootStep::MaemoInstallRpmPackageToSysrootStep(BuildStepList *bsl,
    MaemoInstallRpmPackageToSysrootStep *other)
        : AbstractMaemoInstallPackageToSysrootStep(bsl, other)
{
Friedemann Kleint's avatar
Friedemann Kleint committed
278
    setDisplayName(displayName());
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
}

BuildStepConfigWidget *MaemoInstallRpmPackageToSysrootStep::createConfigWidget()
{
    return new MaemoInstallRpmPackageToSysrootWidget(this);
}

QStringList MaemoInstallRpmPackageToSysrootStep::madArguments() const
{
    return QStringList() << QLatin1String("xrpm") << QLatin1String("-i");
}

const QString MaemoInstallRpmPackageToSysrootStep::Id
    = QLatin1String("MaemoInstallRpmPackageToSysrootStep");

Friedemann Kleint's avatar
Friedemann Kleint committed
294
295
296
297
QString MaemoInstallRpmPackageToSysrootStep::displayName()
{
    return tr("Install RPM package to sysroot");
}
298
299
300
301

MaemoCopyToSysrootStep::MaemoCopyToSysrootStep(BuildStepList *bsl)
    : BuildStep(bsl, Id)
{
Friedemann Kleint's avatar
Friedemann Kleint committed
302
    setDisplayName(displayName());
303
304
305
306
307
308
}

MaemoCopyToSysrootStep::MaemoCopyToSysrootStep(BuildStepList *bsl,
    MaemoCopyToSysrootStep *other)
        : BuildStep(bsl, other)
{
Friedemann Kleint's avatar
Friedemann Kleint committed
309
    setDisplayName(displayName());
310
311
}

312
bool MaemoCopyToSysrootStep::init()
313
314
{
    const Qt4BuildConfiguration * const bc
315
        = qobject_cast<Qt4BaseTarget *>(target())->activeQt4BuildConfiguration();
316
    if (!bc) {
317
        addOutput(tr("Cannot copy to sysroot without build configuration."),
318
            ErrorMessageOutput);
319
        return false;
320
321
    }

322
323
    const MaemoQtVersion * const qtVersion = dynamic_cast<MaemoQtVersion *>(bc->qtVersion());
    if (!qtVersion) {
324
        addOutput(tr("Cannot copy to sysroot without valid Qt version."),
325
            ErrorMessageOutput);
326
        return false;
327
    }
328
329
330
    m_systemRoot = qtVersion->systemRoot();
    return true;
}
331

332
333
void MaemoCopyToSysrootStep::run(QFutureInterface<bool> &fi)
{
334
    emit addOutput(tr("Copying files to sysroot ..."), MessageOutput);
335
    QDir sysrootDir(m_systemRoot);
336
    const QSharedPointer<DeploymentInfo> deploymentInfo
337
        = qobject_cast<RemoteLinuxDeployConfiguration *>(deployConfiguration())->deploymentInfo();
338
    const QChar sep = QLatin1Char('/');
339
340
    for (int i = 0; i < deploymentInfo->deployableCount(); ++i) {
        const DeployableFile &deployable = deploymentInfo->deployableAt(i);
341
        const QFileInfo localFileInfo(deployable.localFilePath);
342
        const QString targetFilePath = m_systemRoot + sep
343
            + deployable.remoteDir + sep + localFileInfo.fileName();
344
        sysrootDir.mkpath(deployable.remoteDir.mid(1));
345
        QString errorMsg;
346
347
        Utils::FileUtils::removeRecursively(targetFilePath, &errorMsg);
        if (!Utils::FileUtils::copyRecursively(deployable.localFilePath,
348
                targetFilePath, &errorMsg)) {
349
            emit addOutput(tr("Sysroot installation failed: %1\n"
350
                " Continuing anyway.").arg(errorMsg), ErrorMessageOutput);
351
352
353
354
355
356
357
358
359
360
361
362
        }
        QCoreApplication::processEvents();
        if (fi.isCanceled()) {
            fi.reportResult(false);
            return;
        }
    }
    fi.reportResult(true);
}

BuildStepConfigWidget *MaemoCopyToSysrootStep::createConfigWidget()
{
363
    return new MaemoCopyFilesToSysrootWidget(this);
364
365
366
367
}

const QString MaemoCopyToSysrootStep::Id
    = QLatin1String("MaemoCopyToSysrootStep");
Friedemann Kleint's avatar
Friedemann Kleint committed
368
369
370
371
QString MaemoCopyToSysrootStep::displayName()
{
    return tr("Copy files to sysroot");
}
372
373
374
375

MaemoMakeInstallToSysrootStep::MaemoMakeInstallToSysrootStep(BuildStepList *bsl)
    : AbstractProcessStep(bsl, Id)
{
Friedemann Kleint's avatar
Friedemann Kleint committed
376
    setDefaultDisplayName(displayName());
377
378
379
380
381
382
}

MaemoMakeInstallToSysrootStep::MaemoMakeInstallToSysrootStep(BuildStepList *bsl,
        MaemoMakeInstallToSysrootStep *other)
    : AbstractProcessStep(bsl, other)
{
Friedemann Kleint's avatar
Friedemann Kleint committed
383
    setDefaultDisplayName(displayName());
384
385
386
387
388
389
390
}

bool MaemoMakeInstallToSysrootStep::init()
{
    const Qt4BuildConfiguration * const bc
        = qobject_cast<Qt4BuildConfiguration *>(target()->activeBuildConfiguration());
    if (!bc) {
391
        addOutput("Cannot deploy: No active build dconfiguration.",
392
393
394
            ErrorMessageOutput);
        return false;
    }
395
    const QtSupport::BaseQtVersion * const qtVersion = bc->qtVersion();
396
    if (!qtVersion) {
397
        addOutput("Cannot deploy: Unusable build configuration.",
398
399
400
401
            ErrorMessageOutput);
        return false;

    }
402
403
404
405
    Utils::Environment env = bc->environment();
    MaemoGlobal::addMaddeEnvironment(env, qtVersion->qmakeCommand());
    QString command = MaemoGlobal::madCommand(qtVersion->qmakeCommand());
    QStringList args = QStringList() << QLatin1String("-t")
dt's avatar
dt committed
406
        << MaemoGlobal::targetName(qtVersion->qmakeCommand()) << QLatin1String("make")
407
408
409
        << QLatin1String("install") << (QLatin1String("INSTALL_ROOT=") + qtVersion->systemRoot());
    MaemoGlobal::transformMaddeCall(command, args, qtVersion->qmakeCommand());
    processParameters()->setCommand(command);
410
    processParameters()->setArguments(args.join(QLatin1String(" ")));
411
    processParameters()->setEnvironment(env);
412
413
414
415
416
417
    processParameters()->setWorkingDirectory(bc->buildDirectory());
    return true;
}

BuildStepConfigWidget *MaemoMakeInstallToSysrootStep::createConfigWidget()
{
418
    return new MaemoCopyFilesToSysrootWidget(this);
419
420
421
422
}

const QString MaemoMakeInstallToSysrootStep::Id
    = QLatin1String("MaemoMakeInstallToSysrootStep");
Friedemann Kleint's avatar
Friedemann Kleint committed
423
424
425
426
QString MaemoMakeInstallToSysrootStep::displayName()
{
    return tr("Copy files to sysroot");
}
427

428
} // namespace Internal
429
} // namespace Madde
430
431

#include "maemoinstalltosysrootstep.moc"