diff --git a/src/plugins/autotest/autotestunittests.cpp b/src/plugins/autotest/autotestunittests.cpp index 9a70fb2fdce..089d0848748 100644 --- a/src/plugins/autotest/autotestunittests.cpp +++ b/src/plugins/autotest/autotestunittests.cpp @@ -61,13 +61,20 @@ AutoTestUnitTests::AutoTestUnitTests(TestTreeModel *model, QObject *parent) void AutoTestUnitTests::initTestCase() { const QList allKits = KitManager::kits(); - if (allKits.count() != 1) - QSKIP("This test requires exactly one kit to be present"); - if (auto qtVersion = QtSupport::QtKitAspect::qtVersion(allKits.first())) + if (allKits.count() == 0) + QSKIP("This test requires at least one kit to be present"); + + m_kit = findOr(allKits, nullptr, [](Kit *k) { + return k->isValid() && QtSupport::QtKitAspect::qtVersion(k) != nullptr; + }); + if (!m_kit) + QSKIP("The test requires at least one valid kit with a valid Qt"); + + if (auto qtVersion = QtSupport::QtKitAspect::qtVersion(m_kit)) m_isQt4 = qtVersion->qtVersionString().startsWith('4'); else QSKIP("Could not figure out which Qt version is used for default kit."); - const ToolChain * const toolchain = ToolChainKitAspect::cxxToolChain(allKits.first()); + const ToolChain * const toolchain = ToolChainKitAspect::cxxToolChain(m_kit); if (!toolchain) QSKIP("This test requires that there is a kit with a toolchain."); @@ -99,7 +106,7 @@ void AutoTestUnitTests::testCodeParser() QFETCH(int, expectedDataTagsCount); CppTools::Tests::ProjectOpenerAndCloser projectManager; - const CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true); + const CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true, m_kit); QVERIFY(projectInfo.isValid()); QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished())); @@ -150,7 +157,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); + CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePaths.at(i), true, m_kit); QVERIFY(projectInfo.isValid()); QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished())); @@ -198,7 +205,7 @@ void AutoTestUnitTests::testCodeParserGTest() QFETCH(QString, projectFilePath); CppTools::Tests::ProjectOpenerAndCloser projectManager; - CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true); + CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true, m_kit); QVERIFY(projectInfo.isValid()); QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished())); @@ -247,7 +254,7 @@ void AutoTestUnitTests::testCodeParserBoostTest() QFETCH(QString, projectFilePath); QFETCH(QString, extension); CppTools::Tests::ProjectOpenerAndCloser projectManager; - CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true); + CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true, m_kit); QVERIFY(projectInfo.isValid()); QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished())); diff --git a/src/plugins/autotest/autotestunittests.h b/src/plugins/autotest/autotestunittests.h index 0007875a3e5..0c43432a5bb 100644 --- a/src/plugins/autotest/autotestunittests.h +++ b/src/plugins/autotest/autotestunittests.h @@ -28,6 +28,7 @@ #include namespace CppTools { namespace Tests { class TemporaryCopiedDir; } } +namespace ProjectExplorer { class Kit; } namespace Autotest { @@ -60,6 +61,7 @@ private: CppTools::Tests::TemporaryCopiedDir *m_tmpDir = nullptr; bool m_isQt4 = false; bool m_checkBoost = false; + ProjectExplorer::Kit *m_kit = nullptr; }; } // namespace Internal diff --git a/src/plugins/clangcodemodel/test/clangbatchfileprocessor.cpp b/src/plugins/clangcodemodel/test/clangbatchfileprocessor.cpp index 8556c84b4b0..85312170d97 100644 --- a/src/plugins/clangcodemodel/test/clangbatchfileprocessor.cpp +++ b/src/plugins/clangcodemodel/test/clangbatchfileprocessor.cpp @@ -235,7 +235,7 @@ bool OpenProjectCommand::run() QTC_ASSERT(openProjectSucceeded, return false); Project *project = openProjectSucceeded.project(); - project->configureAsExampleProject(); + project->configureAsExampleProject(nullptr); return CppTools::Tests::TestCase::waitUntilProjectIsFullyOpened(project, timeOutInMs()); } diff --git a/src/plugins/clangtools/clangtoolsunittests.cpp b/src/plugins/clangtools/clangtoolsunittests.cpp index e9df1514769..7696ef7dbdc 100644 --- a/src/plugins/clangtools/clangtoolsunittests.cpp +++ b/src/plugins/clangtools/clangtoolsunittests.cpp @@ -40,6 +40,8 @@ #include #include +#include + #include #include @@ -60,9 +62,16 @@ namespace Internal { void ClangToolsUnitTests::initTestCase() { const QList allKits = KitManager::kits(); - if (allKits.count() != 1) - QSKIP("This test requires exactly one kit to be present"); - const ToolChain *const toolchain = ToolChainKitAspect::cxxToolChain(allKits.first()); + if (allKits.count() == 0) + QSKIP("This test requires at least one kit to be present"); + + m_kit = findOr(allKits, nullptr, [](Kit *k) { + return k->isValid() && QtSupport::QtKitAspect::qtVersion(k) != nullptr; + }); + if (!m_kit) + QSKIP("This test requires at least one valid kit with a valid Qt"); + + const ToolChain *const toolchain = ToolChainKitAspect::cxxToolChain(m_kit); if (!toolchain) QSKIP("This test requires that there is a kit with a toolchain."); @@ -99,14 +108,14 @@ void ClangToolsUnitTests::testProject() QFETCH(int, expectedDiagCount); QFETCH(ClangDiagnosticConfig, diagnosticConfig); if (projectFilePath.contains("mingw")) { - const auto toolchain = ToolChainKitAspect::cxxToolChain(KitManager::kits().constFirst()); + const auto toolchain = ToolChainKitAspect::cxxToolChain(m_kit); if (toolchain->typeId() != ProjectExplorer::Constants::MINGW_TOOLCHAIN_TYPEID) QSKIP("This test is mingw specific, does not run for other toolchains"); } // Open project Tests::ProjectOpenerAndCloser projectManager; - const ProjectInfo projectInfo = projectManager.open(projectFilePath, true); + const ProjectInfo projectInfo = projectManager.open(projectFilePath, true, m_kit); const bool isProjectOpen = projectInfo.isValid(); QVERIFY(isProjectOpen); diff --git a/src/plugins/clangtools/clangtoolsunittests.h b/src/plugins/clangtools/clangtoolsunittests.h index c54a85bf193..87dd5a114e6 100644 --- a/src/plugins/clangtools/clangtoolsunittests.h +++ b/src/plugins/clangtools/clangtoolsunittests.h @@ -32,6 +32,8 @@ class ClangDiagnosticConfig; namespace Tests { class TemporaryCopiedDir; } } // namespace CppTools +namespace ProjectExplorer { class Kit; } + namespace ClangTools { namespace Internal { @@ -55,6 +57,7 @@ private: private: CppTools::Tests::TemporaryCopiedDir *m_tmpDir = nullptr; + ProjectExplorer::Kit *m_kit = nullptr; }; } // namespace Internal diff --git a/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.cpp b/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.cpp index 8b562a97e37..42a5b3028fb 100644 --- a/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.cpp +++ b/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.cpp @@ -445,9 +445,11 @@ Utils::FilePath CompilationDatabaseProject::rootPathFromSettings() const #endif } -void CompilationDatabaseProject::configureAsExampleProject() +void CompilationDatabaseProject::configureAsExampleProject(Kit *kit) { - if (KitManager::defaultKit()) + if (kit) + addTargetForKit(kit); + else if (KitManager::defaultKit()) addTargetForKit(KitManager::defaultKit()); } diff --git a/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.h b/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.h index bb98f5213e9..345b8bb1082 100644 --- a/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.h +++ b/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.h @@ -54,7 +54,7 @@ public: Utils::FilePath rootPathFromSettings() const; private: - void configureAsExampleProject() override; + void configureAsExampleProject(ProjectExplorer::Kit *kit) override; }; class CompilationDatabaseBuildSystem : public ProjectExplorer::BuildSystem diff --git a/src/plugins/cpptools/cpptoolstestcase.cpp b/src/plugins/cpptools/cpptoolstestcase.cpp index 23dc69e681b..817c78993c1 100644 --- a/src/plugins/cpptools/cpptoolstestcase.cpp +++ b/src/plugins/cpptools/cpptoolstestcase.cpp @@ -277,7 +277,8 @@ ProjectOpenerAndCloser::~ProjectOpenerAndCloser() QCoreApplication::processEvents(); } -ProjectInfo ProjectOpenerAndCloser::open(const QString &projectFile, bool configureAsExampleProject) +ProjectInfo ProjectOpenerAndCloser::open(const QString &projectFile, bool configureAsExampleProject, + Kit *kit) { ProjectExplorerPlugin::OpenProjectResult result = ProjectExplorerPlugin::openProject(projectFile); if (!result) { @@ -287,7 +288,7 @@ ProjectInfo ProjectOpenerAndCloser::open(const QString &projectFile, bool config Project *project = result.project(); if (configureAsExampleProject) - project->configureAsExampleProject(); + project->configureAsExampleProject(kit); if (TestCase::waitUntilProjectIsFullyOpened(project)) { m_openProjects.append(project); diff --git a/src/plugins/cpptools/cpptoolstestcase.h b/src/plugins/cpptools/cpptoolstestcase.h index d6e306d255f..aaa94f1e07b 100644 --- a/src/plugins/cpptools/cpptoolstestcase.h +++ b/src/plugins/cpptools/cpptoolstestcase.h @@ -38,7 +38,10 @@ class Snapshot; } namespace Core { class IEditor; } -namespace ProjectExplorer { class Project; } +namespace ProjectExplorer { +class Kit; +class Project; +} namespace TextEditor { class BaseTextEditor; @@ -118,7 +121,8 @@ public: ProjectOpenerAndCloser(); ~ProjectOpenerAndCloser(); // Closes opened projects - ProjectInfo open(const QString &projectFile, bool configureAsExampleProject = false); + ProjectInfo open(const QString &projectFile, bool configureAsExampleProject = false, + ProjectExplorer::Kit *kit = nullptr); private: QList m_openProjects; diff --git a/src/plugins/projectexplorer/project.cpp b/src/plugins/projectexplorer/project.cpp index 7601fb07429..fafa0cc010d 100644 --- a/src/plugins/projectexplorer/project.cpp +++ b/src/plugins/projectexplorer/project.cpp @@ -910,7 +910,7 @@ bool Project::needsBuildConfigurations() const return d->m_needsBuildConfigurations; } -void Project::configureAsExampleProject() +void Project::configureAsExampleProject(Kit * /*kit*/) { } diff --git a/src/plugins/projectexplorer/project.h b/src/plugins/projectexplorer/project.h index 4974e64297a..534d75e65bf 100644 --- a/src/plugins/projectexplorer/project.h +++ b/src/plugins/projectexplorer/project.h @@ -138,7 +138,7 @@ public: virtual bool needsConfiguration() const; bool needsBuildConfigurations() const; - virtual void configureAsExampleProject(); + virtual void configureAsExampleProject(ProjectExplorer::Kit *kit); virtual ProjectImporter *projectImporter() const; diff --git a/src/plugins/qbsprojectmanager/qbsproject.cpp b/src/plugins/qbsprojectmanager/qbsproject.cpp index db8404f1780..51a16e0f6f6 100644 --- a/src/plugins/qbsprojectmanager/qbsproject.cpp +++ b/src/plugins/qbsprojectmanager/qbsproject.cpp @@ -139,10 +139,14 @@ ProjectImporter *QbsProject::projectImporter() const return m_importer; } -void QbsProject::configureAsExampleProject() +void QbsProject::configureAsExampleProject(Kit *kit) { QList infoList; - const QList kits = KitManager::kits(); + QList kits; + if (kit) + kits.append(kit); + else + kits = KitManager::kits(); for (Kit *k : kits) { if (QtSupport::QtKitAspect::qtVersion(k) != nullptr) { if (auto factory = BuildConfigurationFactory::find(k, projectFilePath())) diff --git a/src/plugins/qbsprojectmanager/qbsproject.h b/src/plugins/qbsprojectmanager/qbsproject.h index 7d4a027adf7..13f9803c254 100644 --- a/src/plugins/qbsprojectmanager/qbsproject.h +++ b/src/plugins/qbsprojectmanager/qbsproject.h @@ -64,7 +64,7 @@ public: ProjectExplorer::DeploymentKnowledge deploymentKnowledge() const override; - void configureAsExampleProject() final; + void configureAsExampleProject(ProjectExplorer::Kit *kit) final; private: mutable ProjectExplorer::ProjectImporter *m_importer = nullptr; diff --git a/src/plugins/qmakeprojectmanager/qmakeproject.cpp b/src/plugins/qmakeprojectmanager/qmakeproject.cpp index 8afb8c33b5c..4b39dbbd8d9 100644 --- a/src/plugins/qmakeprojectmanager/qmakeproject.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeproject.cpp @@ -1012,10 +1012,14 @@ void CentralizedFolderWatcher::delayedFolderChanged(const QString &folder) m_buildSystem->updateCodeModels(); } -void QmakeProject::configureAsExampleProject() +void QmakeProject::configureAsExampleProject(Kit *kit) { QList infoList; - const QList kits = KitManager::kits(); + QList kits; + if (kit) + kits.append(kit); + else + kits = KitManager::kits(); for (Kit *k : kits) { if (QtSupport::QtKitAspect::qtVersion(k) != nullptr) { if (auto factory = BuildConfigurationFactory::find(k, projectFilePath())) diff --git a/src/plugins/qmakeprojectmanager/qmakeproject.h b/src/plugins/qmakeprojectmanager/qmakeproject.h index bf2f9ae45d2..a267b76ed81 100644 --- a/src/plugins/qmakeprojectmanager/qmakeproject.h +++ b/src/plugins/qmakeprojectmanager/qmakeproject.h @@ -63,7 +63,7 @@ public: ProjectExplorer::Tasks projectIssues(const ProjectExplorer::Kit *k) const final; - void configureAsExampleProject() final; + void configureAsExampleProject(ProjectExplorer::Kit *kit) final; ProjectExplorer::ProjectImporter *projectImporter() const final;