Commit 6d9ff690 authored by Tobias Hunger's avatar Tobias Hunger

ToolChainManager: Use partition in ToolChainManager

Change-Id: I4a1376f1ed4ffea83bbd693b3bc1e8fd284771a7
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 7d4078b9
...@@ -46,6 +46,8 @@ ...@@ -46,6 +46,8 @@
#include <QDir> #include <QDir>
#include <QSettings> #include <QSettings>
#include <tuple>
static const char TOOLCHAIN_DATA_KEY[] = "ToolChain."; static const char TOOLCHAIN_DATA_KEY[] = "ToolChain.";
static const char TOOLCHAIN_COUNT_KEY[] = "ToolChain.Count"; static const char TOOLCHAIN_COUNT_KEY[] = "ToolChain.Count";
static const char TOOLCHAIN_FILE_VERSION_KEY[] = "Version"; static const char TOOLCHAIN_FILE_VERSION_KEY[] = "Version";
...@@ -196,11 +198,9 @@ static QList<ToolChain *> subtractById(const QList<ToolChain *> &a, const QList< ...@@ -196,11 +198,9 @@ static QList<ToolChain *> subtractById(const QList<ToolChain *> &a, const QList<
}); });
} }
static QList<ToolChain *> intersectByEqual(const QList<ToolChain *> &a, const QList<ToolChain *> &b) static bool containsByEqual(const QList<ToolChain *> &a, const ToolChain *atc)
{ {
return Utils::filtered(a, [&b](ToolChain *atc) { return Utils::anyOf(a, [atc](ToolChain *btc) { return *atc == *btc; });
return Utils::anyOf(b, [atc](ToolChain *btc) { return *atc == *btc; });
});
} }
static QList<ToolChain *> makeUnique(const QList<ToolChain *> &a) static QList<ToolChain *> makeUnique(const QList<ToolChain *> &a)
...@@ -223,22 +223,20 @@ static ToolChainOperations mergeToolChainLists(const QList<ToolChain *> &systemF ...@@ -223,22 +223,20 @@ static ToolChainOperations mergeToolChainLists(const QList<ToolChain *> &systemF
const QList<ToolChain *> &userFileTcs, const QList<ToolChain *> &userFileTcs,
const QList<ToolChain *> &autodetectedTcs) const QList<ToolChain *> &autodetectedTcs)
{ {
const QList<ToolChain *> manualUserTcs // Remove systemFileTcs from autodetectedUserFileTcs based on id-matches:
= Utils::filtered(userFileTcs, [](ToolChain *t) { return !t->isAutoDetected(); }); QList<ToolChain *> manualUserFileTcs;
QList<ToolChain *> autodetectedUserFileTcs;
// Remove systemFileTcs from autodetectedUserTcs based on id-matches: std::tie(autodetectedUserFileTcs, manualUserFileTcs)
const QList<ToolChain *> autodetectedUserFileTcs = Utils::partition(userFileTcs, &ToolChain::isAutoDetected);
= Utils::filtered(userFileTcs, &ToolChain::isAutoDetected);
const QList<ToolChain *> autodetectedUserTcs = subtractById(autodetectedUserFileTcs, systemFileTcs); const QList<ToolChain *> autodetectedUserTcs = subtractById(autodetectedUserFileTcs, systemFileTcs);
// Calculate a set of Tcs that were detected before (and saved to userFile) and that // Calculate a set of Tcs that were detected before (and saved to userFile) and that
// got re-detected again. Take the userTcs (to keep Ids) over the same in autodetectedTcs. // got re-detected again. Take the userTcs (to keep Ids) over the same in autodetectedTcs.
const QList<ToolChain *> redetectedUserTcs QList<ToolChain *> redetectedUserTcs;
= intersectByEqual(autodetectedUserTcs, autodetectedTcs); QList<ToolChain *> notRedetectedUserTcs;
std::tie(redetectedUserTcs, notRedetectedUserTcs)
// Remove redetected tcs from autodetectedUserTcs: = Utils::partition(autodetectedUserTcs,
const QList<ToolChain *> notRedetectedUserTcs [&autodetectedTcs](ToolChain *tc) { return containsByEqual(autodetectedTcs, tc); });
= subtractByPointerEqual(autodetectedUserTcs, redetectedUserTcs);
// Remove redetected tcs from autodetectedTcs: // Remove redetected tcs from autodetectedTcs:
const QList<ToolChain *> newlyAutodetectedTcs const QList<ToolChain *> newlyAutodetectedTcs
...@@ -248,12 +246,12 @@ static ToolChainOperations mergeToolChainLists(const QList<ToolChain *> &systemF ...@@ -248,12 +246,12 @@ static ToolChainOperations mergeToolChainLists(const QList<ToolChain *> &systemF
= Utils::filtered(notRedetectedUserTcs, &ToolChain::isValid); = Utils::filtered(notRedetectedUserTcs, &ToolChain::isValid);
const QList<ToolChain *> validManualUserTcs const QList<ToolChain *> validManualUserTcs
= Utils::filtered(manualUserTcs, &ToolChain::isValid); = Utils::filtered(manualUserFileTcs, &ToolChain::isValid);
ToolChainOperations result; ToolChainOperations result;
result.toDemote = notRedetectedButValidUserTcs; result.toDemote = notRedetectedButValidUserTcs;
result.toRegister = result.toDemote + systemFileTcs + redetectedUserTcs + newlyAutodetectedTcs result.toRegister = systemFileTcs + validManualUserTcs + result.toDemote // manual TCs
+ validManualUserTcs; + redetectedUserTcs + newlyAutodetectedTcs; // auto TCs
result.toDelete = makeUnique(subtractByPointerEqual(systemFileTcs + userFileTcs + autodetectedTcs, result.toDelete = makeUnique(subtractByPointerEqual(systemFileTcs + userFileTcs + autodetectedTcs,
result.toRegister)); result.toRegister));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment