From 5f6a3f90fb8dc8f125dfa13896724e8a682bfcc5 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Thu, 17 Nov 2016 12:39:48 +0100 Subject: [PATCH] SDKtool: Add rmCMake operation Task-number: QTCREATORBUG-17290 Change-Id: I17363e44614aebcc06786b791249ce9468b37eb4 Reviewed-by: Tim Jenssen --- src/tools/sdktool/main.cpp | 3 + src/tools/sdktool/rmcmakeoperation.cpp | 157 +++++++++++++++++++++++++ src/tools/sdktool/rmcmakeoperation.h | 51 ++++++++ src/tools/sdktool/sdktool.pro | 2 + src/tools/sdktool/sdktool.qbs | 1 + 5 files changed, 214 insertions(+) create mode 100644 src/tools/sdktool/rmcmakeoperation.cpp create mode 100644 src/tools/sdktool/rmcmakeoperation.h diff --git a/src/tools/sdktool/main.cpp b/src/tools/sdktool/main.cpp index 6e7ebc1f367..bf8e51972bc 100644 --- a/src/tools/sdktool/main.cpp +++ b/src/tools/sdktool/main.cpp @@ -37,6 +37,7 @@ #include "findkeyoperation.h" #include "findvalueoperation.h" #include "getoperation.h" +#include "rmcmakeoperation.h" #include "rmdebuggeroperation.h" #include "rmdeviceoperation.h" #include "rmkeysoperation.h" @@ -185,6 +186,8 @@ int main(int argc, char *argv[]) << new AddKitOperation << new GetOperation + + << new RmCMakeOperation << new RmKitOperation << new RmDebuggerOperation << new RmDeviceOperation diff --git a/src/tools/sdktool/rmcmakeoperation.cpp b/src/tools/sdktool/rmcmakeoperation.cpp new file mode 100644 index 00000000000..0da4651ad3c --- /dev/null +++ b/src/tools/sdktool/rmcmakeoperation.cpp @@ -0,0 +1,157 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 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. +** +** 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. +** +****************************************************************************/ + +#include "rmcmakeoperation.h" + +#include "addkeysoperation.h" +#include "addcmakeoperation.h" +#include "findkeyoperation.h" +#include "findvalueoperation.h" +#include "getoperation.h" +#include "rmkeysoperation.h" + +#include + +// CMake file stuff: +const char COUNT[] = "CMakeTools.Count"; +const char PREFIX[] = "CMakeTools."; + +// CMake: +const char ID[] = "Id"; + +QString RmCMakeOperation::name() const +{ + return QString("rmCMake"); +} + +QString RmCMakeOperation::helpText() const +{ + return QString("remove a cmake tool from Qt Creator"); +} + +QString RmCMakeOperation::argumentsHelpText() const +{ + return QString(" --id The id of the cmake tool to remove.\n"); +} + +bool RmCMakeOperation::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(); + + if (current == "--id") { + if (next.isNull()) { + std::cerr << "No parameter for --id given." << std::endl << std::endl; + return false; + } + ++i; // skip next; + m_id = next; + continue; + } + } + + if (m_id.isEmpty()) + std::cerr << "No id given." << std::endl << std::endl; + + return !m_id.isEmpty(); +} + +int RmCMakeOperation::execute() const +{ + QVariantMap map = load("cmaketools"); + if (map.isEmpty()) + return 0; + + QVariantMap result = rmCMake(map, m_id); + if (result == map) + return 2; + + return save(result, "cmaketools") ? 0 : 3; +} + +#ifdef WITH_TESTS +bool RmCMakeOperation::test() const +{ + // Add cmakes: + QVariantMap map = AddCMakeOperation::initializeCMake(); + map = AddCMakeOperation::addCMake(map, "testId", "name", "/tmp/test", + KeyValuePairList({ KeyValuePair("ExtraKey", QVariant("ExtraValue")) })); + map = AddCMakeOperation::addCMake(map, "testId2", "other name", "/tmp/test2", KeyValuePairList()); + + QVariantMap result = rmCMake(QVariantMap(), "nonexistent"); + if (!result.isEmpty()) + return false; + + result = rmCMake(map, "nonexistent"); + if (result != map) + return false; + + result = rmCMake(map, "testId2"); + if (result == map + || result.value(COUNT, 0).toInt() != 1 + || !result.contains("CMake.0") || result.value("CMake.0") != map.value("CMake.0")) + return false; + + result = rmCMake(map, "testId"); + if (result == map + || result.value(COUNT, 0).toInt() != 1 + || !result.contains("CMake.0") || result.value("CMake.0") != map.value("CMake.1")) + return false; + + result = rmCMake(result, "testId2"); + if (result == map + || result.value(COUNT, 0).toInt() != 0) + return false; + + return true; +} +#endif + +QVariantMap RmCMakeOperation::rmCMake(const QVariantMap &map, const QString &id) +{ + // Find count of cmakes: + bool ok; + int count = GetOperation::get(map, COUNT).toInt(&ok); + if (!ok || count < 0) { + std::cerr << "Error: Count found in cmake tools file seems wrong." << std::endl; + return map; + } + + QVariantList cmList; + for (int i = 0; i < count; ++i) { + QVariantMap cmData = GetOperation::get(map, QString::fromLatin1(PREFIX) + QString::number(i)).toMap(); + if (cmData.value(ID).toString() != id) + cmList.append(cmData); + } + + QVariantMap newMap = AddCMakeOperation::initializeCMake(); + for (int i = 0; i < cmList.count(); ++i) + newMap.insert(QString::fromLatin1(PREFIX) + QString::number(i), cmList.at(i)); + newMap.insert(COUNT, cmList.count()); + + return newMap; +} + diff --git a/src/tools/sdktool/rmcmakeoperation.h b/src/tools/sdktool/rmcmakeoperation.h new file mode 100644 index 00000000000..1a292a3fd6e --- /dev/null +++ b/src/tools/sdktool/rmcmakeoperation.h @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 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. +** +** 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. +** +****************************************************************************/ + +#pragma once + +#include "operation.h" + +#include + +class RmCMakeOperation : public Operation +{ +public: + QString name() const; + QString helpText() const; + QString argumentsHelpText() const; + + bool setArguments(const QStringList &args); + + int execute() const; + +#ifdef WITH_TESTS + bool test() const; +#endif + + static QVariantMap rmCMake(const QVariantMap &map, const QString &id); + +private: + QString m_id; +}; diff --git a/src/tools/sdktool/sdktool.pro b/src/tools/sdktool/sdktool.pro index f862783f6c9..3721a8d8278 100644 --- a/src/tools/sdktool/sdktool.pro +++ b/src/tools/sdktool/sdktool.pro @@ -20,6 +20,7 @@ SOURCES += \ findvalueoperation.cpp \ getoperation.cpp \ operation.cpp \ + rmcmakeoperation.cpp \ rmdebuggeroperation.cpp \ rmdeviceoperation.cpp \ rmkeysoperation.cpp \ @@ -40,6 +41,7 @@ HEADERS += \ findvalueoperation.h \ getoperation.h \ operation.h \ + rmcmakeoperation.h \ rmdebuggeroperation.h \ rmdeviceoperation.h \ rmkeysoperation.h \ diff --git a/src/tools/sdktool/sdktool.qbs b/src/tools/sdktool/sdktool.qbs index f51667e1ba0..adce7cda83d 100644 --- a/src/tools/sdktool/sdktool.qbs +++ b/src/tools/sdktool/sdktool.qbs @@ -33,6 +33,7 @@ QtcTool { "main.cpp", "operation.cpp", "operation.h", + "rmcmakeoperation.cpp", "rmcmakeoperation.h", "rmdebuggeroperation.cpp", "rmdebuggeroperation.h", "rmdeviceoperation.cpp", "rmdeviceoperation.h", "rmkeysoperation.cpp",