s60createpackagestep.cpp 17.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

#include "s60createpackagestep.h"

#include "qt4projectmanagerconstants.h"
#include "qt4buildconfiguration.h"
dt's avatar
dt committed
34
35
#include "qt4nodes.h"
#include "qt4project.h"
36
#include "abldparser.h"
37
38
39

#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/target.h>
dt's avatar
dt committed
40
#include <projectexplorer/project.h>
41
#include <projectexplorer/gnumakeparser.h>
dt's avatar
dt committed
42
#include <projectexplorer/task.h>
43

44
#include <QtCore/QDir>
dt's avatar
dt committed
45
#include <QtCore/QTimer>
46

47
48
49
50
51
52
53
using namespace Qt4ProjectManager::Internal;

namespace {
    const char * const SIGN_BS_ID = "Qt4ProjectManager.S60SignBuildStep";
    const char * const SIGNMODE_KEY("Qt4ProjectManager.S60CreatePackageStep.SignMode");
    const char * const CERTIFICATE_KEY("Qt4ProjectManager.S60CreatePackageStep.Certificate");
    const char * const KEYFILE_KEY("Qt4ProjectManager.S60CreatePackageStep.Keyfile");
con's avatar
con committed
54
    const char * const SMART_INSTALLER_KEY("Qt4ProjectManager.S60CreatorPackageStep.SmartInstaller");
55
56
57
}

S60CreatePackageStep::S60CreatePackageStep(ProjectExplorer::BuildConfiguration *bc) :
dt's avatar
dt committed
58
    BuildStep(bc, QLatin1String(SIGN_BS_ID)),
con's avatar
con committed
59
    m_signingMode(SignSelf),
dt's avatar
dt committed
60
61
62
63
64
65
    m_createSmartInstaller(false),
    m_outputParserChain(0),
    m_process(0),
    m_timer(0),
    m_eventLoop(0),
    m_futureInterface(0)
66
67
68
69
70
{
    ctor_package();
}

S60CreatePackageStep::S60CreatePackageStep(ProjectExplorer::BuildConfiguration *bc, S60CreatePackageStep *bs) :
dt's avatar
dt committed
71
    BuildStep(bc, bs),
72
73
    m_signingMode(bs->m_signingMode),
    m_customSignaturePath(bs->m_customSignaturePath),
con's avatar
con committed
74
    m_customKeyPath(bs->m_customKeyPath),
dt's avatar
dt committed
75
76
77
78
79
    m_createSmartInstaller(bs->m_createSmartInstaller),
    m_outputParserChain(0),
    m_timer(0),
    m_eventLoop(0),
    m_futureInterface(0)
80
81
82
83
84
{
    ctor_package();
}

S60CreatePackageStep::S60CreatePackageStep(ProjectExplorer::BuildConfiguration *bc, const QString &id) :
dt's avatar
dt committed
85
    BuildStep(bc, id),
con's avatar
con committed
86
    m_signingMode(SignSelf),
dt's avatar
dt committed
87
88
89
90
91
    m_createSmartInstaller(false),
    m_outputParserChain(0),
    m_timer(0),
    m_eventLoop(0),
    m_futureInterface(0)
92
93
94
95
96
97
{
    ctor_package();
}

void S60CreatePackageStep::ctor_package()
{
98
    setDisplayName(tr("Create SIS Package", "Create SIS package build step name"));
99
100
101
102
103
104
105
106
}

S60CreatePackageStep::~S60CreatePackageStep()
{
}

QVariantMap S60CreatePackageStep::toMap() const
{
dt's avatar
dt committed
107
    QVariantMap map(BuildStep::toMap());
108
109
110
    map.insert(QLatin1String(SIGNMODE_KEY), (int)m_signingMode);
    map.insert(QLatin1String(CERTIFICATE_KEY), m_customSignaturePath);
    map.insert(QLatin1String(KEYFILE_KEY), m_customKeyPath);
con's avatar
con committed
111
    map.insert(QLatin1String(SMART_INSTALLER_KEY), m_createSmartInstaller);
112
113
114
115
116
117
118
119
    return map;
}

bool S60CreatePackageStep::fromMap(const QVariantMap &map)
{
    m_signingMode = (SigningMode)map.value(QLatin1String(SIGNMODE_KEY)).toInt();
    m_customSignaturePath = map.value(QLatin1String(CERTIFICATE_KEY)).toString();
    m_customKeyPath = map.value(QLatin1String(KEYFILE_KEY)).toString();
con's avatar
con committed
120
    m_createSmartInstaller = map.value(QLatin1String(SMART_INSTALLER_KEY), false).toBool();
dt's avatar
dt committed
121
122
123
124
125
126
    return BuildStep::fromMap(map);
}

Qt4BuildConfiguration *S60CreatePackageStep::qt4BuildConfiguration() const
{
    return static_cast<Qt4BuildConfiguration *>(buildConfiguration());
127
128
129
130
}

bool S60CreatePackageStep::init()
{
dt's avatar
dt committed
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
    Qt4Project *pro = qobject_cast<Qt4Project *>(buildConfiguration()->target()->project());

    QList<Qt4ProFileNode *> nodes = pro->leafProFiles();

    m_workingDirectories.clear();
    foreach (Qt4ProFileNode *node, nodes)
        m_workingDirectories << node->buildDir();

    m_makeCmd = qt4BuildConfiguration()->makeCommand();
    if (!QFileInfo(m_makeCmd).isAbsolute()) {
        // Try to detect command in environment
        const QString tmp = buildConfiguration()->environment().searchInPath(m_makeCmd);
        if (tmp.isEmpty()) {
            emit addOutput(tr("Could not find make command: %1 in the build environment").arg(m_makeCmd), BuildStep::ErrorOutput);
            return false;
        }
        m_makeCmd = tmp;
    }

    m_environment = qt4BuildConfiguration()->environment();

    m_args.clear();
con's avatar
con committed
153
    if (m_createSmartInstaller)
dt's avatar
dt committed
154
        m_args << QLatin1String("installer_sis");
con's avatar
con committed
155
    else
dt's avatar
dt committed
156
        m_args << QLatin1String("sis");
157
    if (signingMode() == SignCustom) {
dt's avatar
dt committed
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
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
234
235
236
237
238
239
240
241
242
        m_args << QLatin1String("QT_SIS_CERTIFICATE=") + QDir::toNativeSeparators(customSignaturePath())
               << QLatin1String("QT_SIS_KEY=") + QDir::toNativeSeparators(customKeyPath());
    }

    delete m_outputParserChain;
    m_outputParserChain = new ProjectExplorer::GnuMakeParser;
    m_outputParserChain->appendOutputParser(new Qt4ProjectManager::AbldParser);
    connect(m_outputParserChain, SIGNAL(addOutput(QString, ProjectExplorer::BuildStep::OutputFormat)),
            this, SLOT(outputAdded(QString, ProjectExplorer::BuildStep::OutputFormat)));
    connect(m_outputParserChain, SIGNAL(addTask(ProjectExplorer::Task)),
            this, SLOT(taskAdded(ProjectExplorer::Task)));

    return true;
}

void S60CreatePackageStep::run(QFutureInterface<bool> &fi)
{
    m_futureInterface = &fi;

    if (m_workingDirectories.isEmpty()) {
        fi.reportResult(true);
        return;
    }

    // Setup everything...
    m_process = new QProcess();
    m_process->setEnvironment(m_environment.toStringList());

    connect(m_process, SIGNAL(readyReadStandardOutput()),
            this, SLOT(processReadyReadStdOutput()),
            Qt::DirectConnection);
    connect(m_process, SIGNAL(readyReadStandardError()),
            this, SLOT(processReadyReadStdError()),
            Qt::DirectConnection);

    connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)),
            this, SLOT(slotProcessFinished(int, QProcess::ExitStatus)),
            Qt::DirectConnection);

    m_timer = new QTimer();
    connect(m_timer, SIGNAL(timeout()), this, SLOT(checkForCancel()), Qt::DirectConnection);
    m_timer->start(500);
    m_eventLoop = new QEventLoop;

    bool returnValue = false;
    if (startProcess())
        returnValue = m_eventLoop->exec();

    // Finished
    m_timer->stop();
    delete m_timer;
    m_timer = 0;

    delete m_process;
    m_process = 0;
    delete m_eventLoop;
    m_eventLoop = 0;
    fi.reportResult(returnValue);
    m_futureInterface = 0;

    return;
}

void S60CreatePackageStep::slotProcessFinished(int, QProcess::ExitStatus)
{
    QString line = QString::fromLocal8Bit(m_process->readAllStandardError());
    if (!line.isEmpty())
        stdError(line);

    line = QString::fromLocal8Bit(m_process->readAllStandardOutput());
    if (!line.isEmpty())
        stdOutput(line);

    bool returnValue = false;
    if (m_process->exitStatus() == QProcess::NormalExit && m_process->exitCode() == 0) {
        emit addOutput(tr("The process \"%1\" exited normally.")
                       .arg(QDir::toNativeSeparators(m_makeCmd)),
                       BuildStep::MessageOutput);
        returnValue = true;
    } else if (m_process->exitStatus() == QProcess::NormalExit) {
        emit addOutput(tr("The process \"%1\" exited with code %2.")
                       .arg(QDir::toNativeSeparators(m_makeCmd), QString::number(m_process->exitCode())),
                       BuildStep::ErrorMessageOutput);
    } else {
        emit addOutput(tr("The process \"%1\" crashed.").arg(QDir::toNativeSeparators(m_makeCmd)), BuildStep::ErrorMessageOutput);
243
    }
244

dt's avatar
dt committed
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
    if (m_workingDirectories.isEmpty() || !returnValue) {
        m_eventLoop->exit(returnValue);
    } else {
        // Success, do next
        if (!startProcess())
            m_eventLoop->exit(returnValue);
    }
}

bool S60CreatePackageStep::startProcess()
{
    QString workingDirectory = m_workingDirectories.takeFirst();
    QDir wd(workingDirectory);
    if (!wd.exists())
        wd.mkpath(wd.absolutePath());

    m_process->setWorkingDirectory(workingDirectory);
262

dt's avatar
dt committed
263
264
265
266
267
268
269
270
271
272
273
274
275
276
    // Go for it!
    m_process->start(m_makeCmd, m_args);
    if (!m_process->waitForStarted()) {
        emit addOutput(tr("Could not start process \"%1\" in %2")
                       .arg(QDir::toNativeSeparators(m_makeCmd),
                            workingDirectory),
                       BuildStep::ErrorMessageOutput);
        return false;
    }
    emit addOutput(tr("Starting: \"%1\" %2 in %3\n")
                   .arg(QDir::toNativeSeparators(m_makeCmd),
                        m_args.join(" "),
                        workingDirectory),
                   BuildStep::MessageOutput);
277
278
279
    return true;
}

dt's avatar
dt committed
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
void S60CreatePackageStep::processReadyReadStdOutput()
{
    m_process->setReadChannel(QProcess::StandardOutput);
    while (m_process->canReadLine()) {
        QString line = QString::fromLocal8Bit(m_process->readLine());
        stdOutput(line);
    }
}

void S60CreatePackageStep::stdOutput(const QString &line)
{
    if (m_outputParserChain)
        m_outputParserChain->stdOutput(line);
    emit addOutput(line, BuildStep::NormalOutput);
}

void S60CreatePackageStep::processReadyReadStdError()
{
    m_process->setReadChannel(QProcess::StandardError);
    while (m_process->canReadLine()) {
        QString line = QString::fromLocal8Bit(m_process->readLine());
        stdError(line);
    }
}

void S60CreatePackageStep::stdError(const QString &line)
{
    if (m_outputParserChain)
        m_outputParserChain->stdError(line);
    emit addOutput(line, BuildStep::ErrorOutput);
}

void S60CreatePackageStep::checkForCancel()
{
    if (m_futureInterface->isCanceled() && m_timer->isActive()) {
        m_timer->stop();
        m_process->terminate();
        m_process->waitForFinished(5000);
        m_process->kill();
    }
}

void S60CreatePackageStep::taskAdded(const ProjectExplorer::Task &task)
{
    ProjectExplorer::Task editable(task);
    QString filePath = QDir::cleanPath(task.file.trimmed());
    if (!filePath.isEmpty() && !QDir::isAbsolutePath(filePath)) {
        // TODO which kind of tasks do we get from package building?
        // No absoulte path
    }
    emit addTask(editable);
}

void S60CreatePackageStep::outputAdded(const QString &string, ProjectExplorer::BuildStep::OutputFormat format)
{
    emit addOutput(string, format);
}


339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
bool S60CreatePackageStep::immutable() const
{
    return false;
}

ProjectExplorer::BuildStepConfigWidget *S60CreatePackageStep::createConfigWidget()
{
    return new S60CreatePackageStepConfigWidget(this);
}

S60CreatePackageStep::SigningMode S60CreatePackageStep::signingMode() const
{
    return m_signingMode;
}

void S60CreatePackageStep::setSigningMode(SigningMode mode)
{
    m_signingMode = mode;
}

QString S60CreatePackageStep::customSignaturePath() const
{
    return m_customSignaturePath;
}

void S60CreatePackageStep::setCustomSignaturePath(const QString &path)
{
    m_customSignaturePath = path;
}

QString S60CreatePackageStep::customKeyPath() const
{
    return m_customKeyPath;
}

void S60CreatePackageStep::setCustomKeyPath(const QString &path)
{
    m_customKeyPath = path;
}

379
bool S60CreatePackageStep::createsSmartInstaller() const
con's avatar
con committed
380
381
382
383
{
    return m_createSmartInstaller;
}

384
void S60CreatePackageStep::setCreatesSmartInstaller(bool value)
con's avatar
con committed
385
386
{
    m_createSmartInstaller = value;
387
    static_cast<Qt4BuildConfiguration *>(buildConfiguration())->emitS60CreatesSmartInstallerChanged();
con's avatar
con committed
388
389
}

390
391
392
393
394
395
396
397
398
399
400
// #pragma mark -- S60SignBuildStepFactory

S60CreatePackageStepFactory::S60CreatePackageStepFactory(QObject *parent) :
    ProjectExplorer::IBuildStepFactory(parent)
{
}

S60CreatePackageStepFactory::~S60CreatePackageStepFactory()
{
}

401
bool S60CreatePackageStepFactory::canCreate(ProjectExplorer::BuildConfiguration *parent, ProjectExplorer::BuildStep::Type type, const QString &id) const
402
{
Tobias Hunger's avatar
Tobias Hunger committed
403
    if (type != ProjectExplorer::BuildStep::Deploy)
404
405
406
407
408
409
        return false;
    if (parent->target()->id() != Constants::S60_DEVICE_TARGET_ID)
        return false;
    return (id == QLatin1String(SIGN_BS_ID));
}

410
ProjectExplorer::BuildStep *S60CreatePackageStepFactory::create(ProjectExplorer::BuildConfiguration *parent, ProjectExplorer::BuildStep::Type type, const QString &id)
411
412
413
414
415
416
{
    if (!canCreate(parent, type, id))
        return 0;
    return new S60CreatePackageStep(parent);
}

417
bool S60CreatePackageStepFactory::canClone(ProjectExplorer::BuildConfiguration *parent, ProjectExplorer::BuildStep::Type type, ProjectExplorer::BuildStep *source) const
418
419
420
421
{
    return canCreate(parent, type, source->id());
}

422
ProjectExplorer::BuildStep *S60CreatePackageStepFactory::clone(ProjectExplorer::BuildConfiguration *parent, ProjectExplorer::BuildStep::Type type, ProjectExplorer::BuildStep *source)
423
424
425
426
427
428
{
    if (!canClone(parent, type, source))
        return 0;
    return new S60CreatePackageStep(parent, static_cast<S60CreatePackageStep *>(source));
}

429
bool S60CreatePackageStepFactory::canRestore(ProjectExplorer::BuildConfiguration *parent, ProjectExplorer::BuildStep::Type type, const QVariantMap &map) const
430
431
432
433
434
{
    QString id(ProjectExplorer::idFromMap(map));
    return canCreate(parent, type, id);
}

435
ProjectExplorer::BuildStep *S60CreatePackageStepFactory::restore(ProjectExplorer::BuildConfiguration *parent, ProjectExplorer::BuildStep::Type type, const QVariantMap &map)
436
437
438
439
440
441
442
443
444
445
{
    if (!canRestore(parent, type, map))
        return 0;
    S60CreatePackageStep *bs(new S60CreatePackageStep(parent));
    if (bs->fromMap(map))
        return bs;
    delete bs;
    return 0;
}

446
QStringList S60CreatePackageStepFactory::availableCreationIds(ProjectExplorer::BuildConfiguration *parent, ProjectExplorer::BuildStep::Type type) const
447
{
Tobias Hunger's avatar
Tobias Hunger committed
448
    if (type != ProjectExplorer::BuildStep::Deploy)
449
450
451
452
453
454
455
456
457
        return QStringList();
    if (parent->target()->id() == Constants::S60_DEVICE_TARGET_ID)
        return QStringList() << QLatin1String(SIGN_BS_ID);
    return QStringList();
}

QString S60CreatePackageStepFactory::displayNameForId(const QString &id) const
{
    if (id == QLatin1String(SIGN_BS_ID))
458
        return tr("Create SIS Package");
459
460
461
462
463
464
465
466
467
    return QString();
}

// #pragma mark -- S60SignBuildStepConfigWidget

S60CreatePackageStepConfigWidget::S60CreatePackageStepConfigWidget(S60CreatePackageStep *signStep)
    : BuildStepConfigWidget(), m_signStep(signStep)
{
    m_ui.setupUi(this);
468
469
    m_ui.signaturePath->setExpectedKind(Utils::PathChooser::File);
    m_ui.keyFilePath->setExpectedKind(Utils::PathChooser::File);
470
471
472
473
474
475
476
477
478
    updateUi();
    connect(m_ui.customCertificateButton, SIGNAL(clicked()),
            this, SLOT(updateFromUi()));
    connect(m_ui.selfSignedButton, SIGNAL(clicked()),
            this, SLOT(updateFromUi()));
    connect(m_ui.signaturePath, SIGNAL(changed(QString)),
            this, SLOT(updateFromUi()));
    connect(m_ui.keyFilePath, SIGNAL(changed(QString)),
            this, SLOT(updateFromUi()));
con's avatar
con committed
479
480
    connect(m_ui.smartInstaller, SIGNAL(clicked()),
            this, SLOT(updateFromUi()));
481
482
483
484
485
486
487
488
489
490
491
}

void S60CreatePackageStepConfigWidget::updateUi()
{
    bool selfSigned = m_signStep->signingMode() == S60CreatePackageStep::SignSelf;
    m_ui.selfSignedButton->setChecked(selfSigned);
    m_ui.customCertificateButton->setChecked(!selfSigned);
    m_ui.signaturePath->setEnabled(!selfSigned);
    m_ui.keyFilePath->setEnabled(!selfSigned);
    m_ui.signaturePath->setPath(m_signStep->customSignaturePath());
    m_ui.keyFilePath->setPath(m_signStep->customKeyPath());
492
    m_ui.smartInstaller->setChecked(m_signStep->createsSmartInstaller());
493
494
495
496
497
498
499
500
501
502
    emit updateSummary();
}

void S60CreatePackageStepConfigWidget::updateFromUi()
{
    bool selfSigned = m_ui.selfSignedButton->isChecked();
    m_signStep->setSigningMode(selfSigned ? S60CreatePackageStep::SignSelf
        : S60CreatePackageStep::SignCustom);
    m_signStep->setCustomSignaturePath(m_ui.signaturePath->path());
    m_signStep->setCustomKeyPath(m_ui.keyFilePath->path());
503
    m_signStep->setCreatesSmartInstaller(m_ui.smartInstaller->isChecked());
504
505
506
507
508
509
510
511
512
513
514
515
516
    updateUi();
}

QString S60CreatePackageStepConfigWidget::summaryText() const
{
    QString text;
    if (m_signStep->signingMode() == S60CreatePackageStep::SignSelf) {
        text = tr("self-signed");
    } else {
        text = tr("signed with certificate %1 and key file %2")
               .arg(m_signStep->customSignaturePath())
               .arg(m_signStep->customKeyPath());
    }
517
    if (m_signStep->createsSmartInstaller())
con's avatar
con committed
518
        return tr("<b>Create SIS Package:</b> %1, using Smart Installer").arg(text);
519
    return tr("<b>Create SIS Package:</b> %1").arg(text);
520
521
522
523
524
525
526
527
528
529
}

QString S60CreatePackageStepConfigWidget::displayName() const
{
    return m_signStep->displayName();
}

void S60CreatePackageStepConfigWidget::init()
{
}