forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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,
|
||||
|
@@ -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 {};
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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)
|
||||
|
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user