forked from qt-creator/qt-creator
ProjectExplorer: Set unique build directory
... after cloning a build configuration. It's very unlikely that the user intends to re-use the same build directory in the new build configuration. Fixes: QTCREATORBUG-24831 Change-Id: I39b7839225e973fea4e16b9b686fbbf9207cb5ae Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -90,18 +90,26 @@ QTCREATOR_UTILS_EXPORT QString expandMacros(const QString &str, AbstractMacroExp
|
||||
|
||||
QTCREATOR_UTILS_EXPORT int parseUsedPortFromNetstatOutput(const QByteArray &line);
|
||||
|
||||
template<typename T, typename Container>
|
||||
T makeUniquelyNumbered(const T &preferred, const Container &reserved)
|
||||
template<typename T>
|
||||
T makeUniquelyNumbered(const T &preferred, const std::function<bool(const T &)> &isOk)
|
||||
{
|
||||
if (!reserved.contains(preferred))
|
||||
if (isOk(preferred))
|
||||
return preferred;
|
||||
int i = 2;
|
||||
T tryName = preferred + QString::number(i);
|
||||
while (reserved.contains(tryName))
|
||||
while (!isOk(tryName))
|
||||
tryName = preferred + QString::number(++i);
|
||||
return tryName;
|
||||
}
|
||||
|
||||
template<typename T, typename Container>
|
||||
T makeUniquelyNumbered(const T &preferred, const Container &reserved)
|
||||
{
|
||||
const std::function<bool(const T &)> isOk
|
||||
= [&reserved](const T &v) { return !reserved.contains(v); };
|
||||
return makeUniquelyNumbered(preferred, isOk);
|
||||
}
|
||||
|
||||
QTCREATOR_UTILS_EXPORT QString formatElapsedTime(qint64 elapsed);
|
||||
|
||||
/* This function is only necessary if you need to match the wildcard expression against a
|
||||
|
@@ -31,7 +31,9 @@
|
||||
#include "projectconfigurationmodel.h"
|
||||
#include "session.h"
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/stringutils.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/buildmanager.h>
|
||||
@@ -49,6 +51,7 @@
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
using namespace ProjectExplorer::Internal;
|
||||
using namespace Utils;
|
||||
|
||||
///
|
||||
// BuildSettingsWidget
|
||||
@@ -251,7 +254,7 @@ QString BuildSettingsWidget::uniqueName(const QString & name)
|
||||
continue;
|
||||
bcNames.append(bc->displayName());
|
||||
}
|
||||
result = Utils::makeUniquelyNumbered(result, bcNames);
|
||||
result = makeUniquelyNumbered(result, bcNames);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -297,6 +300,16 @@ void BuildSettingsWidget::cloneConfiguration()
|
||||
return;
|
||||
|
||||
bc->setDisplayName(name);
|
||||
const std::function<bool(const QString &)> isBuildDirOk = [this](const QString &candidate) {
|
||||
const auto fp = FilePath::fromString(candidate);
|
||||
if (fp.exists())
|
||||
return false;
|
||||
return !anyOf(m_target->buildConfigurations(), [&fp](const BuildConfiguration *bc) {
|
||||
return bc->buildDirectory() == fp; });
|
||||
};
|
||||
bc->setBuildDirectory(FilePath::fromString(makeUniquelyNumbered(
|
||||
bc->buildDirectory().toString(),
|
||||
isBuildDirOk)));
|
||||
m_target->addBuildConfiguration(bc);
|
||||
SessionManager::setActiveBuildConfiguration(m_target, bc, SetActive::Cascade);
|
||||
}
|
||||
|
Reference in New Issue
Block a user