CMake: Store pointer to CMakeProject in BuildDirManager

Use this back-pointer to validate the buildconfiguration.

Use the validated buildconfiguration consistently. In theory
the buildconfiguration is valid at all times (since deleting
a buildconfiguration will trigger an update to the parameters
in BuildDirManager), but better be safe.

Change-Id: I614d9ce16e4974a9437a2f44756f01c71a5ede13
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Tobias Hunger
2019-06-06 13:38:28 +02:00
parent daaef73682
commit 08d905ae3d
3 changed files with 34 additions and 23 deletions

View File

@@ -82,7 +82,8 @@ static CMakeBuildConfiguration *activeBc(const CMakeProject *p)
\class CMakeProject
*/
CMakeProject::CMakeProject(const FilePath &fileName) : Project(Constants::CMAKEMIMETYPE, fileName),
m_cppCodeModelUpdater(new CppTools::CppProjectUpdater)
m_cppCodeModelUpdater(new CppTools::CppProjectUpdater),
m_buildDirManager(this)
{
setId(CMakeProjectManager::Constants::CMAKEPROJECT_ID);
setProjectLanguages(Core::Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
@@ -100,16 +101,16 @@ CMakeProject::CMakeProject(const FilePath &fileName) : Project(Constants::CMAKEM
this, &CMakeProject::handleReparseRequest);
connect(&m_buildDirManager, &BuildDirManager::dataAvailable,
this, [this]() {
CMakeBuildConfiguration *bc = activeBc(this);
if (bc && bc == m_buildDirManager.buildConfiguration()) {
CMakeBuildConfiguration *bc = m_buildDirManager.buildConfiguration();
if (bc) {
bc->clearError();
handleParsingSuccess(bc);
}
});
connect(&m_buildDirManager, &BuildDirManager::errorOccured,
this, [this](const QString &msg) {
CMakeBuildConfiguration *bc = activeBc(this);
if (bc && bc == m_buildDirManager.buildConfiguration()) {
CMakeBuildConfiguration *bc = m_buildDirManager.buildConfiguration();
if (bc) {
bc->setError(msg);
bc->setConfigurationFromCMake(m_buildDirManager.takeCMakeConfiguration());
handleParsingError(bc);
@@ -117,8 +118,8 @@ CMakeProject::CMakeProject(const FilePath &fileName) : Project(Constants::CMAKEM
});
connect(&m_buildDirManager, &BuildDirManager::parsingStarted,
this, [this]() {
CMakeBuildConfiguration *bc = activeBc(this);
if (bc && bc == m_buildDirManager.buildConfiguration())
CMakeBuildConfiguration *bc = m_buildDirManager.buildConfiguration();
if (bc)
bc->clearError(CMakeBuildConfiguration::ForceEnabledChanged::True);
});
@@ -186,7 +187,7 @@ CMakeProject::CMakeProject(const FilePath &fileName) : Project(Constants::CMAKEM
subscribeSignal(&CMakeBuildConfiguration::buildDirectoryChanged, this, [this]() {
auto senderBc = qobject_cast<CMakeBuildConfiguration *>(sender());
if (senderBc && senderBc->isActive() && senderBc == m_buildDirManager.buildConfiguration()) {
if (senderBc && senderBc == m_buildDirManager.buildConfiguration()) {
// The build directory of our BC has changed:
// * Error out if the reader updates, cannot happen since all BCs share a target/kit.
// * run cmake without configuration arguments if the reader stays
@@ -201,7 +202,7 @@ CMakeProject::CMakeProject(const FilePath &fileName) : Project(Constants::CMAKEM
subscribeSignal(&CMakeBuildConfiguration::configurationForCMakeChanged, this, [this]() {
auto senderBc = qobject_cast<CMakeBuildConfiguration *>(sender());
if (senderBc && senderBc->isActive() && senderBc == m_buildDirManager.buildConfiguration()) {
if (senderBc && senderBc == m_buildDirManager.buildConfiguration()) {
// The CMake configuration has changed on our BC:
// * Error out if the reader updates, cannot happen since all BCs share a target/kit.
// * run cmake with configuration arguments if the reader stays
@@ -565,7 +566,6 @@ void CMakeProject::handleParsingError(CMakeBuildConfiguration *bc)
combineScanAndParse(bc);
}
void CMakeProject::combineScanAndParse(CMakeBuildConfiguration *bc)
{
QTC_ASSERT(bc && bc->isActive(), return);