forked from qt-creator/qt-creator
CMake: Do not crash when deleting cmake tools
Do not crash when the cmake tool that was used to parse the project gets removed. Change-Id: Ieda3ae2025dbcfb1f90d9bd01c5f0ed960756c6a Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
@@ -64,7 +64,7 @@ BuildDirManager::~BuildDirManager() = default;
|
|||||||
Utils::FileName BuildDirManager::workDirectory(const BuildDirParameters ¶meters) const
|
Utils::FileName BuildDirManager::workDirectory(const BuildDirParameters ¶meters) const
|
||||||
{
|
{
|
||||||
const Utils::FileName bdir = parameters.buildDirectory;
|
const Utils::FileName bdir = parameters.buildDirectory;
|
||||||
const CMakeTool *cmake = parameters.cmakeTool;
|
const CMakeTool *cmake = parameters.cmakeTool();
|
||||||
if (bdir.exists()) {
|
if (bdir.exists()) {
|
||||||
m_buildDirToTempDir.erase(bdir);
|
m_buildDirToTempDir.erase(bdir);
|
||||||
return bdir;
|
return bdir;
|
||||||
@@ -141,7 +141,7 @@ bool BuildDirManager::hasConfigChanged()
|
|||||||
|
|
||||||
const CMakeConfig currentConfig = takeCMakeConfiguration();
|
const CMakeConfig currentConfig = takeCMakeConfiguration();
|
||||||
|
|
||||||
const CMakeTool *tool = m_parameters.cmakeTool;
|
const CMakeTool *tool = m_parameters.cmakeTool();
|
||||||
QTC_ASSERT(tool, return false); // No cmake... we should not have ended up here in the first place
|
QTC_ASSERT(tool, return false); // No cmake... we should not have ended up here in the first place
|
||||||
const QString extraKitGenerator = m_parameters.extraGenerator;
|
const QString extraKitGenerator = m_parameters.extraGenerator;
|
||||||
const QString mainKitGenerator = m_parameters.generator;
|
const QString mainKitGenerator = m_parameters.generator;
|
||||||
@@ -196,7 +196,7 @@ void BuildDirManager::setParametersAndRequestParse(const BuildDirParameters &par
|
|||||||
int newReaderReparseOptions,
|
int newReaderReparseOptions,
|
||||||
int existingReaderReparseOptions)
|
int existingReaderReparseOptions)
|
||||||
{
|
{
|
||||||
if (!parameters.cmakeTool) {
|
if (!parameters.cmakeTool()) {
|
||||||
TaskHub::addTask(Task::Error,
|
TaskHub::addTask(Task::Error,
|
||||||
tr("The kit needs to define a CMake tool to parse this project."),
|
tr("The kit needs to define a CMake tool to parse this project."),
|
||||||
ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM);
|
ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM);
|
||||||
@@ -240,7 +240,7 @@ void BuildDirManager::becameDirty()
|
|||||||
if (!m_parameters.buildConfiguration || !m_parameters.buildConfiguration->isActive())
|
if (!m_parameters.buildConfiguration || !m_parameters.buildConfiguration->isActive())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const CMakeTool *tool = m_parameters.cmakeTool;
|
const CMakeTool *tool = m_parameters.cmakeTool();
|
||||||
if (!tool->isAutoRun())
|
if (!tool->isAutoRun())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "cmakebuildconfiguration.h"
|
#include "cmakebuildconfiguration.h"
|
||||||
#include "cmakekitinformation.h"
|
#include "cmakekitinformation.h"
|
||||||
|
#include "cmaketoolmanager.h"
|
||||||
|
|
||||||
#include <projectexplorer/kit.h>
|
#include <projectexplorer/kit.h>
|
||||||
#include <projectexplorer/kitinformation.h>
|
#include <projectexplorer/kitinformation.h>
|
||||||
@@ -53,7 +54,7 @@ BuildDirParameters::BuildDirParameters(CMakeBuildConfiguration *bc)
|
|||||||
|
|
||||||
environment = bc->environment();
|
environment = bc->environment();
|
||||||
|
|
||||||
cmakeTool = CMakeKitInformation::cmakeTool(k);
|
cmakeToolId = CMakeKitInformation::cmakeToolId(k);
|
||||||
|
|
||||||
auto tc = ToolChainKitInformation::toolChain(k, Constants::CXX_LANGUAGE_ID);
|
auto tc = ToolChainKitInformation::toolChain(k, Constants::CXX_LANGUAGE_ID);
|
||||||
if (tc)
|
if (tc)
|
||||||
@@ -74,7 +75,12 @@ BuildDirParameters::BuildDirParameters(CMakeBuildConfiguration *bc)
|
|||||||
generatorArguments = CMakeGeneratorKitInformation::generatorArguments(k);
|
generatorArguments = CMakeGeneratorKitInformation::generatorArguments(k);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BuildDirParameters::isValid() const { return buildConfiguration && cmakeTool; }
|
bool BuildDirParameters::isValid() const { return buildConfiguration && cmakeTool(); }
|
||||||
|
|
||||||
|
CMakeTool *BuildDirParameters::cmakeTool() const
|
||||||
|
{
|
||||||
|
return CMakeToolManager::findById(cmakeToolId);
|
||||||
|
}
|
||||||
|
|
||||||
BuildDirParameters::BuildDirParameters(const BuildDirParameters &) = default;
|
BuildDirParameters::BuildDirParameters(const BuildDirParameters &) = default;
|
||||||
|
|
||||||
|
@@ -46,6 +46,7 @@ public:
|
|||||||
BuildDirParameters(const BuildDirParameters &other);
|
BuildDirParameters(const BuildDirParameters &other);
|
||||||
|
|
||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
|
CMakeTool *cmakeTool() const;
|
||||||
|
|
||||||
CMakeBuildConfiguration *buildConfiguration = nullptr;
|
CMakeBuildConfiguration *buildConfiguration = nullptr;
|
||||||
QString projectName;
|
QString projectName;
|
||||||
@@ -54,7 +55,7 @@ public:
|
|||||||
Utils::FileName buildDirectory;
|
Utils::FileName buildDirectory;
|
||||||
Utils::FileName workDirectory; // either buildDirectory or a QTemporaryDirectory!
|
Utils::FileName workDirectory; // either buildDirectory or a QTemporaryDirectory!
|
||||||
Utils::Environment environment;
|
Utils::Environment environment;
|
||||||
CMakeTool *cmakeTool = nullptr;
|
Core::Id cmakeToolId;
|
||||||
|
|
||||||
QByteArray cxxToolChainId;
|
QByteArray cxxToolChainId;
|
||||||
QByteArray cToolChainId;
|
QByteArray cToolChainId;
|
||||||
|
@@ -41,8 +41,9 @@ namespace Internal {
|
|||||||
|
|
||||||
BuildDirReader *BuildDirReader::createReader(const BuildDirParameters &p)
|
BuildDirReader *BuildDirReader::createReader(const BuildDirParameters &p)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(p.isValid() && p.cmakeTool, return nullptr);
|
CMakeTool *cmake = p.cmakeTool();
|
||||||
if (p.cmakeTool->hasServerMode())
|
QTC_ASSERT(p.isValid() && cmake, return nullptr);
|
||||||
|
if (cmake->hasServerMode())
|
||||||
return new ServerModeReader;
|
return new ServerModeReader;
|
||||||
return new TeaLeafReader;
|
return new TeaLeafReader;
|
||||||
}
|
}
|
||||||
|
@@ -83,13 +83,16 @@ Core::Id CMakeKitInformation::id()
|
|||||||
return TOOL_ID;
|
return TOOL_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
CMakeTool *CMakeKitInformation::cmakeTool(const Kit *k)
|
Core::Id CMakeKitInformation::cmakeToolId(const Kit *k)
|
||||||
{
|
{
|
||||||
if (!k)
|
if (!k)
|
||||||
return nullptr;
|
return {};
|
||||||
|
return Core::Id::fromSetting(k->value(TOOL_ID));
|
||||||
|
}
|
||||||
|
|
||||||
const QVariant id = k->value(TOOL_ID);
|
CMakeTool *CMakeKitInformation::cmakeTool(const Kit *k)
|
||||||
return CMakeToolManager::findById(Core::Id::fromSetting(id));
|
{
|
||||||
|
return CMakeToolManager::findById(cmakeToolId(k));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMakeKitInformation::setCMakeTool(Kit *k, const Core::Id id)
|
void CMakeKitInformation::setCMakeTool(Kit *k, const Core::Id id)
|
||||||
|
@@ -43,6 +43,7 @@ public:
|
|||||||
|
|
||||||
static Core::Id id();
|
static Core::Id id();
|
||||||
|
|
||||||
|
static Core::Id cmakeToolId(const ProjectExplorer::Kit *k);
|
||||||
static CMakeTool *cmakeTool(const ProjectExplorer::Kit *k);
|
static CMakeTool *cmakeTool(const ProjectExplorer::Kit *k);
|
||||||
static void setCMakeTool(ProjectExplorer::Kit *k, const Core::Id id);
|
static void setCMakeTool(ProjectExplorer::Kit *k, const Core::Id id);
|
||||||
|
|
||||||
|
@@ -98,13 +98,14 @@ ServerModeReader::~ServerModeReader()
|
|||||||
|
|
||||||
void ServerModeReader::setParameters(const BuildDirParameters &p)
|
void ServerModeReader::setParameters(const BuildDirParameters &p)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(p.cmakeTool, return);
|
CMakeTool *cmake = p.cmakeTool();
|
||||||
|
QTC_ASSERT(cmake, return);
|
||||||
|
|
||||||
BuildDirReader::setParameters(p);
|
BuildDirReader::setParameters(p);
|
||||||
if (!m_cmakeServer) {
|
if (!m_cmakeServer) {
|
||||||
m_cmakeServer.reset(new ServerMode(p.environment,
|
m_cmakeServer.reset(new ServerMode(p.environment,
|
||||||
p.sourceDirectory, p.workDirectory,
|
p.sourceDirectory, p.workDirectory,
|
||||||
p.cmakeTool->cmakeExecutable(),
|
cmake->cmakeExecutable(),
|
||||||
p.generator, p.extraGenerator, p.platform, p.toolset,
|
p.generator, p.extraGenerator, p.platform, p.toolset,
|
||||||
true, 1));
|
true, 1));
|
||||||
connect(m_cmakeServer.get(), &ServerMode::errorOccured,
|
connect(m_cmakeServer.get(), &ServerMode::errorOccured,
|
||||||
@@ -139,15 +140,17 @@ void ServerModeReader::setParameters(const BuildDirParameters &p)
|
|||||||
|
|
||||||
bool ServerModeReader::isCompatible(const BuildDirParameters &p)
|
bool ServerModeReader::isCompatible(const BuildDirParameters &p)
|
||||||
{
|
{
|
||||||
if (!p.cmakeTool)
|
CMakeTool *newCmake = p.cmakeTool();
|
||||||
|
CMakeTool *oldCmake = m_parameters.cmakeTool();
|
||||||
|
if (!newCmake || !oldCmake)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Server mode connection got lost, reset...
|
// Server mode connection got lost, reset...
|
||||||
if (!m_parameters.cmakeTool->cmakeExecutable().isEmpty() && !m_cmakeServer)
|
if (!oldCmake && oldCmake->cmakeExecutable().isEmpty() && !m_cmakeServer)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return p.cmakeTool->hasServerMode()
|
return newCmake->hasServerMode()
|
||||||
&& p.cmakeTool->cmakeExecutable() == m_parameters.cmakeTool->cmakeExecutable()
|
&& newCmake->cmakeExecutable() == oldCmake->cmakeExecutable()
|
||||||
&& p.environment == m_parameters.environment
|
&& p.environment == m_parameters.environment
|
||||||
&& p.generator == m_parameters.generator
|
&& p.generator == m_parameters.generator
|
||||||
&& p.extraGenerator == m_parameters.extraGenerator
|
&& p.extraGenerator == m_parameters.extraGenerator
|
||||||
|
@@ -131,8 +131,8 @@ TeaLeafReader::TeaLeafReader()
|
|||||||
connect(EditorManager::instance(), &EditorManager::aboutToSave,
|
connect(EditorManager::instance(), &EditorManager::aboutToSave,
|
||||||
this, [this](const IDocument *document) {
|
this, [this](const IDocument *document) {
|
||||||
if (m_cmakeFiles.contains(document->filePath())
|
if (m_cmakeFiles.contains(document->filePath())
|
||||||
|| !m_parameters.cmakeTool
|
|| !m_parameters.cmakeTool()
|
||||||
|| !m_parameters.cmakeTool->isAutoRun())
|
|| !m_parameters.cmakeTool()->isAutoRun())
|
||||||
emit dirty();
|
emit dirty();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -154,9 +154,9 @@ TeaLeafReader::~TeaLeafReader()
|
|||||||
|
|
||||||
bool TeaLeafReader::isCompatible(const BuildDirParameters &p)
|
bool TeaLeafReader::isCompatible(const BuildDirParameters &p)
|
||||||
{
|
{
|
||||||
if (!p.cmakeTool)
|
if (!p.cmakeTool())
|
||||||
return false;
|
return false;
|
||||||
return !p.cmakeTool->hasServerMode();
|
return !p.cmakeTool()->hasServerMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TeaLeafReader::resetData()
|
void TeaLeafReader::resetData()
|
||||||
@@ -409,7 +409,8 @@ void TeaLeafReader::cleanUpProcess()
|
|||||||
|
|
||||||
void TeaLeafReader::extractData()
|
void TeaLeafReader::extractData()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_parameters.isValid() && m_parameters.cmakeTool, return);
|
CMakeTool *cmake = m_parameters.cmakeTool();
|
||||||
|
QTC_ASSERT(m_parameters.isValid() && cmake, return);
|
||||||
|
|
||||||
const FileName srcDir = m_parameters.sourceDirectory;
|
const FileName srcDir = m_parameters.sourceDirectory;
|
||||||
const FileName bldDir = m_parameters.workDirectory;
|
const FileName bldDir = m_parameters.workDirectory;
|
||||||
@@ -436,7 +437,7 @@ void TeaLeafReader::extractData()
|
|||||||
// setFolderName
|
// setFolderName
|
||||||
CMakeCbpParser cbpparser;
|
CMakeCbpParser cbpparser;
|
||||||
// Parsing
|
// Parsing
|
||||||
if (!cbpparser.parseCbpFile(m_parameters.cmakeTool->pathMapper(), cbpFile, srcDir))
|
if (!cbpparser.parseCbpFile(cmake->pathMapper(), cbpFile, srcDir))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_projectName = cbpparser.projectName();
|
m_projectName = cbpparser.projectName();
|
||||||
@@ -461,7 +462,8 @@ void TeaLeafReader::extractData()
|
|||||||
|
|
||||||
void TeaLeafReader::startCMake(const QStringList &configurationArguments)
|
void TeaLeafReader::startCMake(const QStringList &configurationArguments)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_parameters.isValid() && m_parameters.cmakeTool, return);
|
CMakeTool *cmake = m_parameters.cmakeTool();
|
||||||
|
QTC_ASSERT(m_parameters.isValid() && cmake, return);
|
||||||
|
|
||||||
const FileName workDirectory = m_parameters.workDirectory;
|
const FileName workDirectory = m_parameters.workDirectory;
|
||||||
QTC_ASSERT(!m_cmakeProcess, return);
|
QTC_ASSERT(!m_cmakeProcess, return);
|
||||||
@@ -506,7 +508,7 @@ void TeaLeafReader::startCMake(const QStringList &configurationArguments)
|
|||||||
TaskHub::clearTasks(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM);
|
TaskHub::clearTasks(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM);
|
||||||
|
|
||||||
MessageManager::write(tr("Running \"%1 %2\" in %3.")
|
MessageManager::write(tr("Running \"%1 %2\" in %3.")
|
||||||
.arg(m_parameters.cmakeTool->cmakeExecutable().toUserOutput())
|
.arg(cmake->cmakeExecutable().toUserOutput())
|
||||||
.arg(args)
|
.arg(args)
|
||||||
.arg(workDirectory.toUserOutput()));
|
.arg(workDirectory.toUserOutput()));
|
||||||
|
|
||||||
@@ -516,7 +518,7 @@ void TeaLeafReader::startCMake(const QStringList &configurationArguments)
|
|||||||
tr("Configuring \"%1\"").arg(m_parameters.projectName),
|
tr("Configuring \"%1\"").arg(m_parameters.projectName),
|
||||||
"CMake.Configure");
|
"CMake.Configure");
|
||||||
|
|
||||||
m_cmakeProcess->setCommand(m_parameters.cmakeTool->cmakeExecutable().toString(), args);
|
m_cmakeProcess->setCommand(cmake->cmakeExecutable().toString(), args);
|
||||||
emit configurationStarted();
|
emit configurationStarted();
|
||||||
m_cmakeProcess->start();
|
m_cmakeProcess->start();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user