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