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).
**
7
** Contact: Nokia Corporation (qt-info@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
29
** Nokia at qt-info@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
#include <remotelinux/deploymentinfo.h>
#include <remotelinux/remotelinuxdeployconfiguration.h>
47

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

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

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

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

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

private:
87
88
89
90
91
92
93
94
    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);
    }

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


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

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

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

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

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


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

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

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

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

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

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

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

void AbstractMaemoInstallPackageToSysrootStep::run(QFutureInterface<bool> &fi)
{
189
190
191
192
193
194
195
    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);
196
197
198
    const int packageFileSize = QFileInfo(m_packageFilePath).size() / (1024*1024);
    const QStringList args = madArguments() << m_packageFilePath;
    MaemoGlobal::callMadAdmin(*m_installerProcess, args, m_qmakeCommand, true);
199
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
    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
234
    setDisplayName(displayName());
235
236
237
238
239
240
}

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

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

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

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

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

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

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

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
293
294
295
296
QString MaemoInstallRpmPackageToSysrootStep::displayName()
{
    return tr("Install RPM package to sysroot");
}
297
298
299
300

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

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

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

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

    const QSharedPointer<DeploymentInfo> deploymentInfo
            = static_cast<RemoteLinuxDeployConfiguration *>(deployConfiguration())->deploymentInfo();
    m_files.clear();
    for (int i = 0; i < deploymentInfo->deployableCount(); ++i)
        m_files << deploymentInfo->deployableAt(i);

335
336
    return true;
}
337

338
339
void MaemoCopyToSysrootStep::run(QFutureInterface<bool> &fi)
{
340
    emit addOutput(tr("Copying files to sysroot ..."), MessageOutput);
341
    QDir sysrootDir(m_systemRoot);
342

343
    const QChar sep = QLatin1Char('/');
344
    foreach (const DeployableFile &deployable, m_files) {
345
        const QFileInfo localFileInfo(deployable.localFilePath);
346
        const QString targetFilePath = m_systemRoot + sep
347
            + deployable.remoteDir + sep + localFileInfo.fileName();
348
        sysrootDir.mkpath(deployable.remoteDir.mid(1));
349
        QString errorMsg;
350
351
        Utils::FileUtils::removeRecursively(targetFilePath, &errorMsg);
        if (!Utils::FileUtils::copyRecursively(deployable.localFilePath,
352
                targetFilePath, &errorMsg)) {
353
            emit addOutput(tr("Sysroot installation failed: %1\n"
354
                " Continuing anyway.").arg(errorMsg), ErrorMessageOutput);
355
356
357
358
359
360
361
362
363
364
365
        }
        if (fi.isCanceled()) {
            fi.reportResult(false);
            return;
        }
    }
    fi.reportResult(true);
}

BuildStepConfigWidget *MaemoCopyToSysrootStep::createConfigWidget()
{
366
    return new MaemoCopyFilesToSysrootWidget(this);
367
368
369
370
}

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

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

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

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

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

BuildStepConfigWidget *MaemoMakeInstallToSysrootStep::createConfigWidget()
{
421
    return new MaemoCopyFilesToSysrootWidget(this);
422
423
424
425
}

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

431
} // namespace Internal
432
} // namespace Madde
433
434

#include "maemoinstalltosysrootstep.moc"