aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cmakeprojectmanager
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@qt.io>2020-04-22 11:18:01 +0200
committerTobias Hunger <tobias.hunger@qt.io>2020-04-22 10:38:27 +0000
commitf51f3c897ed34156c652f768ba55a577ff7c87bf (patch)
tree01ad0bf57829485bd3ce2dda8ba596fe1d26837d /src/plugins/cmakeprojectmanager
parent7d3c6f7c02ee52560835f866e3f6a4f47436a3a5 (diff)
CMake: Do not crash without a supported CMake
Do not crash when a CMake < 3.7 (no server-mode and no file-api) is used. Change-Id: I72a4ce6bb81d4fcf3d59508c72e46f422a8a00c0 Reviewed-by: Cristian Adam <cristian.adam@qt.io>
Diffstat (limited to 'src/plugins/cmakeprojectmanager')
-rw-r--r--src/plugins/cmakeprojectmanager/builddirmanager.cpp7
-rw-r--r--src/plugins/cmakeprojectmanager/builddirreader.cpp7
-rw-r--r--src/plugins/cmakeprojectmanager/cmaketool.cpp37
-rw-r--r--src/plugins/cmakeprojectmanager/cmaketool.h2
4 files changed, 30 insertions, 23 deletions
diff --git a/src/plugins/cmakeprojectmanager/builddirmanager.cpp b/src/plugins/cmakeprojectmanager/builddirmanager.cpp
index 44aec2346e..2e99326d94 100644
--- a/src/plugins/cmakeprojectmanager/builddirmanager.cpp
+++ b/src/plugins/cmakeprojectmanager/builddirmanager.cpp
@@ -143,6 +143,13 @@ void BuildDirManager::updateReaderType(const BuildDirParameters &p,
}
m_reader = BuildDirReader::createReader(p);
+ if (!m_reader) {
+ TaskHub::addTask(BuildSystemTask(
+ Task::Error,
+ tr("The kit does not define a valid CMake tool to parse this project with.")));
+ return;
+ }
+
connect(m_reader.get(),
&BuildDirReader::configurationStarted,
this,
diff --git a/src/plugins/cmakeprojectmanager/builddirreader.cpp b/src/plugins/cmakeprojectmanager/builddirreader.cpp
index 031f1ec6c7..091e6d1a6f 100644
--- a/src/plugins/cmakeprojectmanager/builddirreader.cpp
+++ b/src/plugins/cmakeprojectmanager/builddirreader.cpp
@@ -44,13 +44,14 @@ std::unique_ptr<BuildDirReader> BuildDirReader::createReader(const BuildDirParam
CMakeTool *cmake = p.cmakeTool();
QTC_ASSERT(p.isValid() && cmake, return {});
- switch (cmake->readerType()) {
+ auto type = cmake->readerType();
+ if (!type)
+ return {};
+ switch (type.value()) {
case CMakeTool::FileApi:
return std::make_unique<FileApiReader>();
case CMakeTool::ServerMode:
return std::make_unique<ServerModeReader>();
- default:
- return {};
}
}
diff --git a/src/plugins/cmakeprojectmanager/cmaketool.cpp b/src/plugins/cmakeprojectmanager/cmaketool.cpp
index 8c77d3bccd..f487734b3d 100644
--- a/src/plugins/cmakeprojectmanager/cmaketool.cpp
+++ b/src/plugins/cmakeprojectmanager/cmaketool.cpp
@@ -69,10 +69,11 @@ static bool ignoreFileApi()
static Utils::optional<CMakeTool::ReaderType> readerTypeFromString(const QString &input)
{
+ // Do not try to be clever here, just use whatever is in the string!
if (input == READER_TYPE_SERVERMODE)
return CMakeTool::ServerMode;
if (input == READER_TYPE_FILEAPI)
- return ignoreFileApi() ? CMakeTool::ServerMode : CMakeTool::FileApi;
+ return CMakeTool::FileApi;
return {};
}
@@ -84,7 +85,6 @@ static QString readerTypeToString(const CMakeTool::ReaderType &type)
case CMakeTool::FileApi:
return QString(READER_TYPE_FILEAPI);
}
- return QString("<INVALID>");
}
// --------------------------------------------------------------------
@@ -120,9 +120,10 @@ public:
///////////////////////////
// CMakeTool
///////////////////////////
-CMakeTool::CMakeTool(Detection d, const Core::Id &id) :
- m_id(id), m_isAutoDetected(d == AutoDetection),
- m_introspection(std::make_unique<Internal::IntrospectionData>())
+CMakeTool::CMakeTool(Detection d, const Core::Id &id)
+ : m_id(id)
+ , m_isAutoDetected(d == AutoDetection)
+ , m_introspection(std::make_unique<Internal::IntrospectionData>())
{
QTC_ASSERT(m_id.isValid(), m_id = Core::Id::fromString(QUuid::createUuid().toString()));
}
@@ -198,7 +199,7 @@ bool CMakeTool::isValid() const
if (!m_introspection->m_didAttemptToRun)
supportedGenerators();
- return m_introspection->m_didRun && (hasFileApi() || hasServerMode());
+ return m_introspection->m_didRun && readerType().has_value();
}
Utils::SynchronousProcessResponse CMakeTool::run(const QStringList &args, int timeoutS) const
@@ -223,7 +224,7 @@ QVariantMap CMakeTool::toMap() const
data.insert(CMAKE_INFORMATION_QCH_FILE_PATH, m_qchFilePath.toString());
data.insert(CMAKE_INFORMATION_AUTORUN, m_isAutoRun);
data.insert(CMAKE_INFORMATION_AUTO_CREATE_BUILD_DIRECTORY, m_autoCreateBuildDirectory);
- if (m_readerType.has_value())
+ if (m_readerType)
data.insert(CMAKE_INFORMATION_READERTYPE,
Internal::readerTypeToString(m_readerType.value()));
data.insert(CMAKE_INFORMATION_AUTODETECTED, m_isAutoDetected);
@@ -368,19 +369,17 @@ CMakeTool::PathMapper CMakeTool::pathMapper() const
return [](const Utils::FilePath &fn) { return fn; };
}
-CMakeTool::ReaderType CMakeTool::readerType() const
+Utils::optional<CMakeTool::ReaderType> CMakeTool::readerType() const
{
- if (!m_readerType.has_value()) {
- // Find best possible reader type:
- if (hasFileApi()) {
- if (hasServerMode() && Internal::ignoreFileApi())
- return ServerMode; // We were asked to fall back to server mode
- return FileApi;
- }
- if (hasServerMode())
- return ServerMode;
- }
- return m_readerType.value();
+ if (m_readerType)
+ return m_readerType; // Allow overriding the auto-detected value via .user files
+
+ // Find best possible reader type:
+ if (hasFileApi() && !Internal::ignoreFileApi())
+ return FileApi;
+ if (hasServerMode())
+ return ServerMode;
+ return {};
}
Utils::FilePath CMakeTool::searchQchFile(const Utils::FilePath &executable)
diff --git a/src/plugins/cmakeprojectmanager/cmaketool.h b/src/plugins/cmakeprojectmanager/cmaketool.h
index 40a79071cf..1d7bcde82e 100644
--- a/src/plugins/cmakeprojectmanager/cmaketool.h
+++ b/src/plugins/cmakeprojectmanager/cmaketool.h
@@ -110,7 +110,7 @@ public:
void setPathMapper(const PathMapper &includePathMapper);
PathMapper pathMapper() const;
- ReaderType readerType() const;
+ Utils::optional<ReaderType> readerType() const;
static Utils::FilePath searchQchFile(const Utils::FilePath &executable);