symbianqtversion.cpp 13.6 KB
Newer Older
dt's avatar
dt committed
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** 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.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/

#include "qt4projectmanagerconstants.h"
#include "symbianqtversion.h"
#include "qt-s60/sbsv2parser.h"
#include "qt-s60/abldparser.h"
#include "profileevaluator.h"

#include <projectexplorer/gnumakeparser.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/toolchain.h>
#include <projectexplorer/toolchainmanager.h>
#include <utils/pathchooser.h>

#include <QtCore/QCoreApplication>
#include <QtCore/QDir>
#include <QtGui/QLabel>
#include <QtGui/QFormLayout>

using namespace Qt4ProjectManager;
using namespace Qt4ProjectManager::Internal;

SymbianQtVersion::SymbianQtVersion()
    : BaseQtVersion(),
      m_validSystemRoot(false)
{
}

SymbianQtVersion::SymbianQtVersion(const QString &path, bool isAutodetected, const QString &autodetectionSource)
    : BaseQtVersion(path, isAutodetected, autodetectionSource),
      m_validSystemRoot(false)
{

}

SymbianQtVersion::~SymbianQtVersion()
{

}

SymbianQtVersion *SymbianQtVersion::clone() const
{
    return new SymbianQtVersion(*this);
}

bool SymbianQtVersion::equals(BaseQtVersion *other)
{
    if (!BaseQtVersion::equals(other))
        return false;
    SymbianQtVersion *o = static_cast<SymbianQtVersion *>(other);
    return m_sbsV2Directory == o->m_sbsV2Directory
            && m_systemRoot == o->m_systemRoot;
}

QString SymbianQtVersion::type() const
{
    return QLatin1String(Constants::SYMBIANQT);
}

bool SymbianQtVersion::isValid() const
{
    if (!BaseQtVersion::isValid())
        return false;
    if (!m_validSystemRoot)
        return false;
dt's avatar
dt committed
96
    if (isBuildWithSymbianSbsV2() && (m_sbsV2Directory.isEmpty() || !QFileInfo(m_sbsV2Directory + QLatin1String("/sbs")).exists()))
dt's avatar
dt committed
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
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
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
379
380
381
382
383
384
385
386
387
388
389
390
        return false;
    return true;
}

QString SymbianQtVersion::invalidReason() const
{
    QString tmp = BaseQtVersion::invalidReason();
    if (tmp.isEmpty() && !m_validSystemRoot)
        return QCoreApplication::translate("QtVersion", "The \"Open C/C++ plugin\" is not installed in the Symbian SDK or the Symbian SDK path is misconfigured");
    if (isBuildWithSymbianSbsV2()
            && (m_sbsV2Directory.isEmpty() || !QFileInfo(m_sbsV2Directory + QLatin1String("/sbs")).exists()))
        return QCoreApplication::translate("QtVersion", "SBS was not found.");

    return QString();
}

bool SymbianQtVersion::toolChainAvailable(const QString &id) const
{
    if (!isValid())
        return false;
    if (id == QLatin1String(Constants::S60_EMULATOR_TARGET_ID)) {
        QList<ProjectExplorer::ToolChain *> tcList =
                ProjectExplorer::ToolChainManager::instance()->toolChains();
        foreach (ProjectExplorer::ToolChain *tc, tcList) {
            if (tc->id().startsWith(QLatin1String(Constants::WINSCW_TOOLCHAIN_ID)))
                return true;
        }
        return false;
    } else if (id == QLatin1String(Constants::S60_DEVICE_TARGET_ID)) {
        QList<ProjectExplorer::ToolChain *> tcList =
                ProjectExplorer::ToolChainManager::instance()->toolChains();
        foreach (ProjectExplorer::ToolChain *tc, tcList) {
            if (!tc->id().startsWith(Qt4ProjectManager::Constants::WINSCW_TOOLCHAIN_ID))
                return true;
        }
        return false;
    }
    return false;
}

void SymbianQtVersion::fromMap(const QVariantMap &map)
{
    BaseQtVersion::fromMap(map);
    setSbsV2Directory(map.value(QLatin1String("SBSv2Directory")).toString());
    setSystemRoot(map.value(QLatin1String("SystemRoot")).toString());
}

QVariantMap SymbianQtVersion::toMap() const
{
    QVariantMap result = BaseQtVersion::toMap();
    result.insert(QLatin1String("SBSv2Directory"), sbsV2Directory());
    result.insert(QLatin1String("SystemRoot"), systemRoot());
    return result;
}

QList<ProjectExplorer::Abi> SymbianQtVersion::qtAbis() const
{
    return QList<ProjectExplorer::Abi>()
            << ProjectExplorer::Abi(ProjectExplorer::Abi::ArmArchitecture, ProjectExplorer::Abi::SymbianOS,
                                    ProjectExplorer::Abi::UnknownFlavor,
                                    ProjectExplorer::Abi::ElfFormat,
                                    32);
}

bool SymbianQtVersion::supportsTargetId(const QString &id) const
{
    return supportedTargetIds().contains(id);
}

QSet<QString> SymbianQtVersion::supportedTargetIds() const
{
    return QSet<QString>() << QLatin1String(Constants::S60_DEVICE_TARGET_ID)
                              << QLatin1String(Constants::S60_EMULATOR_TARGET_ID);
}

QString SymbianQtVersion::description() const
{
    return QCoreApplication::translate("QtVersion", "Symbian", "Qt Version is meant for Symbian");
}


bool SymbianQtVersion::supportsShadowBuilds() const
{
    return false;
}

bool SymbianQtVersion::supportsBinaryDebuggingHelper() const
{
    return false;
}

static const char *S60_EPOC_HEADERS[] = {
    "include", "mkspecs/common/symbian", "epoc32/include",
    "epoc32/include/osextensions/stdapis", "epoc32/include/osextensions/stdapis/sys",
    "epoc32/include/stdapis", "epoc32/include/stdapis/sys",
    "epoc32/include/osextensions/stdapis/stlport", "epoc32/include/stdapis/stlport",
    "epoc32/include/oem", "epoc32/include/middleware", "epoc32/include/domain/middleware",
    "epoc32/include/osextensions", "epoc32/include/domain/osextensions",
    "epoc32/include/domain/osextensions/loc", "epoc32/include/domain/middleware/loc",
    "epoc32/include/domain/osextensions/loc/sc", "epoc32/include/domain/middleware/loc/sc"
};

void SymbianQtVersion::addToEnvironment(Utils::Environment &env) const
{
    BaseQtVersion::addToEnvironment(env);
    // Generic Symbian environment:
    QString epocRootPath = systemRoot();
    QDir epocDir(epocRootPath);

    // Clean up epoc root path for the environment:
    if (!epocRootPath.endsWith(QLatin1Char('/')))
        epocRootPath.append(QLatin1Char('/'));
    if (!isBuildWithSymbianSbsV2()) {
#ifdef Q_OS_WIN
        if (epocRootPath.count() > 2
                && epocRootPath.at(0).toLower() >= QLatin1Char('a')
                && epocRootPath.at(0).toLower() <= QLatin1Char('z')
                && epocRootPath.at(1) == QLatin1Char(':')) {
            epocRootPath = epocRootPath.mid(2);
        }
#endif
    }
    env.set(QLatin1String("EPOCROOT"), QDir::toNativeSeparators(epocRootPath));

    env.prependOrSetPath(epocDir.filePath(QLatin1String("epoc32/tools"))); // e.g. make.exe
    // Windows only:
    if (ProjectExplorer::Abi::hostAbi().os() == ProjectExplorer::Abi::WindowsOS) {
        QString winDir = QLatin1String(qgetenv("WINDIR"));
        if (!winDir.isEmpty())
            env.prependOrSetPath(QDir(winDir).filePath(QLatin1String("system32")));

        if (epocDir.exists(QLatin1String("epoc32/gcc/bin")))
            env.prependOrSetPath(epocDir.filePath(QLatin1String("epoc32/gcc/bin"))); // e.g. cpp.exe, *NOT* gcc.exe
        // Find perl in the special Symbian flavour:
        if (epocDir.exists(QLatin1String("../../tools/perl/bin"))) {
            epocDir.cd(QLatin1String("../../tools/perl/bin"));
            env.prependOrSetPath(epocDir.absolutePath());
        } else {
            env.prependOrSetPath(epocDir.filePath(QLatin1String("perl/bin")));
        }
    }

    // SBSv2:
    if (isBuildWithSymbianSbsV2()) {
        QString sbsHome(env.value(QLatin1String("SBS_HOME")));
        QString sbsConfig = sbsV2Directory();
        if (!sbsConfig.isEmpty()) {
            env.prependOrSetPath(sbsConfig);
            // SBS_HOME is the path minus the trailing /bin:
            env.set(QLatin1String("SBS_HOME"),
                    QDir::toNativeSeparators(sbsConfig.left(sbsConfig.count() - 4))); // We need this for Qt 4.6.3 compatibility
        } else if (!sbsHome.isEmpty()) {
            env.prependOrSetPath(sbsHome + QLatin1String("/bin"));
        }
    }
}

QList<ProjectExplorer::HeaderPath> SymbianQtVersion::systemHeaderPathes() const
{
    QList<ProjectExplorer::HeaderPath> result;
    QString root = systemRoot() + QLatin1Char('/');
    const int count = sizeof(S60_EPOC_HEADERS) / sizeof(const char *);
    for (int i = 0; i < count; ++i) {
        const QDir dir(root + QLatin1String(S60_EPOC_HEADERS[i]));
        if (dir.exists())
            result.append(ProjectExplorer::HeaderPath(dir.absolutePath(),
                                                      ProjectExplorer::HeaderPath::GlobalHeaderPath));
    }
    result.append(BaseQtVersion::systemHeaderPathes());
    return result;
}

ProjectExplorer::IOutputParser *SymbianQtVersion::createOutputParser() const
{
    if (isBuildWithSymbianSbsV2()) {
        return new SbsV2Parser;
    } else {
        ProjectExplorer::IOutputParser *parser = new AbldParser;
        parser->appendOutputParser(new ProjectExplorer::GnuMakeParser);
        return parser;
    }
}

QString SymbianQtVersion::sbsV2Directory() const
{
    return m_sbsV2Directory;
}

void SymbianQtVersion::setSbsV2Directory(const QString &directory)
{
    QDir dir(directory);
    if (dir.exists(QLatin1String("sbs"))) {
        m_sbsV2Directory = dir.absolutePath();
        return;
    }
    dir.cd("bin");
    if (dir.exists(QLatin1String("sbs"))) {
        m_sbsV2Directory = dir.absolutePath();
        return;
    }
    m_sbsV2Directory = directory;
}

bool SymbianQtVersion::isBuildWithSymbianSbsV2() const
{
    ensureMkSpecParsed();
    return m_isBuildUsingSbsV2;
}

void SymbianQtVersion::parseMkSpec(ProFileEvaluator *evaluator) const
{
    QString makefileGenerator = evaluator->value("MAKEFILE_GENERATOR");
    m_isBuildUsingSbsV2 = (makefileGenerator == QLatin1String("SYMBIAN_SBSV2"));
    BaseQtVersion::parseMkSpec(evaluator);
}

QList<ProjectExplorer::Task> SymbianQtVersion::reportIssuesImpl(const QString &proFile, const QString &buildDir)
{
    QList<ProjectExplorer::Task> results = BaseQtVersion::reportIssuesImpl(proFile, buildDir);
    const QString epocRootDir = systemRoot();
    // Report an error if project- and epoc directory are on different drives:
    if (!epocRootDir.startsWith(proFile.left(3), Qt::CaseInsensitive) && !isBuildWithSymbianSbsV2()) {
        results.append(ProjectExplorer::Task(ProjectExplorer::Task::Error,
                                             QCoreApplication::translate("ProjectExplorer::Internal::S60ProjectChecker",
                                                                         "The Symbian SDK and the project sources must reside on the same drive."),
                                             QString(), -1, ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
    }
    return results;
}

void SymbianQtVersion::setSystemRoot(const QString &root)
{
    if (root == m_systemRoot)
        return;
    m_systemRoot = root;

    m_validSystemRoot = false;
    if (!m_systemRoot.isEmpty()) {
        if (!m_systemRoot.endsWith(QLatin1Char('/')))
            m_systemRoot.append(QLatin1Char('/'));
        QFileInfo cppheader(m_systemRoot + QLatin1String("epoc32/include/stdapis/string.h"));
        m_validSystemRoot = cppheader.exists();
    }
}

QString SymbianQtVersion::systemRoot() const
{
    return m_systemRoot;
}

QtConfigWidget *SymbianQtVersion::createConfigurationWidget() const
{
    return new SymbianQtConfigWidget(const_cast<SymbianQtVersion *>(this));
}

SymbianQtConfigWidget::SymbianQtConfigWidget(SymbianQtVersion *version)
    : m_version(version)
{
    QFormLayout *fl = new QFormLayout();
    fl->setMargin(0);
    setLayout(fl);

    Utils::PathChooser *s60sdkPath = new Utils::PathChooser;
    s60sdkPath->setExpectedKind(Utils::PathChooser::ExistingDirectory);

    fl->addRow(tr("S60 SDK:"), s60sdkPath);

    s60sdkPath->setPath(QDir::toNativeSeparators(version->systemRoot()));

    connect(s60sdkPath, SIGNAL(changed(QString)),
            this, SLOT(updateCurrentS60SDKDirectory(QString)));

    if (version->isBuildWithSymbianSbsV2()) {
        Utils::PathChooser *sbsV2Path = new Utils::PathChooser;
        sbsV2Path->setExpectedKind(Utils::PathChooser::ExistingDirectory);
        fl->addRow(tr("SBS v2 directory:"), sbsV2Path);
        sbsV2Path->setPath(QDir::toNativeSeparators(version->sbsV2Directory()));
        sbsV2Path->setEnabled(version->isBuildWithSymbianSbsV2());
        connect(sbsV2Path, SIGNAL(changed(QString)),
                this, SLOT(updateCurrentSbsV2Directory(QString)));
    }
}

void SymbianQtConfigWidget::updateCurrentS60SDKDirectory(const QString &path)
{
    m_version->setSystemRoot(QDir::fromNativeSeparators(path));
    emit changed();
}

void SymbianQtConfigWidget::updateCurrentSbsV2Directory(const QString &path)
{
    m_version->setSbsV2Directory(QDir::fromNativeSeparators(path));
    emit changed();
}