qbsproject.cpp 21.5 KB
Newer Older
Tobias Hunger's avatar
Tobias Hunger 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
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/

#include "qbsproject.h"

#include "qbsbuildconfiguration.h"
33
#include "qbslogsink.h"
Tobias Hunger's avatar
Tobias Hunger committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "qbsprojectfile.h"
#include "qbsprojectmanagerconstants.h"
#include "qbsnodes.h"

#include <coreplugin/documentmanager.h>
#include <utils/qtcassert.h>

#include <language/language.h>

#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
#include <coreplugin/id.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <coreplugin/mimedatabase.h>
#include <cpptools/cppmodelmanager.h>
#include <projectexplorer/buildenvironmentwidget.h>
#include <projectexplorer/kit.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/target.h>
#include <projectexplorer/taskhub.h>
56
#include <projectexplorer/toolchain.h>
57
#include <projectexplorer/headerpath.h>
Tobias Hunger's avatar
Tobias Hunger committed
58
#include <qtsupport/qtkitinformation.h>
Tobias Hunger's avatar
Tobias Hunger committed
59
#include <qtsupport/uicodemodelsupport.h>
60
#include <qmljstools/qmljsmodelmanager.h>
Tobias Hunger's avatar
Tobias Hunger committed
61
62
63
64
65
66
67
68
69
70
71
72

#include <qmljs/qmljsmodelmanagerinterface.h>

#include <qbs.h>
#include <tools/scripttools.h> // qbs, remove once there is a expand method in Qbs itself!

#include <QFileInfo>

// --------------------------------------------------------------------
// Constants:
// --------------------------------------------------------------------

73
74
static const char CONFIG_CPP_MODULE[] = "cpp";
static const char CONFIG_CXXFLAGS[] = "cxxflags";
75
static const char CONFIG_CFLAGS[] = "cflags";
76
77
78
79
static const char CONFIG_DEFINES[] = "defines";
static const char CONFIG_INCLUDEPATHS[] = "includePaths";
static const char CONFIG_FRAMEWORKPATHS[] = "frameworkPaths";
static const char CONFIG_PRECOMPILEDHEADER[] = "precompiledHeader";
Tobias Hunger's avatar
Tobias Hunger committed
80
81
82
83
84
85
86
87
88

static const char CONFIGURATION_PATH[] = "<configuration>";

// --------------------------------------------------------------------
// HELPERS:
// --------------------------------------------------------------------

ProjectExplorer::TaskHub *taskHub()
{
hjk's avatar
hjk committed
89
    return ProjectExplorer::ProjectExplorerPlugin::taskHub();
Tobias Hunger's avatar
Tobias Hunger committed
90
91
92
93
94
95
96
97
98
99
100
}


namespace QbsProjectManager {
namespace Internal {

// --------------------------------------------------------------------
// QbsProject:
// --------------------------------------------------------------------

QbsProject::QbsProject(QbsManager *manager, const QString &fileName) :
101
102
103
    m_manager(manager),
    m_projectName(QFileInfo(fileName).completeBaseName()),
    m_fileName(fileName),
104
    m_rootProjectNode(0),
Tobias Hunger's avatar
Tobias Hunger committed
105
106
    m_qbsSetupProjectJob(0),
    m_qbsUpdateFutureInterface(0),
107
108
    m_currentProgressBase(0),
    m_forceParsing(false),
Tobias Hunger's avatar
Tobias Hunger committed
109
110
    m_currentBc(0)
{
111
    m_parsingDelay.setInterval(1000); // delay parsing by 1s.
112

Tobias Hunger's avatar
Tobias Hunger committed
113
    setProjectContext(Core::Context(Constants::PROJECT_ID));
114
    setProjectLanguages(Core::Context(ProjectExplorer::Constants::LANG_CXX));
Tobias Hunger's avatar
Tobias Hunger committed
115
116
117
118
119

    connect(this, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)),
            this, SLOT(changeActiveTarget(ProjectExplorer::Target*)));
    connect(this, SIGNAL(addedTarget(ProjectExplorer::Target*)),
            this, SLOT(targetWasAdded(ProjectExplorer::Target*)));
120
121
122
    connect(this, SIGNAL(environmentChanged()), this, SLOT(delayParsing()));

    connect(&m_parsingDelay, SIGNAL(timeout()), this, SLOT(parseCurrentBuildConfiguration()));
Tobias Hunger's avatar
Tobias Hunger committed
123

124
    updateDocuments(QSet<QString>() << fileName);
125
    m_rootProjectNode = new QbsProjectNode(this); // needs documents to be initialized!
Tobias Hunger's avatar
Tobias Hunger committed
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
}

QbsProject::~QbsProject()
{
    m_codeModelFuture.cancel();
}

QString QbsProject::displayName() const
{
    return m_projectName;
}

Core::Id QbsProject::id() const
{
    return Core::Id(Constants::PROJECT_ID);
}

Core::IDocument *QbsProject::document() const
{
    foreach (Core::IDocument *doc, m_qbsDocuments) {
146
        if (doc->filePath() == m_fileName)
Tobias Hunger's avatar
Tobias Hunger committed
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
            return doc;
    }
    QTC_ASSERT(false, return 0);
}

QbsManager *QbsProject::projectManager() const
{
    return m_manager;
}

ProjectExplorer::ProjectNode *QbsProject::rootProjectNode() const
{
    return m_rootProjectNode;
}

QStringList QbsProject::files(ProjectExplorer::Project::FilesMode fileMode) const
{
    Q_UNUSED(fileMode);
165
    QSet<QString> result;
166
167
    if (m_rootProjectNode && m_rootProjectNode->qbsProjectData().isValid()) {
        foreach (const qbs::ProductData &prd, m_rootProjectNode->qbsProjectData().allProducts()) {
168
169
170
            foreach (const qbs::GroupData &grp, prd.groups()) {
                foreach (const QString &file, grp.allFilePaths())
                    result.insert(file);
171
                result.insert(grp.location().fileName());
172
            }
173
            result.insert(prd.location().fileName());
174
        }
175
        result.insert(m_rootProjectNode->qbsProjectData().location().fileName());
Tobias Hunger's avatar
Tobias Hunger committed
176
    }
177
    return result.toList();
Tobias Hunger's avatar
Tobias Hunger committed
178
179
180
181
182
183
184
}

void QbsProject::invalidate()
{
    prepareForParsing();
}

185
qbs::BuildJob *QbsProject::build(const qbs::BuildOptions &opts, QStringList productNames)
Tobias Hunger's avatar
Tobias Hunger committed
186
{
Tobias Hunger's avatar
Tobias Hunger committed
187
    if (!qbsProject() || isParsing())
Tobias Hunger's avatar
Tobias Hunger committed
188
        return 0;
189
190
191
192
193
194
    if (productNames.isEmpty()) {
        return qbsProject()->buildAllProducts(opts);
    } else {
        QList<qbs::ProductData> products;
        foreach (const QString &productName, productNames) {
            bool found = false;
195
            foreach (const qbs::ProductData &data, qbsProjectData().allProducts()) {
196
197
198
199
200
201
202
203
204
205
206
207
                if (data.name() == productName) {
                    found = true;
                    products.append(data);
                    break;
                }
            }
            if (!found)
                return 0;
        }

        return qbsProject()->buildSomeProducts(products, opts);
    }
Tobias Hunger's avatar
Tobias Hunger committed
208
209
}

210
qbs::CleanJob *QbsProject::clean(const qbs::CleanOptions &opts)
Tobias Hunger's avatar
Tobias Hunger committed
211
{
212
    if (!qbsProject())
Tobias Hunger's avatar
Tobias Hunger committed
213
        return 0;
214
    return qbsProject()->cleanAllProducts(opts);
Tobias Hunger's avatar
Tobias Hunger committed
215
216
}

Tobias Hunger's avatar
Tobias Hunger committed
217
218
219
220
221
222
223
qbs::InstallJob *QbsProject::install(const qbs::InstallOptions &opts)
{
    if (!qbsProject())
        return 0;
    return qbsProject()->installAllProducts(opts);
}

Tobias Hunger's avatar
Tobias Hunger committed
224
225
226
227
228
229
230
231
232
233
234
235
QString QbsProject::profileForTarget(const ProjectExplorer::Target *t) const
{
    return m_manager->profileForKit(t->kit());
}

bool QbsProject::isParsing() const
{
    return m_qbsUpdateFutureInterface;
}

bool QbsProject::hasParseResult() const
{
236
    return qbsProject();
Tobias Hunger's avatar
Tobias Hunger committed
237
238
239
240
241
242
243
244
245
}

Utils::FileName QbsProject::defaultBuildDirectory() const
{
    QFileInfo fi(m_fileName);
    const QString buildDir = QDir(fi.canonicalPath()).absoluteFilePath(QString::fromLatin1("../%1-build").arg(fi.baseName()));
    return Utils::FileName::fromString(buildDir);
}

246
247
248
249
const qbs::Project *QbsProject::qbsProject() const
{
    if (!m_rootProjectNode)
        return 0;
250
    return m_rootProjectNode->qbsProject();
251
252
}

253
const qbs::ProjectData QbsProject::qbsProjectData() const
254
255
{
    if (!m_rootProjectNode)
256
        return qbs::ProjectData();
257
    return m_rootProjectNode->qbsProjectData();
258
259
}

260
261
262
263
264
bool QbsProject::needsSpecialDeployment() const
{
    return true;
}

Tobias Hunger's avatar
Tobias Hunger committed
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
void QbsProject::handleQbsParsingDone(bool success)
{
    QTC_ASSERT(m_qbsSetupProjectJob, return);
    QTC_ASSERT(m_qbsUpdateFutureInterface, return);

    qbs::Project *project = 0;
    if (success) {
        project = new qbs::Project(m_qbsSetupProjectJob->project());
    } else {
        generateErrors(m_qbsSetupProjectJob->error());
        m_qbsUpdateFutureInterface->reportCanceled();
    }
    m_qbsSetupProjectJob->deleteLater();
    m_qbsSetupProjectJob = 0;

    m_qbsUpdateFutureInterface->reportFinished();
    delete m_qbsUpdateFutureInterface;
    m_qbsUpdateFutureInterface = 0;

    m_rootProjectNode->update(project);

286
    updateDocuments(project ? project->buildSystemFiles() : QSet<QString>() << m_fileName);
Tobias Hunger's avatar
Tobias Hunger committed
287

288
289
    updateCppCodeModel(m_rootProjectNode->qbsProjectData());
    updateQmlJsCodeModel(m_rootProjectNode->qbsProjectData());
Tobias Hunger's avatar
Tobias Hunger committed
290

Tobias Hunger's avatar
Tobias Hunger committed
291
292
293
    foreach (ProjectExplorer::Target *t, targets())
        t->updateDefaultRunConfigurations();

294
    emit fileListChanged();
Tobias Hunger's avatar
Tobias Hunger committed
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
    emit projectParsingDone(success);
}

void QbsProject::handleQbsParsingProgress(int progress)
{
    if (m_qbsUpdateFutureInterface)
        m_qbsUpdateFutureInterface->setProgressValue(m_currentProgressBase + progress);
}

void QbsProject::handleQbsParsingTaskSetup(const QString &description, int maximumProgressValue)
{
    Q_UNUSED(description);
    if (m_qbsUpdateFutureInterface) {
        m_currentProgressBase = m_qbsUpdateFutureInterface->progressValue();
        m_qbsUpdateFutureInterface->setProgressRange(0, m_currentProgressBase + maximumProgressValue);
    }
}

void QbsProject::targetWasAdded(ProjectExplorer::Target *t)
{
    connect(t, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
316
317
            this, SLOT(delayForcedParsing()));
    connect(t, SIGNAL(buildDirectoryChanged()), this, SLOT(delayForcedParsing()));
Tobias Hunger's avatar
Tobias Hunger committed
318
319
320
321
322
323
324
325
326
327
328
329
330
}

void QbsProject::changeActiveTarget(ProjectExplorer::Target *t)
{
    ProjectExplorer::BuildConfiguration *bc = 0;
    if (t && t->kit())
        bc = t->activeBuildConfiguration();
    buildConfigurationChanged(bc);
}

void QbsProject::buildConfigurationChanged(ProjectExplorer::BuildConfiguration *bc)
{
    if (m_currentBc)
331
        disconnect(m_currentBc, SIGNAL(qbsConfigurationChanged()), this, SLOT(delayParsing()));
Tobias Hunger's avatar
Tobias Hunger committed
332
333
334

    m_currentBc = qobject_cast<QbsBuildConfiguration *>(bc);
    if (m_currentBc) {
335
336
        connect(m_currentBc, SIGNAL(qbsConfigurationChanged()), this, SLOT(delayParsing()));
        delayParsing();
Tobias Hunger's avatar
Tobias Hunger committed
337
338
339
340
341
    } else {
        invalidate();
    }
}

342
343
344
345
346
void QbsProject::delayParsing()
{
    m_parsingDelay.start();
}

347
348
349
350
351
352
void QbsProject::delayForcedParsing()
{
    m_forceParsing = true;
    delayParsing();
}

Tobias Hunger's avatar
Tobias Hunger committed
353
354
void QbsProject::parseCurrentBuildConfiguration()
{
355
356
    m_parsingDelay.stop();

Tobias Hunger's avatar
Tobias Hunger committed
357
358
359
360
361
    if (!activeTarget())
        return;
    QbsBuildConfiguration *bc = qobject_cast<QbsBuildConfiguration *>(activeTarget()->activeBuildConfiguration());
    if (!bc)
        return;
Tobias Hunger's avatar
Tobias Hunger committed
362
    parse(bc->qbsConfiguration(), bc->environment(), bc->buildDirectory());
Tobias Hunger's avatar
Tobias Hunger committed
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
}

bool QbsProject::fromMap(const QVariantMap &map)
{
    if (!Project::fromMap(map))
        return false;

    ProjectExplorer::KitManager *km = ProjectExplorer::KitManager::instance();
    if (!activeTarget() && km->defaultKit()) {
        ProjectExplorer::Target *t = new ProjectExplorer::Target(this, km->defaultKit());
        t->updateDefaultBuildConfigurations();
        t->updateDefaultDeployConfigurations();
        t->updateDefaultRunConfigurations();
        addTarget(t);
    }

    return true;
}

382
void QbsProject::generateErrors(const qbs::ErrorInfo &e)
Tobias Hunger's avatar
Tobias Hunger committed
383
{
384
    foreach (const qbs::ErrorItem &item, e.items())
Tobias Hunger's avatar
Tobias Hunger committed
385
        taskHub()->addTask(ProjectExplorer::Task(ProjectExplorer::Task::Error,
386
387
388
                                                 item.description(),
                                                 Utils::FileName::fromString(item.codeLocation().fileName()),
                                                 item.codeLocation().line(),
Tobias Hunger's avatar
Tobias Hunger committed
389
390
391
                                                 ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
}

Tobias Hunger's avatar
Tobias Hunger committed
392
void QbsProject::parse(const QVariantMap &config, const Utils::Environment &env, const QString &dir)
Tobias Hunger's avatar
Tobias Hunger committed
393
394
{
    QTC_ASSERT(!dir.isNull(), return);
395

396
    // Clear buildsystem related tasks:
hjk's avatar
hjk committed
397
    taskHub()->clearTasks(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM);
398

Tobias Hunger's avatar
Tobias Hunger committed
399
    qbs::SetupProjectParameters params;
400
    params.setBuildConfiguration(config);
401
    qbs::ErrorInfo err = params.expandBuildConfiguration(m_manager->settings());
Tobias Hunger's avatar
Tobias Hunger committed
402
    if (err.hasError()) {
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
        generateErrors(err);
        return;
    }

    // Avoid useless reparsing:
    const qbs::Project *currentProject = qbsProject();
    if (!m_forceParsing
            && currentProject
            && currentProject->projectConfiguration() == params.buildConfiguration()) {
        QHash<QString, QString> usedEnv = currentProject->usedEnvironment();
        bool canSkip = true;
        for (QHash<QString, QString>::const_iterator i = usedEnv.constBegin();
             i != usedEnv.constEnd(); ++i) {
            if (env.value(i.key()) != i.value()) {
                canSkip = false;
                break;
            }
        }
        if (canSkip)
            return;
    }

425
    params.setBuildRoot(dir);
Christian Kandeler's avatar
Christian Kandeler committed
426
427
    params.setProjectFilePath(m_fileName);
    params.setIgnoreDifferentProjectFilePath(false);
Tobias Hunger's avatar
Tobias Hunger committed
428
    params.setEnvironment(env.toProcessEnvironment());
429
    qbs::Preferences *prefs = QbsManager::preferences();
430
    const QString buildDir = qbsBuildDir();
Christian Kandeler's avatar
Christian Kandeler committed
431
432
    params.setSearchPaths(prefs->searchPaths(buildDir));
    params.setPluginPaths(prefs->pluginPaths(buildDir));
Tobias Hunger's avatar
Tobias Hunger committed
433

434
435
436
437
    // Do the parsing:
    prepareForParsing();
    QTC_ASSERT(!m_qbsSetupProjectJob, return);

Tobias Hunger's avatar
Tobias Hunger committed
438
    m_qbsSetupProjectJob
439
            = qbs::Project::setupProject(params, m_manager->logSink(), 0);
Tobias Hunger's avatar
Tobias Hunger committed
440
441
442
443
444
445
446

    connect(m_qbsSetupProjectJob, SIGNAL(finished(bool,qbs::AbstractJob*)),
            this, SLOT(handleQbsParsingDone(bool)));
    connect(m_qbsSetupProjectJob, SIGNAL(taskStarted(QString,int,qbs::AbstractJob*)),
            this, SLOT(handleQbsParsingTaskSetup(QString,int)));
    connect(m_qbsSetupProjectJob, SIGNAL(taskProgress(int,qbs::AbstractJob*)),
            this, SLOT(handleQbsParsingProgress(int)));
447
448

    emit projectParsingStarted();
Tobias Hunger's avatar
Tobias Hunger committed
449
450
451
452
}

void QbsProject::prepareForParsing()
{
453
454
    m_forceParsing = false;

455
    taskHub()->clearTasks(ProjectExplorer::Constants::TASK_CATEGORY_COMPILE);
Tobias Hunger's avatar
Tobias Hunger committed
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
    if (m_qbsUpdateFutureInterface)
        m_qbsUpdateFutureInterface->reportCanceled();
    delete m_qbsUpdateFutureInterface;
    m_qbsUpdateFutureInterface = 0;

    delete m_qbsSetupProjectJob;
    m_qbsSetupProjectJob = 0;

    m_currentProgressBase = 0;
    m_qbsUpdateFutureInterface = new QFutureInterface<void>();
    m_qbsUpdateFutureInterface->setProgressRange(0, 0);
    Core::ICore::progressManager()->addTask(m_qbsUpdateFutureInterface->future(), tr("Evaluating"),
                                            QLatin1String(Constants::QBS_EVALUATE));
    m_qbsUpdateFutureInterface->reportStarted();
}

472
void QbsProject::updateDocuments(const QSet<QString> &files)
Tobias Hunger's avatar
Tobias Hunger committed
473
474
{
    // Update documents:
475
476
    QSet<QString> newFiles = files;
    QTC_ASSERT(!newFiles.isEmpty(), newFiles << m_fileName);
Tobias Hunger's avatar
Tobias Hunger committed
477
478
    QSet<QString> oldFiles;
    foreach (Core::IDocument *doc, m_qbsDocuments)
479
        oldFiles.insert(doc->filePath());
Tobias Hunger's avatar
Tobias Hunger committed
480
481
482
483
484
485
486
487

    QSet<QString> filesToAdd = newFiles;
    filesToAdd.subtract(oldFiles);
    QSet<QString> filesToRemove = oldFiles;
    filesToRemove.subtract(newFiles);

    QSet<Core::IDocument *> currentDocuments = m_qbsDocuments;
    foreach (Core::IDocument *doc, currentDocuments) {
488
        if (filesToRemove.contains(doc->filePath())) {
Tobias Hunger's avatar
Tobias Hunger committed
489
490
491
492
493
494
495
496
497
498
499
500
            m_qbsDocuments.remove(doc);
            delete doc;
        }
    }
    QSet<Core::IDocument *> toAdd;
    foreach (const QString &f, filesToAdd)
        toAdd.insert(new QbsProjectFile(this, f));

    Core::DocumentManager::instance()->addDocuments(toAdd.toList());
    m_qbsDocuments.unite(toAdd);
}

501
void QbsProject::updateCppCodeModel(const qbs::ProjectData &prj)
Tobias Hunger's avatar
Tobias Hunger committed
502
{
503
    if (!prj.isValid())
Tobias Hunger's avatar
Tobias Hunger committed
504
505
506
507
508
509
510
511
512
513
        return;

    ProjectExplorer::Kit *k = 0;
    QtSupport::BaseQtVersion *qtVersion = 0;
    if (ProjectExplorer::Target *target = activeTarget())
        k = target->kit();
    else
        k = ProjectExplorer::KitManager::instance()->defaultKit();
    qtVersion = QtSupport::QtKitInformation::qtVersion(k);

514
515
    CppTools::CppModelManagerInterface *modelmanager =
        CppTools::CppModelManagerInterface::instance();
Tobias Hunger's avatar
Tobias Hunger committed
516
517
518
519

    if (!modelmanager)
        return;

520
    CppTools::CppModelManagerInterface::ProjectInfo pinfo = modelmanager->projectInfo(this);
Tobias Hunger's avatar
Tobias Hunger committed
521
    pinfo.clearProjectParts();
522
523
    CppTools::ProjectPart::QtVersion qtVersionForPart
            = CppTools::ProjectPart::NoQt;
Tobias Hunger's avatar
Tobias Hunger committed
524
525
    if (qtVersion) {
        if (qtVersion->qtVersion() < QtSupport::QtVersionNumber(5,0,0))
526
            qtVersionForPart = CppTools::ProjectPart::Qt4;
Tobias Hunger's avatar
Tobias Hunger committed
527
        else
528
            qtVersionForPart = CppTools::ProjectPart::Qt5;
Tobias Hunger's avatar
Tobias Hunger committed
529
530
    }

Tobias Hunger's avatar
Tobias Hunger committed
531
    QHash<QString, QString> uiFiles;
Tobias Hunger's avatar
Tobias Hunger committed
532
    QStringList allFiles;
533
    foreach (const qbs::ProductData &prd, prj.allProducts()) {
Tobias Hunger's avatar
Tobias Hunger committed
534
        foreach (const qbs::GroupData &grp, prd.groups()) {
535
            const qbs::PropertyMap &props = grp.properties();
Tobias Hunger's avatar
Tobias Hunger committed
536

537
538
539
            const QStringList cxxFlags = props.getModulePropertiesAsStringList(
                        QLatin1String(CONFIG_CPP_MODULE),
                        QLatin1String(CONFIG_CXXFLAGS));
Tobias Hunger's avatar
Tobias Hunger committed
540

541
542
543
544
            const QStringList cFlags = props.getModulePropertiesAsStringList(
                        QLatin1String(CONFIG_CPP_MODULE),
                        QLatin1String(CONFIG_CFLAGS));

545
546
547
            QStringList list = props.getModulePropertiesAsStringList(
                        QLatin1String(CONFIG_CPP_MODULE),
                        QLatin1String(CONFIG_DEFINES));
548
            QByteArray grpDefines;
549
550
551
552
553
554
555
            foreach (const QString &def, list) {
                QByteArray data = def.toUtf8();
                int pos = data.indexOf('=');
                if (pos >= 0)
                    data[pos] = ' ';
                grpDefines += (QByteArray("#define ") + data + '\n');
            }
Tobias Hunger's avatar
Tobias Hunger committed
556

557
558
            list = props.getModulePropertiesAsStringList(QLatin1String(CONFIG_CPP_MODULE),
                                                         QLatin1String(CONFIG_INCLUDEPATHS));
559
            QStringList grpIncludePaths;
Tobias Hunger's avatar
Tobias Hunger committed
560
561
562
563
564
            foreach (const QString &p, list) {
                const QString cp = Utils::FileName::fromUserInput(p).toString();
                grpIncludePaths.append(cp);
            }

565
566
            list = props.getModulePropertiesAsStringList(QLatin1String(CONFIG_CPP_MODULE),
                                                         QLatin1String(CONFIG_FRAMEWORKPATHS));
567
            QStringList grpFrameworkPaths;
Tobias Hunger's avatar
Tobias Hunger committed
568
569
570
571
572
            foreach (const QString &p, list) {
                const QString cp = Utils::FileName::fromUserInput(p).toString();
                grpFrameworkPaths.append(cp);
            }

573
574
            const QString pch = props.getModuleProperty(QLatin1String(CONFIG_CPP_MODULE),
                    QLatin1String(CONFIG_PRECOMPILEDHEADER)).toString();
Tobias Hunger's avatar
Tobias Hunger committed
575

576
            CppTools::ProjectPart::Ptr part(new CppTools::ProjectPart);
577
578
            part->evaluateToolchain(ProjectExplorer::ToolChainKitInformation::toolChain(k),
                                    cxxFlags,
579
                                    cFlags,
580
581
                                    ProjectExplorer::SysRootKitInformation::sysRoot(k));

582
            CppTools::ProjectFileAdder adder(part->files);
Tobias Hunger's avatar
Tobias Hunger committed
583
584
585
586
587
588
589
            foreach (const QString &file, grp.allFilePaths()) {
                if (file.endsWith(QLatin1String(".ui"))) {
                    QStringList generated = m_rootProjectNode->qbsProject()
                            ->generatedFiles(prd, file, QStringList(QLatin1String("hpp")));
                    if (generated.count() == 1)
                        uiFiles.insert(file, generated.at(0));
                }
590
591
                if (adder.maybeAdd(file))
                    allFiles.append(file);
Tobias Hunger's avatar
Tobias Hunger committed
592
            }
593
594
            part->files << CppTools::ProjectFile(QLatin1String(CONFIGURATION_PATH),
                                                  CppTools::ProjectFile::CXXHeader);
595
596

            part->qtVersion = qtVersionForPart;
597
598
            part->includePaths += grpIncludePaths;
            part->frameworkPaths += grpFrameworkPaths;
599
            part->precompiledHeaders = QStringList(pch);
600
            part->defines += grpDefines;
601
            pinfo.appendProjectPart(part);
Tobias Hunger's avatar
Tobias Hunger committed
602
603
604
        }
    }

605
606
    setProjectLanguage(ProjectExplorer::Constants::LANG_CXX, !allFiles.isEmpty());

Tobias Hunger's avatar
Tobias Hunger committed
607
608
609
    if (pinfo.projectParts().isEmpty())
        return;

Tobias Hunger's avatar
Tobias Hunger committed
610
611
    QtSupport::UiCodeModelManager::update(this, uiFiles);

Tobias Hunger's avatar
Tobias Hunger committed
612
    // Register update the code model:
613
    m_codeModelFuture = modelmanager->updateProjectInfo(pinfo);
Tobias Hunger's avatar
Tobias Hunger committed
614
615
}

616
void QbsProject::updateQmlJsCodeModel(const qbs::ProjectData &prj)
Tobias Hunger's avatar
Tobias Hunger committed
617
618
{
    Q_UNUSED(prj);
619
620
621
622
    QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance();
    if (!modelManager)
        return;

623
624
    QmlJS::ModelManagerInterface::ProjectInfo projectInfo =
            QmlJSTools::defaultProjectInfoForProject(this);
625
626

    setProjectLanguage(ProjectExplorer::Constants::LANG_QMLJS, !projectInfo.sourceFiles.isEmpty());
Tobias Hunger's avatar
Tobias Hunger committed
627
628
629
    modelManager->updateProjectInfo(projectInfo);
}

630
631
632
633
634
QString QbsProject::qbsBuildDir() const
{
    QString buildDir = Utils::Environment::systemEnvironment()
            .value(QLatin1String("QBS_BUILD_DIR"));
    if (buildDir.isEmpty())
635
        buildDir = Core::ICore::resourcePath() + QLatin1String("/qbs");
636
637
638
    return buildDir;
}

Tobias Hunger's avatar
Tobias Hunger committed
639
640
} // namespace Internal
} // namespace QbsProjectManager