~ubuntu-sdk-team/qtcreator-plugin-ubuntu/trunk

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
96
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
#include "ubuntukitmanager.h"
#include "clicktoolchain.h"
#include "ubuntuconstants.h"
#include <ubuntu/device/remote/ubuntudevice.h>
#include "ubuntuclickdialog.h"
#include "ubuntuqtversion.h"
#include "settings.h"
#include "device/container/containerdevice.h"

#include <coreplugin/icore.h>
#include <projectexplorer/kitmanager.h>
#include <projectexplorer/kit.h>
#include <projectexplorer/toolchain.h>
#include <projectexplorer/toolchainmanager.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/devicesupport/devicemanager.h>
#include <debugger/debuggeritemmanager.h>
#include <debugger/debuggeritem.h>
#include <debugger/debuggerkitinformation.h>
#include <qtsupport/qtkitinformation.h>

#include <cmakeprojectmanager/cmaketoolmanager.h>
#include <cmakeprojectmanager/cmaketool.h>
#include <cmakeprojectmanager/cmakekitinformation.h>
#include <cmakeprojectmanager/cmakeconfigitem.h>
#include <qtsupport/qtversionmanager.h>

#include <QMessageBox>
#include <QRegularExpression>
#include <QTextStream>
#include <QStandardPaths>
#include <QFileInfo>
#include <QDebug>
#include <QPair>
#include <QInputDialog>

namespace Ubuntu {
namespace Internal {

enum {
    debug = 0
};

static bool equalKits(ProjectExplorer::Kit *a, ProjectExplorer::Kit *b)
{
    return ProjectExplorer::ToolChainKitInformation::toolChain(a) == ProjectExplorer::ToolChainKitInformation::ToolChainKitInformation::toolChain(b);
}

static bool lessThanToolchain (const ClickToolChain* left, const ClickToolChain* right)
{
    const UbuntuClickTool::Target &leftTarget = left->clickTarget();
    const UbuntuClickTool::Target &rightTarget = right->clickTarget();
    return UbuntuClickFrameworkProvider::caseInsensitiveFWLessThan(leftTarget.framework, rightTarget.framework);
}


static void createOrFindDeviceAndType(ProjectExplorer::Kit *k, ClickToolChain *tc)
{
    if (UbuntuClickTool::compatibleWithHostArchitecture(tc->clickTarget().architecture)) {
        Core::Id devId = ContainerDevice::createIdForContainer(tc->clickTarget().containerName);
        ProjectExplorer::IDevice::ConstPtr ptr
                = ProjectExplorer::DeviceManager::instance()->find(devId);

        if (!ptr) {
            ContainerDevice::Ptr dev = ContainerDevice::create(devId, devId);
            ProjectExplorer::DeviceManager::instance()->addDevice(dev);
            ptr = dev;
        }

        ProjectExplorer::DeviceTypeKitInformation::setDeviceTypeId(k,devId);
        ProjectExplorer::DeviceKitInformation::setDevice(k, ptr);
    } else {
        //a Kit that cannot take a Container Device
        Core::Id devTypeId = Core::Id(Constants::UBUNTU_DEVICE_TYPE_ID).withSuffix(tc->clickTarget().architecture);
        ProjectExplorer::DeviceTypeKitInformation::setDeviceTypeId(k,devTypeId);
    }
}
UbuntuKitManager::UbuntuKitManager()
{
}

QList<ClickToolChain *> UbuntuKitManager::clickToolChains()
{
    QList<ClickToolChain *> toolchains;
    // having a empty toolchains list will remove all autodetected kits for android
    // exactly what we want in that case
    foreach (ProjectExplorer::ToolChain *tc, ProjectExplorer::ToolChainManager::toolChains()) {
        if(tc) {
            if (!tc->isAutoDetected())
                continue;
            if (tc->typeId() != Constants::UBUNTU_CLICK_TOOLCHAIN_ID)
                continue;
            toolchains << static_cast<ClickToolChain *>(tc);
        }
    }
    return toolchains;
}

QList<ProjectExplorer::Kit *> UbuntuKitManager::findKitsUsingTarget (const UbuntuClickTool::Target &target)
{
    auto matcher = [&target](const ProjectExplorer::Kit *k) {
        ProjectExplorer::ToolChain *tc = ProjectExplorer::ToolChainKitInformation::toolChain(k);
        if (!tc)
            return false;

        if (tc->typeId() != Constants::UBUNTU_CLICK_TOOLCHAIN_ID)
            return false;

        ClickToolChain *cTc = static_cast<ClickToolChain *>(tc);
        return (cTc->clickTarget().containerName == target.containerName);
    };

    return ProjectExplorer::KitManager::matchingKits(ProjectExplorer::KitMatcher(matcher));
}

UbuntuQtVersion *UbuntuKitManager::createOrFindQtVersion(ClickToolChain *tc)
{
    QString qmakePath = UbuntuClickTool::findOrCreateQMakeWrapper(tc->clickTarget());
    if(!QFile::exists(qmakePath)) {
        return 0;
    } else {
        //try to find a already existing Qt Version for this chroot
        foreach (QtSupport::BaseQtVersion *qtVersion, QtSupport::QtVersionManager::versions()) {
            if (qtVersion->type() != QLatin1String(Constants::UBUNTU_QTVERSION_TYPE))
                continue;

            if (qtVersion->qmakeCommand().toFileInfo().absoluteFilePath() == QFileInfo(qmakePath).absoluteFilePath())
                return static_cast<UbuntuQtVersion*> (qtVersion);
        }
    }

    UbuntuQtVersion *qtVersion = new UbuntuQtVersion(tc->clickTarget().containerName, Utils::FileName::fromString(qmakePath),false);
    QtSupport::QtVersionManager::addVersion(qtVersion);
    return qtVersion;
}

CMakeProjectManager::CMakeTool *UbuntuKitManager::createOrFindCMakeTool(ClickToolChain *tc)
{
    QString cmakePathStr = UbuntuClickTool::findOrCreateToolWrapper(QStringLiteral("cmake"), tc->clickTarget());
    Utils::FileName cmakePath = Utils::FileName::fromString(cmakePathStr);

    CMakeProjectManager::CMakeTool *cmake = CMakeProjectManager::CMakeToolManager::findByCommand(cmakePath);
    if (cmake)
        return cmake;

    cmake = createCMakeTool(tc);
    if (!CMakeProjectManager::CMakeToolManager::registerCMakeTool(cmake)) {
        delete cmake;
        return 0;
    }

    return cmake;
}

CMakeProjectManager::CMakeTool *UbuntuKitManager::createCMakeTool(ClickToolChain *tc)
{
    return createCMakeTool(tc->clickTarget());
}

CMakeProjectManager::CMakeTool *UbuntuKitManager::createCMakeTool(const UbuntuClickTool::Target &target)
{
    QString cmakePathStr = UbuntuClickTool::findOrCreateToolWrapper(QStringLiteral("cmake"), target);
    Utils::FileName cmakePath = Utils::FileName::fromString(cmakePathStr);
    CMakeProjectManager::CMakeTool *cmake = new CMakeProjectManager::CMakeTool(CMakeProjectManager::CMakeTool::AutoDetection,
                                                                               CMakeProjectManager::CMakeTool::createId());

    cmake->setCMakeExecutable(cmakePath);
    cmake->setDisplayName(tr("Ubuntu SDK cmake (%1-%2-%3)")
                          .arg(target.architecture)
                          .arg(target.framework)
                          .arg(target.containerName));
    return cmake;
}

void UbuntuKitManager::autoCreateKit(UbuntuDevice::Ptr device)
{
    ProjectExplorer::Abi requiredAbi = ClickToolChain::architectureNameToAbi(device->architecture());
    if(requiredAbi.isNull()) {
        QMessageBox::warning(Core::ICore::mainWindow(),
                             tr("Unknown device architecture"),
                             tr("Kit autocreation for %1 is not supported!")
                             .arg(device->architecture()));
        return;
    }

    if(device->framework().isEmpty()) {
        QMessageBox::warning(Core::ICore::mainWindow(),
                             tr("Device framework is unknown."),
                             tr("The supported framework of the device is not known, please make sure to redetect the device features."));
        return;
    }

    QList<ClickToolChain*> toolchains = clickToolChains();

    auto findCompatibleTc = [&](){
        QList<ClickToolChain *> perfectMatches;
        QList<ClickToolChain *> fuzzyMatches;
        if(toolchains.size() > 0) {
            qSort(toolchains.begin(),toolchains.end(),lessThanToolchain);

            for( int i = toolchains.size() -1; i >= 0; i-- ) {
                ClickToolChain* tc = toolchains[i];

                if (tc->clickTarget().framework != device->framework())
                    continue;

                if( tc->targetAbi() == requiredAbi ) {
                    perfectMatches.append(tc);
                    continue;
                }

                //the abi is compatible but not exactly the same
                if(tc->targetAbi().isCompatibleWith(requiredAbi))
                    fuzzyMatches.append(tc);
            }
        }
        return qMakePair(perfectMatches, fuzzyMatches);
    };

    ClickToolChain* match = nullptr;
    while (!match) {

        //search a tk with a compatible arch
        QPair<QList<ClickToolChain *>, QList<ClickToolChain *> > matches = findCompatibleTc();
        QList<ClickToolChain *> perfect = matches.first;
        QList<ClickToolChain *> fuzzy = matches.second;

        auto getToolchain = [](const QList<ClickToolChain *> &toolchains, bool *ok) {
            QStringList names;
            foreach (const ClickToolChain *curr, toolchains) {
                names.append(curr->displayName());
            }

            if (names.empty())
                return static_cast<ClickToolChain *>(nullptr);

            QString selection = QInputDialog::getItem(Core::ICore::mainWindow(), qApp->applicationName(),
                                                      tr("There are multiple compatible Toolchains available, please select one:"),
                                                      names, 0, false, ok);
            if (!ok) {
                return static_cast<ClickToolChain *>(nullptr);
            }

            return toolchains.at(names.indexOf(selection));
        };

        if (perfect.size() > 0) {
            if (perfect.size() == 1) {
                match = perfect.first();
                break;
            } else {
                bool ok = true;
                match = getToolchain(perfect, &ok);
                if (!ok)
                    return;

                break;
            }
        } else if (fuzzy.size() > 0) {
            if (fuzzy.size() == 1) {
                match = fuzzy.first();
                break;
            } else {
                bool ok = true;
                match = getToolchain(fuzzy, &ok);
                if (!ok)
                    return;

                break;
            }
        }

        if (!match) {
            //create target
            int choice = QMessageBox::question(Core::ICore::mainWindow(),
                                  tr("No target available"),
                                  tr("There is no compatible target available on your system, do you want to create it now?"));

            if(choice == QMessageBox::Yes) {
                if(!UbuntuClickDialog::createClickChrootModal(false, device->architecture(), device->framework()))
                    return;
                toolchains = clickToolChains();
            } else
                return;
        }
    }

    ProjectExplorer::Kit* newKit = createKit(match);
    if(newKit) {
        fixKit(newKit);

        newKit->setUnexpandedDisplayName(tr("%1 (GCC %2-%3-%4)")
                                        .arg(device->displayName())
                                        .arg(match->clickTarget().architecture)
                                        .arg(match->clickTarget().framework)
                                        .arg(match->clickTarget().containerName));

        ProjectExplorer::DeviceKitInformation::setDevice(newKit,device);
        ProjectExplorer::KitManager::registerKit(newKit);
    }
}

void UbuntuKitManager::autoDetectKits()
{
    //destroy all obsolete QtVersions, they are recreated later on in fixKit()
    foreach (QtSupport::BaseQtVersion *qtVersion, QtSupport::QtVersionManager::versions()) {
        if (qtVersion->type() != QLatin1String(Constants::UBUNTU_QTVERSION_TYPE))
            continue;

        UbuntuQtVersion* ver = static_cast<UbuntuQtVersion*> (qtVersion);
        if(ver->scriptVersion() < UbuntuQtVersion::minimalScriptVersion() || !qtVersion->isValid()) {
            //we need to remove that QtVersion
            QFile::remove(ver->qmakeCommand().toString());
            QtSupport::QtVersionManager::removeVersion(ver);
        }
    }

    // having a empty toolchains list will remove all autodetected kits for ubuntu
    // exactly what we want in that case
    QList<ClickToolChain *> toolchains = clickToolChains();

    QList<ProjectExplorer::Kit *> existingKits;
    foreach (ProjectExplorer::Kit *k, ProjectExplorer::KitManager::kits()) {
        if (k->isSdkProvided())
            continue;

        ProjectExplorer::ToolChain *tc = ProjectExplorer::ToolChainKitInformation::toolChain(k);
        if (tc && tc->typeId() != Constants::UBUNTU_CLICK_TOOLCHAIN_ID)
            continue;

        //@TODO check for ubuntu device information
        if(debug) qDebug()<<"Found possible Ubuntu Kit: "<<k->displayName();
        existingKits << k;
    }

    // create new kits
    QList<ProjectExplorer::Kit *> newKits;
    foreach (ClickToolChain *tc, toolchains) {
        ProjectExplorer::Kit* newKit = createKit(tc);
        newKit->makeSticky();
        newKits << newKit;
    }

    //remove already existing kits
    for (int i = existingKits.count() - 1; i >= 0; --i) {
        ProjectExplorer::Kit *existingKit = existingKits.at(i);
        for (int j = 0; j < newKits.count(); ++j) {
            ProjectExplorer::Kit *newKit = newKits.at(j);
            if (equalKits(existingKit, newKit)) {
                // Kit is already registered, nothing to do
                ProjectExplorer::Kit *oldKit = existingKits.takeAt(i);
                oldKit->blockNotification();
                oldKit->makeSticky();

                //make sure kit has all required informations
                fixKit(oldKit);
                oldKit->unblockNotification();

                newKits.removeAt(j);
                ProjectExplorer::KitManager::deleteKit(newKit);
                j = newKits.count();
            }
        }
    }

    //all kits remaining need to be removed if they don't have all informations
    foreach (ProjectExplorer::Kit *k, existingKits) {
        ProjectExplorer::ToolChain *tc = ProjectExplorer::ToolChainKitInformation::toolChain(k);
        CMakeProjectManager::CMakeTool* cmake = CMakeProjectManager::CMakeKitInformation::cmakeTool(k);
        if (tc && tc->typeId() == Constants::UBUNTU_CLICK_TOOLCHAIN_ID
                && cmake
                && cmake->isValid()) {
            fixKit(k);

            //existing targets are not autodetected anymore
            k->makeUnSticky();
            k->setAutoDetected(false);
        } else {
            //has not all informations, go away
            ProjectExplorer::KitManager::deregisterKit(k);
        }
    }

    foreach (ProjectExplorer::Kit *kit, newKits) {
        ClickToolChain *tc = static_cast<ClickToolChain *>(ProjectExplorer::ToolChainKitInformation::toolChain(kit));
        kit->setUnexpandedDisplayName(tr("UbuntuSDK for %1 (GCC %2-%3)")
                                      .arg(tc->clickTarget().containerName)
                                      .arg(tc->clickTarget().architecture)
                                      .arg(tc->clickTarget().framework));
        ProjectExplorer::KitManager::registerKit(kit);
        fixKit(kit);
    }

    static bool cmakeUpdaterSet = false;
    if (!cmakeUpdaterSet) {

        cmakeUpdaterSet = true;

        auto cmakeUpdater = [](const Core::Id &id){
            CMakeProjectManager::CMakeTool *tool = CMakeProjectManager::CMakeToolManager::findById(id);
            if (!tool)
                return;

            QString basePath = Settings::settingsPath().toString();
            if (tool->cmakeExecutable().toString().startsWith(basePath)) {
                qDebug()<<"Setting mapper to "<<tool->displayName();
                tool->setPathMapper(&UbuntuClickTool::mapIncludePathsForCMake);
            } else {
                qDebug()<<"Unsetting mapper from "<<tool->displayName();
                tool->setPathMapper(CMakeProjectManager::CMakeTool::PathMapper());
            }
        };

        connect(CMakeProjectManager::CMakeToolManager::instance(), &CMakeProjectManager::CMakeToolManager::cmakeAdded,
                cmakeUpdater);
        connect(CMakeProjectManager::CMakeToolManager::instance(), &CMakeProjectManager::CMakeToolManager::cmakeRemoved,
                cmakeUpdater);
    }
}

/*!
 * \brief UbuntuKitManager::createKit
 * Creates a new Kit for the Ubunut toolchain and sets default
 * values
 */
ProjectExplorer::Kit *UbuntuKitManager::createKit(ClickToolChain *tc)
{
    //@TODO find a qt version
    ProjectExplorer::Kit* newKit = new ProjectExplorer::Kit;
    newKit->setAutoDetected(false); //let the user delete that stuff
    newKit->setIconPath(Utils::FileName::fromString(QLatin1String(Constants::UBUNTU_ICON)));
    ProjectExplorer::ToolChainKitInformation::setToolChain(newKit, tc);

    CMakeProjectManager::CMakeTool *cmake = createOrFindCMakeTool(tc);
    if (cmake) {
        cmake->setPathMapper(&UbuntuClickTool::mapIncludePathsForCMake);
        CMakeProjectManager::CMakeKitInformation::setCMakeTool(newKit, cmake->id());
    }

    ProjectExplorer::SysRootKitInformation::setSysRoot(newKit,Utils::FileName::fromString(UbuntuClickTool::targetBasePath(tc->clickTarget())));

    createOrFindDeviceAndType(newKit, tc);

    //@TODO add gdbserver support
    QtSupport::QtKitInformation::setQtVersion(newKit, createOrFindQtVersion(tc));
    return newKit;
}



/*!
 * \brief UbuntuKitManager::createOrFindDebugger
 * Tries to find a already existing ubuntu debugger, if it can not find one
 * it is registered and returned
 */
QVariant UbuntuKitManager::createOrFindDebugger(const Utils::FileName &path)
{
    if(path.isEmpty())
        return QVariant();

    QList<Debugger::DebuggerItem> debuggers = Debugger::DebuggerItemManager::debuggers();
    foreach(const Debugger::DebuggerItem& debugger,debuggers) {
        if(debugger.command() == path) {
            return debugger.id();
        }
    }


    Debugger::DebuggerItem debugger;
    debugger.setCommand(path);
    debugger.setEngineType(Debugger::GdbEngineType);
    debugger.setUnexpandedDisplayName(tr("Ubuntu SDK Debugger"));
    debugger.setAutoDetected(true);
    //multiarch debugger
    ProjectExplorer::Abi abi(ProjectExplorer::Abi::UnknownArchitecture
                             ,ProjectExplorer::Abi::LinuxOS
                             ,ProjectExplorer::Abi::GenericLinuxFlavor
                             ,ProjectExplorer::Abi::UnknownFormat
                             ,0);
    debugger.setAbi(abi);
    return Debugger::DebuggerItemManager::registerDebugger(debugger);
}

/*!
 * \brief UbuntuKitManager::fixKit
 * Tries to fix a Kit if there is missing information
 */
void UbuntuKitManager::fixKit(ProjectExplorer::Kit *k)
{
    k->setAutoDetected(false);

    ClickToolChain* tc = static_cast<ClickToolChain *> (ProjectExplorer::ToolChainKitInformation::toolChain(k));
    if(!tc) {
        return;
    }

    //make sure we have the multiarch debugger
    QVariant dId = createOrFindDebugger(tc->suggestedDebugger());
    const Debugger::DebuggerItem *debugger = Debugger::DebuggerKitInformation::debugger(k);
    if(!debugger) {
        if(dId.isValid())
            Debugger::DebuggerKitInformation::setDebugger(k,dId);
    } else if (debugger->id() != dId){
        if(dId.isValid())
            Debugger::DebuggerKitInformation::setDebugger(k,dId);
    }

    if(ProjectExplorer::SysRootKitInformation::sysRoot(k).isEmpty()) {
        ProjectExplorer::SysRootKitInformation::setSysRoot(k,Utils::FileName::fromString(UbuntuClickTool::targetBasePath(tc->clickTarget())));
    }

    //make sure we point to a ubuntu device
    Core::Id devId = ProjectExplorer::DeviceTypeKitInformation::deviceTypeId(k);
    bool devValid        = devId.isValid(); //invalid type
    bool usesOldDevType  = devId == Constants::UBUNTU_DEVICE_TYPE_ID; //Kit uses still the old device type ids
    bool hasWrongDevType = devId.toString().startsWith(QLatin1String(Constants::UBUNTU_DEVICE_TYPE_ID)) ||
            devId.toString().startsWith(QLatin1String(Constants::UBUNTU_CONTAINER_DEVICE_TYPE_ID)); //kit has a wrong device type

    if (usesOldDevType) {
        //if this kit still uses the old type ids, we try to find the correct device by name

        Core::Id devTypeId = Core::Id(Constants::UBUNTU_DEVICE_TYPE_ID).withSuffix(tc->clickTarget().architecture);
        ProjectExplorer::DeviceTypeKitInformation::setDeviceTypeId(k,devTypeId);
        UbuntuDevice::ConstPtr fuzzyMatch;
        UbuntuDevice::ConstPtr fullMatch;

        //lets search for a device
        ProjectExplorer::DeviceManager *devMgr = ProjectExplorer::DeviceManager::instance();
        for (int i = 0; i<devMgr->deviceCount(); i++) {
            ProjectExplorer::IDevice::ConstPtr dev = devMgr->deviceAt(i);
            if(!dev)
                continue;

            //the type ID also checks if the architecture is correct
            if(dev->type() != devTypeId)
                continue;

            UbuntuDevice::ConstPtr ubuntuDev = qSharedPointerCast<const UbuntuDevice>(dev);

            //we found a possible Device!
            if(!fuzzyMatch)
                fuzzyMatch = ubuntuDev;

            //this is most likely the device that was used with this kit by using the autocreate button
            QRegularExpression regExp (QStringLiteral("^(%1\\s+\\(.*\\))$").arg(ubuntuDev->displayName()));
            QRegularExpressionMatch m = regExp.match(ubuntuDev->displayName());
            if (m.hasMatch()) {
                fullMatch = ubuntuDev;
                break;
            }
        }
        ProjectExplorer::DeviceKitInformation::setDevice(k,!fullMatch.isNull() ? fullMatch : fuzzyMatch);
    }

    if (!devValid || hasWrongDevType) {
        createOrFindDeviceAndType(k, tc);
    }

    //values the user can change
    k->setSticky(ProjectExplorer::DeviceKitInformation::id(),false);
    k->setSticky(Debugger::DebuggerKitInformation::id(),false);

    //values the user cannot change
    k->setSticky(ProjectExplorer::SysRootKitInformation::id(),true);
    k->setMutable(ProjectExplorer::SysRootKitInformation::id(),false);

    //make sure we use a ubuntu Qt version
    UbuntuQtVersion *qtVer = createOrFindQtVersion(tc);
    QtSupport::QtKitInformation::setQtVersion(k, qtVer);

    //make sure we use a ubuntu cmake
    CMakeProjectManager::CMakeTool *cmake = createOrFindCMakeTool(tc);
    if(cmake) {
        CMakeProjectManager::CMakeConfig  conf{
            CMakeProjectManager::CMakeConfigItem("QT_QMAKE_EXECUTABLE",  qtVer->remoteQMakeCommand().toUtf8()),
            CMakeProjectManager::CMakeConfigItem("CMAKE_CXX_COMPILER",  tc->remoteCompilerCommand().toUtf8())
        };

        cmake->setPathMapper(&UbuntuClickTool::mapIncludePathsForCMake);
        CMakeProjectManager::CMakeKitInformation::setCMakeTool(k, cmake->id());
        CMakeProjectManager::CMakeConfigurationKitInformation::setConfiguration(k , conf);
    }

}

} // namespace Internal
} // namespace Ubuntu