diff options
author | Christian Kandeler <[email protected]> | 2021-05-07 16:10:07 +0200 |
---|---|---|
committer | Christian Kandeler <[email protected]> | 2021-08-13 12:35:49 +0000 |
commit | 33108795d6b2dd1e91942efb3c1c27ad23342295 (patch) | |
tree | 084d21ac56db3c55c84f242acc8400f2e68cd81c /src/plugins/autotest | |
parent | 3143ba79e3d954e006f261cc0a535724a4fdc08a (diff) |
CppTools: Turn some classes into pure value types
ProjectInfo, ProjectPart and ProjectUpdateInfo used to carry pointers
to Project and/or Toolchain, even though they were used in contexts
where these pointers were either unsafe to access or not guaranteed to
be valid anymore, which made their use difficult and error-prone.
We turn these classes into pure value types by copying in all relevant
information before the first async operation takes place.
Fixes: QTCREATORBUG-25678
Change-Id: I1914b0dbda6c7dfba6c95e5e92f2d69977755590
Reviewed-by: Jarek Kobus <[email protected]>
Diffstat (limited to 'src/plugins/autotest')
-rw-r--r-- | src/plugins/autotest/autotestunittests.cpp | 19 | ||||
-rw-r--r-- | src/plugins/autotest/gtest/gtesttreeitem.cpp | 4 | ||||
-rw-r--r-- | src/plugins/autotest/loadprojectscenario.cpp | 4 | ||||
-rw-r--r-- | src/plugins/autotest/quick/quicktesttreeitem.cpp | 4 |
4 files changed, 15 insertions, 16 deletions
diff --git a/src/plugins/autotest/autotestunittests.cpp b/src/plugins/autotest/autotestunittests.cpp index 3ce4c69a284..27badd7beb2 100644 --- a/src/plugins/autotest/autotestunittests.cpp +++ b/src/plugins/autotest/autotestunittests.cpp @@ -109,8 +109,7 @@ void AutoTestUnitTests::testCodeParser() QFETCH(int, expectedDataTagsCount); CppTools::Tests::ProjectOpenerAndCloser projectManager; - const CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true, m_kit); - QVERIFY(projectInfo.isValid()); + QVERIFY(projectManager.open(projectFilePath, true, m_kit)); QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished())); QSignalSpy modelUpdateSpy(m_model, SIGNAL(sweepingDone())); @@ -160,8 +159,7 @@ void AutoTestUnitTests::testCodeParserSwitchStartup() CppTools::Tests::ProjectOpenerAndCloser projectManager; for (int i = 0; i < projectFilePaths.size(); ++i) { qDebug() << "Opening project" << projectFilePaths.at(i); - CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePaths.at(i), true, m_kit); - QVERIFY(projectInfo.isValid()); + QVERIFY(projectManager.open(projectFilePaths.at(i), true, m_kit)); QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished())); QSignalSpy modelUpdateSpy(m_model, SIGNAL(sweepingDone())); @@ -208,8 +206,7 @@ void AutoTestUnitTests::testCodeParserGTest() QFETCH(QString, projectFilePath); CppTools::Tests::ProjectOpenerAndCloser projectManager; - CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true, m_kit); - QVERIFY(projectInfo.isValid()); + QVERIFY(projectManager.open(projectFilePath, true, m_kit)); QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished())); QSignalSpy modelUpdateSpy(m_model, SIGNAL(sweepingDone())); @@ -258,8 +255,9 @@ void AutoTestUnitTests::testCodeParserBoostTest() QFETCH(QString, projectFilePath); QFETCH(QString, extension); CppTools::Tests::ProjectOpenerAndCloser projectManager; - CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true, m_kit); - QVERIFY(projectInfo.isValid()); + const CppTools::ProjectInfo::Ptr projectInfo + = projectManager.open(projectFilePath, true, m_kit); + QVERIFY(projectInfo); QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished())); QSignalSpy modelUpdateSpy(m_model, SIGNAL(sweepingDone())); @@ -268,10 +266,7 @@ void AutoTestUnitTests::testCodeParserBoostTest() QCOMPARE(m_model->boostTestNamesCount(), 5); - - auto project = projectInfo.project(); - QVERIFY(project); - const Utils::FilePath basePath = project->projectFilePath().absolutePath(); + const Utils::FilePath basePath = projectInfo->projectRoot(); QVERIFY(!basePath.isEmpty()); QMap<QString, int> expectedSuitesAndTests; diff --git a/src/plugins/autotest/gtest/gtesttreeitem.cpp b/src/plugins/autotest/gtest/gtesttreeitem.cpp index a52b8b63e54..fcdc98316dc 100644 --- a/src/plugins/autotest/gtest/gtesttreeitem.cpp +++ b/src/plugins/autotest/gtest/gtesttreeitem.cpp @@ -524,9 +524,11 @@ QSet<QString> internalTargets(const TestTreeItem &item) QSet<QString> result; const auto cppMM = CppTools::CppModelManager::instance(); const auto projectInfo = cppMM->projectInfo(ProjectExplorer::SessionManager::startupProject()); + if (!projectInfo) + return {}; const Utils::FilePath filePath = item.filePath(); const QString file = filePath.toString(); - const QVector<CppTools::ProjectPart::Ptr> projectParts = projectInfo.projectParts(); + const QVector<CppTools::ProjectPart::Ptr> projectParts = projectInfo->projectParts(); if (projectParts.isEmpty()) return cppMM->dependingInternalTargets(item.filePath()); for (const CppTools::ProjectPart::Ptr &projectPart : projectParts) { diff --git a/src/plugins/autotest/loadprojectscenario.cpp b/src/plugins/autotest/loadprojectscenario.cpp index 40e9173493d..2013d1a5821 100644 --- a/src/plugins/autotest/loadprojectscenario.cpp +++ b/src/plugins/autotest/loadprojectscenario.cpp @@ -92,8 +92,8 @@ bool LoadProjectScenario::loadProject() CppTools::Tests::ProjectOpenerAndCloser projectManager; // This code must trigger a call to PluginManager::finishScenario() at some later point. - const CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true, m_kit); - return projectInfo.isValid(); + const CppTools::ProjectInfo::Ptr projectInfo = projectManager.open(projectFilePath, true, m_kit); + return projectInfo.get(); } } // namespace Internal diff --git a/src/plugins/autotest/quick/quicktesttreeitem.cpp b/src/plugins/autotest/quick/quicktesttreeitem.cpp index 1be0e7153b9..e80432674ff 100644 --- a/src/plugins/autotest/quick/quicktesttreeitem.cpp +++ b/src/plugins/autotest/quick/quicktesttreeitem.cpp @@ -389,7 +389,9 @@ QSet<QString> internalTargets(const Utils::FilePath &proFile) QSet<QString> result; const auto cppMM = CppTools::CppModelManager::instance(); const auto projectInfo = cppMM->projectInfo(ProjectExplorer::SessionManager::startupProject()); - for (const CppTools::ProjectPart::Ptr &projectPart : projectInfo.projectParts()) { + if (!projectInfo) + return {}; + for (const CppTools::ProjectPart::Ptr &projectPart : projectInfo->projectParts()) { if (projectPart->buildTargetType != ProjectExplorer::BuildTargetType::Executable) continue; if (projectPart->projectFile == proFile.toString()) |