2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2012-09-18 15:58:07 +02:00
|
|
|
**
|
2016-01-15 14:57:14 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2012-09-18 15:58:07 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-09-18 15:58:07 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2016-01-15 14:57:14 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-18 15:58:07 +02:00
|
|
|
**
|
2016-01-15 14:57:14 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2012-09-18 15:58:07 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-09-18 15:58:07 +02:00
|
|
|
|
|
|
|
|
#include "addtoolchainoperation.h"
|
|
|
|
|
|
|
|
|
|
#include "addkeysoperation.h"
|
|
|
|
|
#include "findkeyoperation.h"
|
|
|
|
|
#include "findvalueoperation.h"
|
|
|
|
|
#include "getoperation.h"
|
|
|
|
|
#include "rmkeysoperation.h"
|
|
|
|
|
|
|
|
|
|
#include "settings.h"
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
2016-01-19 14:21:28 +01:00
|
|
|
#include <QDir>
|
|
|
|
|
|
2012-09-18 15:58:07 +02:00
|
|
|
// ToolChain file stuff:
|
2013-10-29 16:44:24 +01:00
|
|
|
const char COUNT[] = "ToolChain.Count";
|
|
|
|
|
const char PREFIX[] = "ToolChain.";
|
|
|
|
|
const char VERSION[] = "Version";
|
2012-09-18 15:58:07 +02:00
|
|
|
|
|
|
|
|
// ToolChain:
|
2013-10-29 16:44:24 +01:00
|
|
|
const char ID[] = "ProjectExplorer.ToolChain.Id";
|
|
|
|
|
const char DISPLAYNAME[] = "ProjectExplorer.ToolChain.DisplayName";
|
|
|
|
|
const char AUTODETECTED[] = "ProjectExplorer.ToolChain.Autodetect";
|
2012-09-18 15:58:07 +02:00
|
|
|
|
|
|
|
|
// GCC ToolChain:
|
2013-10-29 16:44:24 +01:00
|
|
|
const char PATH[] = "ProjectExplorer.GccToolChain.Path";
|
|
|
|
|
const char TARGET_ABI[] = "ProjectExplorer.GccToolChain.TargetAbi";
|
|
|
|
|
const char SUPPORTED_ABIS[] = "ProjectExplorer.GccToolChain.SupportedAbis";
|
2012-09-18 15:58:07 +02:00
|
|
|
|
|
|
|
|
QString AddToolChainOperation::name() const
|
|
|
|
|
{
|
2016-07-20 10:58:54 +02:00
|
|
|
return QString("addTC");
|
2012-09-18 15:58:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AddToolChainOperation::helpText() const
|
|
|
|
|
{
|
2016-07-20 10:58:54 +02:00
|
|
|
return QString("add a tool chain to Qt Creator");
|
2012-09-18 15:58:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AddToolChainOperation::argumentsHelpText() const
|
|
|
|
|
{
|
2016-07-20 10:58:54 +02:00
|
|
|
return QString(
|
|
|
|
|
" --id <ID> id of the new tool chain (required).\n"
|
2016-07-15 11:40:56 +02:00
|
|
|
" --name <NAME> display name of the new tool chain (required).\n"
|
|
|
|
|
" --path <PATH> path to the compiler (required).\n"
|
|
|
|
|
" --abi <ABI STRING> ABI of the compiler (required).\n"
|
|
|
|
|
" --supportedAbis <ABI STRING>,<ABI STRING> list of ABIs supported by the compiler.\n"
|
2016-07-20 10:58:54 +02:00
|
|
|
" <KEY> <TYPE:VALUE> extra key value pairs\n");
|
2012-09-18 15:58:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AddToolChainOperation::setArguments(const QStringList &args)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < args.count(); ++i) {
|
|
|
|
|
const QString current = args.at(i);
|
|
|
|
|
const QString next = ((i + 1) < args.count()) ? args.at(i + 1) : QString();
|
|
|
|
|
|
2016-07-15 11:40:56 +02:00
|
|
|
if (next.isNull() && current.startsWith("--")) {
|
2013-02-07 10:42:24 +01:00
|
|
|
std::cerr << "No parameter for option '" << qPrintable(current) << "' given." << std::endl << std::endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-15 11:40:56 +02:00
|
|
|
if (current == "--id") {
|
2012-09-18 15:58:07 +02:00
|
|
|
++i; // skip next;
|
|
|
|
|
m_id = next;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-15 11:40:56 +02:00
|
|
|
if (current == "--name") {
|
2012-09-18 15:58:07 +02:00
|
|
|
++i; // skip next;
|
|
|
|
|
m_displayName = next;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-15 11:40:56 +02:00
|
|
|
if (current == "--path") {
|
2012-09-18 15:58:07 +02:00
|
|
|
++i; // skip next;
|
2016-01-19 14:21:28 +01:00
|
|
|
m_path = QDir::fromNativeSeparators(next);
|
2012-09-18 15:58:07 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-15 11:40:56 +02:00
|
|
|
if (current == "--abi") {
|
2012-09-18 15:58:07 +02:00
|
|
|
++i; // skip next;
|
|
|
|
|
m_targetAbi = next;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-15 11:40:56 +02:00
|
|
|
if (current == "--supportedAbis") {
|
2012-09-18 15:58:07 +02:00
|
|
|
++i; // skip next;
|
|
|
|
|
m_supportedAbis = next;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-07 10:42:24 +01:00
|
|
|
if (next.isNull()) {
|
|
|
|
|
std::cerr << "No value given for key '" << qPrintable(current) << "'.";
|
2012-09-18 15:58:07 +02:00
|
|
|
return false;
|
2013-02-07 10:42:24 +01:00
|
|
|
}
|
2012-09-18 15:58:07 +02:00
|
|
|
++i; // skip next;
|
|
|
|
|
KeyValuePair pair(current, next);
|
2013-02-07 10:42:24 +01:00
|
|
|
if (!pair.value.isValid()) {
|
|
|
|
|
std::cerr << "Value for key '" << qPrintable(current) << "' is not valid.";
|
2012-09-18 15:58:07 +02:00
|
|
|
return false;
|
2013-02-07 10:42:24 +01:00
|
|
|
}
|
2012-09-18 15:58:07 +02:00
|
|
|
m_extra << pair;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_supportedAbis.isEmpty())
|
|
|
|
|
m_supportedAbis = m_targetAbi;
|
|
|
|
|
|
2013-02-07 10:42:24 +01:00
|
|
|
if (m_id.isEmpty())
|
|
|
|
|
std::cerr << "No id given for tool chain." << std::endl;
|
|
|
|
|
if (m_displayName.isEmpty())
|
|
|
|
|
std::cerr << "No name given for tool chain." << std::endl;
|
|
|
|
|
if (m_path.isEmpty())
|
|
|
|
|
std::cerr << "No path given for tool chain." << std::endl;
|
|
|
|
|
if (m_targetAbi.isEmpty())
|
|
|
|
|
std::cerr << "No target abi given for tool chain." << std::endl;
|
|
|
|
|
|
2012-09-18 15:58:07 +02:00
|
|
|
return !m_id.isEmpty() && !m_displayName.isEmpty() && !m_path.isEmpty() && !m_targetAbi.isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AddToolChainOperation::execute() const
|
|
|
|
|
{
|
2016-07-15 11:40:56 +02:00
|
|
|
QVariantMap map = load("ToolChains");
|
2012-09-18 15:58:07 +02:00
|
|
|
if (map.isEmpty())
|
|
|
|
|
map = initializeToolChains();
|
|
|
|
|
|
2013-02-22 13:57:00 +01:00
|
|
|
QVariantMap result = addToolChain(map, m_id, m_displayName, m_path, m_targetAbi, m_supportedAbis, m_extra);
|
2013-05-16 15:47:47 +02:00
|
|
|
if (result.isEmpty() || map == result)
|
2013-07-08 08:35:18 +02:00
|
|
|
return 2;
|
2012-09-18 15:58:07 +02:00
|
|
|
|
2016-07-15 11:40:56 +02:00
|
|
|
return save(result, "ToolChains") ? 0 : 3;
|
2012-09-18 15:58:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
bool AddToolChainOperation::test() const
|
|
|
|
|
{
|
|
|
|
|
QVariantMap map = initializeToolChains();
|
|
|
|
|
|
|
|
|
|
// Add toolchain:
|
2016-07-15 11:40:56 +02:00
|
|
|
map = addToolChain(map, "testId", "name", "/tmp/test", "test-abi", "test-abi,test-abi2",
|
|
|
|
|
KeyValuePairList() << KeyValuePair("ExtraKey", QVariant("ExtraValue")));
|
|
|
|
|
if (map.value(COUNT).toInt() != 1
|
|
|
|
|
|| !map.contains(QString::fromLatin1(PREFIX) + '0'))
|
2012-09-18 15:58:07 +02:00
|
|
|
return false;
|
2016-07-15 11:40:56 +02:00
|
|
|
QVariantMap tcData = map.value(QString::fromLatin1(PREFIX) + '0').toMap();
|
2012-09-18 15:58:07 +02:00
|
|
|
if (tcData.count() != 7
|
2016-07-15 11:40:56 +02:00
|
|
|
|| tcData.value(ID).toString() != "testId"
|
|
|
|
|
|| tcData.value(DISPLAYNAME).toString() != "name"
|
|
|
|
|
|| tcData.value(AUTODETECTED).toBool() != true
|
|
|
|
|
|| tcData.value(PATH).toString() != "/tmp/test"
|
|
|
|
|
|| tcData.value(TARGET_ABI).toString() != "test-abi"
|
|
|
|
|
|| tcData.value(SUPPORTED_ABIS).toList().count() != 2
|
|
|
|
|
|| tcData.value("ExtraKey").toString() != "ExtraValue")
|
2012-09-18 15:58:07 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Ignore same Id:
|
2016-07-15 11:40:56 +02:00
|
|
|
QVariantMap unchanged = addToolChain(map, "testId", "name2", "/tmp/test2", "test-abi2", "test-abi2,test-abi3",
|
|
|
|
|
KeyValuePairList() << KeyValuePair("ExtraKey", QVariant("ExtraValue2")));
|
2012-09-18 15:58:07 +02:00
|
|
|
if (!unchanged.isEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Make sure name stays unique:
|
2016-07-15 11:40:56 +02:00
|
|
|
map = addToolChain(map, "{some-tc-id}", "name", "/tmp/test", "test-abi", "test-abi,test-abi2",
|
|
|
|
|
KeyValuePairList() << KeyValuePair("ExtraKey", QVariant("ExtraValue")));
|
|
|
|
|
if (map.value(COUNT).toInt() != 2
|
|
|
|
|
|| !map.contains(QString::fromLatin1(PREFIX) + '0')
|
|
|
|
|
|| !map.contains(QString::fromLatin1(PREFIX) + '1'))
|
2012-09-18 15:58:07 +02:00
|
|
|
return false;
|
2016-07-15 11:40:56 +02:00
|
|
|
tcData = map.value(QString::fromLatin1(PREFIX) + '0').toMap();
|
2012-09-18 15:58:07 +02:00
|
|
|
if (tcData.count() != 7
|
2016-07-15 11:40:56 +02:00
|
|
|
|| tcData.value(ID).toString() != "testId"
|
|
|
|
|
|| tcData.value(DISPLAYNAME).toString() != "name"
|
|
|
|
|
|| tcData.value(AUTODETECTED).toBool() != true
|
|
|
|
|
|| tcData.value(PATH).toString() != "/tmp/test"
|
|
|
|
|
|| tcData.value(TARGET_ABI).toString() != "test-abi"
|
|
|
|
|
|| tcData.value(SUPPORTED_ABIS).toList().count() != 2
|
|
|
|
|
|| tcData.value("ExtraKey").toString() != "ExtraValue")
|
2012-09-18 15:58:07 +02:00
|
|
|
return false;
|
2016-07-15 11:40:56 +02:00
|
|
|
tcData = map.value(QString::fromLatin1(PREFIX) + '1').toMap();
|
2012-09-18 15:58:07 +02:00
|
|
|
if (tcData.count() != 7
|
2016-07-15 11:40:56 +02:00
|
|
|
|| tcData.value(ID).toString() != "{some-tc-id}"
|
|
|
|
|
|| tcData.value(DISPLAYNAME).toString() != "name2"
|
|
|
|
|
|| tcData.value(AUTODETECTED).toBool() != true
|
|
|
|
|
|| tcData.value(PATH).toString() != "/tmp/test"
|
|
|
|
|
|| tcData.value(TARGET_ABI).toString() != "test-abi"
|
|
|
|
|
|| tcData.value(SUPPORTED_ABIS).toList().count() != 2
|
|
|
|
|
|| tcData.value("ExtraKey").toString() != "ExtraValue")
|
2012-09-18 15:58:07 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
QVariantMap AddToolChainOperation::addToolChain(const QVariantMap &map,
|
|
|
|
|
const QString &id, const QString &displayName,
|
|
|
|
|
const QString &path, const QString &abi,
|
|
|
|
|
const QString &supportedAbis, const KeyValuePairList &extra)
|
|
|
|
|
{
|
|
|
|
|
// Sanity check: Does the Id already exist?
|
2014-03-04 11:06:51 +01:00
|
|
|
if (exists(map, id)) {
|
2012-09-18 15:58:07 +02:00
|
|
|
std::cerr << "Error: Id " << qPrintable(id) << " already defined for tool chains." << std::endl;
|
|
|
|
|
return QVariantMap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Find position to insert Tool Chain at:
|
|
|
|
|
bool ok;
|
2016-07-15 11:40:56 +02:00
|
|
|
int count = GetOperation::get(map, COUNT).toInt(&ok);
|
2012-09-18 15:58:07 +02:00
|
|
|
if (!ok || count < 0) {
|
|
|
|
|
std::cerr << "Error: Count found in toolchains file seems wrong." << std::endl;
|
|
|
|
|
return QVariantMap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sanity check: Make sure displayName is unique.
|
2016-07-15 11:40:56 +02:00
|
|
|
QStringList nameKeys = FindKeyOperation::findKey(map, DISPLAYNAME);
|
2012-09-18 15:58:07 +02:00
|
|
|
QStringList nameList;
|
2013-03-11 17:23:55 +01:00
|
|
|
foreach (const QString &nameKey, nameKeys)
|
2012-09-18 15:58:07 +02:00
|
|
|
nameList << GetOperation::get(map, nameKey).toString();
|
|
|
|
|
const QString uniqueName = makeUnique(displayName, nameList);
|
|
|
|
|
|
2016-07-15 11:40:56 +02:00
|
|
|
QVariantMap result = RmKeysOperation::rmKeys(map, { COUNT });
|
2012-09-18 15:58:07 +02:00
|
|
|
|
|
|
|
|
const QString tc = QString::fromLatin1(PREFIX) + QString::number(count);
|
|
|
|
|
|
|
|
|
|
KeyValuePairList data;
|
2016-07-15 11:40:56 +02:00
|
|
|
data << KeyValuePair({ tc, ID }, QVariant(id));
|
|
|
|
|
data << KeyValuePair({ tc, DISPLAYNAME }, QVariant(uniqueName));
|
|
|
|
|
data << KeyValuePair({ tc, AUTODETECTED }, QVariant(true));
|
|
|
|
|
data << KeyValuePair({ tc, PATH }, QVariant(path));
|
|
|
|
|
data << KeyValuePair({ tc, TARGET_ABI }, QVariant(abi));
|
2012-09-18 15:58:07 +02:00
|
|
|
QVariantList abis;
|
2016-07-15 11:40:56 +02:00
|
|
|
QStringList abiStrings = supportedAbis.split(',');
|
2012-09-18 15:58:07 +02:00
|
|
|
foreach (const QString &s, abiStrings)
|
|
|
|
|
abis << QVariant(s);
|
2016-07-15 11:40:56 +02:00
|
|
|
data << KeyValuePair({ tc, SUPPORTED_ABIS }, QVariant(abis));
|
2012-09-18 15:58:07 +02:00
|
|
|
KeyValuePairList tcExtraList;
|
|
|
|
|
foreach (const KeyValuePair &pair, extra)
|
2016-07-15 11:40:56 +02:00
|
|
|
tcExtraList << KeyValuePair(QStringList({ tc }) << pair.key, pair.value);
|
2012-09-18 15:58:07 +02:00
|
|
|
data.append(tcExtraList);
|
2016-07-15 11:40:56 +02:00
|
|
|
data << KeyValuePair(COUNT, QVariant(count + 1));
|
2012-09-18 15:58:07 +02:00
|
|
|
|
|
|
|
|
return AddKeysOperation::addKeys(result, data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap AddToolChainOperation::initializeToolChains()
|
|
|
|
|
{
|
|
|
|
|
QVariantMap map;
|
2016-07-15 11:40:56 +02:00
|
|
|
map.insert(COUNT, 0);
|
|
|
|
|
map.insert(VERSION, 1);
|
2012-09-18 15:58:07 +02:00
|
|
|
return map;
|
|
|
|
|
}
|
2014-03-04 11:06:51 +01:00
|
|
|
|
|
|
|
|
bool AddToolChainOperation::exists(const QVariantMap &map, const QString &id)
|
|
|
|
|
{
|
2015-04-30 12:55:26 +02:00
|
|
|
QStringList valueKeys = FindValueOperation::findValue(map, id);
|
2015-06-03 10:59:38 +02:00
|
|
|
// support old settings using QByteArray for id's
|
|
|
|
|
valueKeys.append(FindValueOperation::findValue(map, id.toUtf8()));
|
2014-03-04 11:06:51 +01:00
|
|
|
|
|
|
|
|
foreach (const QString &k, valueKeys) {
|
2016-07-15 11:40:56 +02:00
|
|
|
if (k.endsWith(QString('/') + ID)) {
|
2014-03-04 11:06:51 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AddToolChainOperation::exists(const QString &id)
|
|
|
|
|
{
|
2016-07-15 11:40:56 +02:00
|
|
|
QVariantMap map = Operation::load("ToolChains");
|
2014-03-04 11:06:51 +01:00
|
|
|
return exists(map, id);
|
|
|
|
|
}
|