Docker: Rework auto-detection and removal of kit items

- Use more uniform messages for the different kinds of items
- Remove all auto-detected items

Change-Id: I0b0df0bca484337039432b163bd8e19593b1cd22
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-07-13 13:05:36 +02:00
parent 5d17ff7a67
commit f8c7d2e848
11 changed files with 143 additions and 41 deletions

View File

@@ -277,9 +277,10 @@ void CMakeKitAspect::setup(Kit *k)
return;
// Look for a suitable auto-detected one:
const QString id = k->autoDetectionSource();
const QString kitSource = k->autoDetectionSource();
for (CMakeTool *tool : CMakeToolManager::cmakeTools()) {
if (tool->detectionSource() == id) {
const QString toolSource = tool->detectionSource();
if (!toolSource.isEmpty() && toolSource == kitSource) {
setCMakeTool(k, tool->id());
return;
}
@@ -1043,8 +1044,6 @@ CMakeConfig CMakeConfigurationKitAspect::defaultConfiguration(const Kit *k)
QVariant CMakeConfigurationKitAspect::defaultValue(const Kit *k) const
{
Q_UNUSED(k)
// FIXME: Convert preload scripts
CMakeConfig config = defaultConfiguration(k);
const QStringList tmp

View File

@@ -110,6 +110,7 @@ public:
, m_executable(item->filePath())
, m_qchFile(item->qchFilePath())
, m_versionDisplay(item->versionDisplay())
, m_detectionSource(item->detectionSource())
, m_isAutoRun(item->isAutoRun())
, m_autodetected(item->isAutoDetected())
, m_isSupported(item->hasFileApi())
@@ -145,9 +146,10 @@ public:
cmake.setFilePath(m_executable);
m_isSupported = cmake.hasFileApi();
m_tooltip = tr("Version: %1<br>Supports fileApi: %2")
.arg(cmake.versionDisplay())
.arg(cmake.hasFileApi() ? tr("yes") : tr("no"));
m_tooltip = tr("Version: %1").arg(cmake.versionDisplay());
m_tooltip += "<br>" + tr("Supports fileApi: %1").arg(m_isSupported ? tr("yes") : tr("no"));
m_tooltip += "<br>" + tr("Detection source: \"%1\"").arg(m_detectionSource);
m_versionDisplay = cmake.versionDisplay();
}
@@ -223,6 +225,7 @@ public:
FilePath m_executable;
FilePath m_qchFile;
QString m_versionDisplay;
QString m_detectionSource;
bool m_isAutoRun = true;
bool m_pathExists = false;
bool m_pathIsFile = false;
@@ -362,6 +365,7 @@ void CMakeToolItemModel::apply()
cmake->setDisplayName(item->m_name);
cmake->setFilePath(item->m_executable);
cmake->setQchFilePath(item->m_qchFile);
cmake->setDetectionSource(item->m_detectionSource);
cmake->setAutorun(item->m_isAutoRun);
} else {
toRegister.append(item);
@@ -375,6 +379,7 @@ void CMakeToolItemModel::apply()
cmake->setDisplayName(item->m_name);
cmake->setFilePath(item->m_executable);
cmake->setQchFilePath(item->m_qchFile);
cmake->setDetectionSource(item->m_detectionSource);
if (!CMakeToolManager::registerCMakeTool(std::move(cmake)))
item->m_changed = true;
}

View File

@@ -53,6 +53,7 @@ const char CMAKE_INFORMATION_QCH_FILE_PATH[] = "QchFile";
// obsolete since Qt Creator 5. Kept for backward compatibility
const char CMAKE_INFORMATION_AUTO_CREATE_BUILD_DIRECTORY[] = "AutoCreateBuildDirectory";
const char CMAKE_INFORMATION_AUTODETECTED[] = "AutoDetected";
const char CMAKE_INFORMATION_DETECTIONSOURCE[] = "DetectionSource";
const char CMAKE_INFORMATION_READERTYPE[] = "ReaderType";
bool CMakeTool::Generator::matches(const QString &n, const QString &ex) const
@@ -132,6 +133,7 @@ CMakeTool::CMakeTool(const QVariantMap &map, bool fromSdk) :
//loading a CMakeTool from SDK is always autodetection
if (!fromSdk)
m_isAutoDetected = map.value(CMAKE_INFORMATION_AUTODETECTED, false).toBool();
m_detectionSource = map.value(CMAKE_INFORMATION_DETECTIONSOURCE).toString();
setFilePath(FilePath::fromString(map.value(CMAKE_INFORMATION_COMMAND).toString()));
@@ -209,6 +211,7 @@ QVariantMap CMakeTool::toMap() const
data.insert(CMAKE_INFORMATION_READERTYPE,
Internal::readerTypeToString(m_readerType.value()));
data.insert(CMAKE_INFORMATION_AUTODETECTED, m_isAutoDetected);
data.insert(CMAKE_INFORMATION_DETECTIONSOURCE, m_detectionSource);
return data;
}

View File

@@ -122,6 +122,8 @@ private:
void fetchFromCapabilities() const;
void parseFromCapabilities(const QString &input) const;
// Note: New items here need also be handled in CMakeToolItemModel::apply()
// FIXME: Use a saner approach.
Utils::Id m_id;
QString m_displayName;
Utils::FilePath m_executable;

View File

@@ -184,14 +184,14 @@ void CMakeToolManager::autoDetectCMakeForDevice(const FilePath &deviceRoot,
const QString &detectionSource,
QString *logMessage)
{
QStringList messages;
QStringList messages{tr("Searching CMake binaries...")};
const FilePaths candidates = {FilePath::fromString("cmake").onDevice(deviceRoot)};
const Environment env = deviceRoot.deviceEnvironment();
for (const FilePath &candidate : candidates) {
const FilePath cmake = candidate.searchOnDevice(env.path());
if (!cmake.isEmpty()) {
registerCMakeByPath(cmake, detectionSource);
messages.append(tr("Found CMake binary: %1").arg(cmake.toUserOutput()));
messages.append(tr("Found \"%1\"").arg(cmake.toUserOutput()));
}
}
if (logMessage)
@@ -209,11 +209,28 @@ void CMakeToolManager::registerCMakeByPath(const FilePath &cmakePath, const QStr
auto newTool = std::make_unique<CMakeTool>(CMakeTool::ManualDetection, id);
newTool->setFilePath(cmakePath);
newTool->setDisplayName(cmakePath.toUserOutput());
newTool->setDetectionSource(detectionSource);
newTool->setDisplayName(cmakePath.toUserOutput());
registerCMakeTool(std::move(newTool));
}
void CMakeToolManager::removeDetectedCMake(const QString &detectionSource, QString *logMessage)
{
QStringList logMessages{tr("Removing CMake entries...")};
while (true) {
auto toRemove = Utils::take(d->m_cmakeTools, Utils::equal(&CMakeTool::detectionSource, detectionSource));
if (!toRemove.has_value())
break;
logMessages.append(tr("Removed \"%1\"").arg((*toRemove)->displayName()));
emit m_instance->cmakeRemoved((*toRemove)->id());
}
ensureDefaultCMakeToolIsValid();
updateDocumentation();
if (logMessage)
*logMessage = logMessages.join('\n');
}
void CMakeToolManager::notifyAboutUpdate(CMakeTool *tool)
{
if (!tool || !Utils::contains(d->m_cmakeTools, tool))

View File

@@ -68,6 +68,7 @@ public slots:
QString *logMessage);
void registerCMakeByPath(const Utils::FilePath &cmakePath,
const QString &detectionSource);
void removeDetectedCMake(const QString &detectionSource, QString *logMessage);
signals:
void cmakeAdded (const Utils::Id &id);