forked from qt-creator/qt-creator
CMake: Fix project parsing notification
This builds on top of 08677c0b01 and
fixes one more code path to go through a common entry/exit point.
Change-Id: I1d00fa9242f247028e5d3b0ef3b5fe1d3f4cb03d
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -42,6 +42,7 @@
|
||||
#include <projectexplorer/deploymentdata.h>
|
||||
#include <projectexplorer/headerpath.h>
|
||||
#include <projectexplorer/kitinformation.h>
|
||||
#include <projectexplorer/kitmanager.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/target.h>
|
||||
#include <projectexplorer/toolchain.h>
|
||||
@@ -66,6 +67,11 @@ namespace CMakeProjectManager {
|
||||
|
||||
using namespace Internal;
|
||||
|
||||
static CMakeBuildConfiguration *activeBc(const CMakeProject *p)
|
||||
{
|
||||
return qobject_cast<CMakeBuildConfiguration *>(p->activeTarget() ? p->activeTarget()->activeBuildConfiguration() : nullptr);
|
||||
}
|
||||
|
||||
// QtCreator CMake Generator wishlist:
|
||||
// Which make targets we need to build to get all executables
|
||||
// What is the actual compiler executable
|
||||
@@ -77,27 +83,129 @@ using namespace Internal;
|
||||
CMakeProject::CMakeProject(const FileName &fileName) : Project(Constants::CMAKEMIMETYPE, fileName),
|
||||
m_cppCodeModelUpdater(new CppTools::CppProjectUpdater(this))
|
||||
{
|
||||
m_delayedParsingTimer.setSingleShot(true);
|
||||
|
||||
connect(&m_delayedParsingTimer, &QTimer::timeout,
|
||||
this, [this]() { startParsingProject(PARSE); });
|
||||
|
||||
setId(CMakeProjectManager::Constants::CMAKEPROJECT_ID);
|
||||
|
||||
setProjectContext(Core::Context(CMakeProjectManager::Constants::PROJECTCONTEXT));
|
||||
setProjectLanguages(Core::Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
|
||||
setDisplayName(projectDirectory().fileName());
|
||||
|
||||
connect(this, &Project::activeProjectConfigurationChanged,
|
||||
this, &CMakeProject::handleActiveProjectConfigurationChanged);
|
||||
// Timer:
|
||||
m_delayedParsingTimer.setSingleShot(true);
|
||||
|
||||
subscribeSignal(&CMakeBuildConfiguration::requestReparse,
|
||||
this, [this](CMakeBuildConfiguration *bc, bool isUrgent) {
|
||||
if (bc->isActive()) {
|
||||
m_delayedParsingTimer.setInterval(isUrgent ? 0 : 1000);
|
||||
m_delayedParsingTimer.start();
|
||||
connect(&m_delayedParsingTimer, &QTimer::timeout,
|
||||
this, [this]() { startParsing(m_delayedParsingParameters); });
|
||||
|
||||
// BuildDirManager:
|
||||
connect(&m_buildDirManager, &BuildDirManager::requestReparse,
|
||||
this, &CMakeProject::handleReparseRequest);
|
||||
connect(&m_buildDirManager, &BuildDirManager::dataAvailable,
|
||||
this, [this]() {
|
||||
CMakeBuildConfiguration *bc = activeBc(this);
|
||||
if (bc && bc == m_buildDirManager.buildConfiguration()) {
|
||||
bc->clearError();
|
||||
handleParsingSuccess(bc);
|
||||
}
|
||||
});
|
||||
connect(&m_buildDirManager, &BuildDirManager::errorOccured,
|
||||
this, [this](const QString &msg) {
|
||||
CMakeBuildConfiguration *bc = activeBc(this);
|
||||
if (bc && bc == m_buildDirManager.buildConfiguration()) {
|
||||
bc->setError(msg);
|
||||
handleParsingError(bc);
|
||||
}
|
||||
});
|
||||
connect(&m_buildDirManager, &BuildDirManager::parsingStarted,
|
||||
this, [this]() {
|
||||
CMakeBuildConfiguration *bc = activeBc(this);
|
||||
if (bc && bc == m_buildDirManager.buildConfiguration())
|
||||
bc->clearError(CMakeBuildConfiguration::ForceEnabledChanged::True);
|
||||
});
|
||||
|
||||
// Kit changed:
|
||||
connect(KitManager::instance(), &KitManager::kitUpdated,
|
||||
this, [this](Kit *k) {
|
||||
CMakeBuildConfiguration *bc = activeBc(this);
|
||||
if (!bc || k != bc->target()->kit())
|
||||
return; // not for us...
|
||||
|
||||
// Build configuration has not changed, but Kit settings might have:
|
||||
// reparse and check the configuration, independent of whether the reader has changed
|
||||
m_buildDirManager.setParametersAndRequestParse(
|
||||
BuildDirParameters(bc),
|
||||
BuildDirManager::REPARSE_CHECK_CONFIGURATION,
|
||||
BuildDirManager::REPARSE_CHECK_CONFIGURATION);
|
||||
});
|
||||
|
||||
// Target switched:
|
||||
connect(this, &Project::activeTargetChanged, this, [this]() {
|
||||
CMakeBuildConfiguration *bc = activeBc(this);
|
||||
|
||||
// Target has switched, so the kit has changed, too.
|
||||
// * run cmake with configuration arguments if the reader needs to be switched
|
||||
// * run cmake without configuration arguments if the reader stays
|
||||
m_buildDirManager.setParametersAndRequestParse(
|
||||
BuildDirParameters(bc),
|
||||
BuildDirManager::REPARSE_CHECK_CONFIGURATION,
|
||||
BuildDirManager::REPARSE_CHECK_CONFIGURATION);
|
||||
});
|
||||
|
||||
// BuildConfiguration switched:
|
||||
subscribeSignal(&Target::activeBuildConfigurationChanged, this, [this]() {
|
||||
CMakeBuildConfiguration *bc = activeBc(this);
|
||||
|
||||
// Build configuration has switched:
|
||||
// * Error out if the reader updates, can not happen since all BCs share a target/kit.
|
||||
// * run cmake without configuration arguments if the reader stays
|
||||
m_buildDirManager.setParametersAndRequestParse(
|
||||
BuildDirParameters(bc),
|
||||
BuildDirManager::REPARSE_FAIL,
|
||||
BuildDirManager::REPARSE_CHECK_CONFIGURATION);
|
||||
});
|
||||
|
||||
// BuildConfiguration changed:
|
||||
subscribeSignal(&CMakeBuildConfiguration::environmentChanged, this, [this]() {
|
||||
auto senderBc = qobject_cast<CMakeBuildConfiguration *>(sender());
|
||||
|
||||
if (senderBc && senderBc->isActive()) {
|
||||
// The environment on our BC has changed:
|
||||
// * Error out if the reader updates, can not happen since all BCs share a target/kit.
|
||||
// * run cmake without configuration arguments if the reader stays
|
||||
m_buildDirManager.setParametersAndRequestParse(
|
||||
BuildDirParameters(senderBc),
|
||||
BuildDirManager::REPARSE_FAIL,
|
||||
BuildDirManager::REPARSE_CHECK_CONFIGURATION);
|
||||
}
|
||||
});
|
||||
subscribeSignal(&CMakeBuildConfiguration::buildDirectoryChanged, this, [this]() {
|
||||
auto senderBc = qobject_cast<CMakeBuildConfiguration *>(sender());
|
||||
|
||||
if (senderBc && senderBc->isActive() && senderBc == m_buildDirManager.buildConfiguration()) {
|
||||
// The build directory of our BC has changed:
|
||||
// * Error out if the reader updates, can not happen since all BCs share a target/kit.
|
||||
// * run cmake without configuration arguments if the reader stays
|
||||
// If no configuration exists, then the arguments will get added automatically by
|
||||
// the reader.
|
||||
m_buildDirManager.setParametersAndRequestParse(
|
||||
BuildDirParameters(senderBc),
|
||||
BuildDirManager::REPARSE_FAIL,
|
||||
BuildDirManager::REPARSE_CHECK_CONFIGURATION);
|
||||
}
|
||||
});
|
||||
subscribeSignal(&CMakeBuildConfiguration::configurationForCMakeChanged, this, [this]() {
|
||||
auto senderBc = qobject_cast<CMakeBuildConfiguration *>(sender());
|
||||
|
||||
if (senderBc && senderBc->isActive() && senderBc == m_buildDirManager.buildConfiguration()) {
|
||||
// The CMake configuration has changed on our BC:
|
||||
// * Error out if the reader updates, can not happen since all BCs share a target/kit.
|
||||
// * run cmake with configuration arguments if the reader stays
|
||||
m_buildDirManager.setParametersAndRequestParse(
|
||||
BuildDirParameters(senderBc),
|
||||
BuildDirManager::REPARSE_FAIL,
|
||||
BuildDirManager::REPARSE_FORCE_CONFIGURATION);
|
||||
}
|
||||
});
|
||||
|
||||
// TreeScanner:
|
||||
connect(&m_treeScanner, &TreeScanner::finished, this, &CMakeProject::handleTreeScanningFinished);
|
||||
|
||||
m_treeScanner.setFilter([this](const Utils::MimeType &mimeType, const Utils::FileName &fn) {
|
||||
@@ -148,15 +256,19 @@ CMakeProject::~CMakeProject()
|
||||
|
||||
void CMakeProject::updateProjectData(CMakeBuildConfiguration *bc)
|
||||
{
|
||||
Target *const t = activeTarget();
|
||||
const CMakeBuildConfiguration *aBc = activeBc(this);
|
||||
|
||||
QTC_ASSERT(bc, return);
|
||||
QTC_ASSERT(bc == (t ? t->activeBuildConfiguration() : nullptr), return);
|
||||
QTC_ASSERT(m_treeScanner.isFinished() && !bc->isParsing(), return);
|
||||
QTC_ASSERT(bc == aBc, return);
|
||||
QTC_ASSERT(m_treeScanner.isFinished() && !m_buildDirManager.isParsing(), return);
|
||||
|
||||
Target *t = bc->target();
|
||||
Kit *k = t->kit();
|
||||
|
||||
auto newRoot = bc->generateProjectTree(m_allFiles);
|
||||
bc->setBuildTargets(m_buildDirManager.takeBuildTargets());
|
||||
bc->setConfigurationFromCMake(m_buildDirManager.takeCMakeConfiguration());
|
||||
|
||||
auto newRoot = generateProjectTree(m_allFiles);
|
||||
if (newRoot) {
|
||||
setDisplayName(newRoot->displayName());
|
||||
setRootProjectNode(newRoot);
|
||||
@@ -184,7 +296,7 @@ void CMakeProject::updateProjectData(CMakeBuildConfiguration *bc)
|
||||
}
|
||||
|
||||
CppTools::RawProjectParts rpps;
|
||||
bc->updateCodeModel(rpps);
|
||||
m_buildDirManager.updateCodeModel(rpps);
|
||||
|
||||
for (CppTools::RawProjectPart &rpp : rpps) {
|
||||
// TODO: Set the Qt version only if target actually depends on Qt.
|
||||
@@ -197,6 +309,8 @@ void CMakeProject::updateProjectData(CMakeBuildConfiguration *bc)
|
||||
|
||||
updateQmlJSCodeModel();
|
||||
|
||||
m_buildDirManager.resetData();
|
||||
|
||||
emit fileListChanged();
|
||||
|
||||
emit bc->emitBuildTypeChanged();
|
||||
@@ -220,10 +334,10 @@ void CMakeProject::updateQmlJSCodeModel()
|
||||
if (!bc)
|
||||
return;
|
||||
|
||||
const QList<ConfigModel::DataItem> &cm = bc->completeCMakeConfiguration();
|
||||
foreach (const ConfigModel::DataItem &di, cm) {
|
||||
if (di.key.contains(QStringLiteral("QML_IMPORT_PATH"))) {
|
||||
cmakeImports = di.value;
|
||||
const CMakeConfig &cm = bc->configurationFromCMake();
|
||||
foreach (const CMakeConfigItem &di, cm) {
|
||||
if (di.key.contains("QML_IMPORT_PATH")) {
|
||||
cmakeImports = QString::fromUtf8(di.value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -234,6 +348,16 @@ void CMakeProject::updateQmlJSCodeModel()
|
||||
modelManager->updateProjectInfo(projectInfo, this);
|
||||
}
|
||||
|
||||
CMakeProjectNode *CMakeProject::generateProjectTree(const QList<const FileNode *> &allFiles) const
|
||||
{
|
||||
if (m_buildDirManager.isParsing())
|
||||
return nullptr;
|
||||
|
||||
auto root = std::make_unique<CMakeProjectNode>(projectDirectory());
|
||||
m_buildDirManager.generateProjectTree(root.get(), allFiles);
|
||||
return root ? root.release() : nullptr;
|
||||
}
|
||||
|
||||
bool CMakeProject::needsConfiguration() const
|
||||
{
|
||||
return targets().isEmpty();
|
||||
@@ -264,53 +388,28 @@ void CMakeProject::runCMake()
|
||||
if (isParsing())
|
||||
return;
|
||||
|
||||
startParsingProject(PARSE);
|
||||
CMakeBuildConfiguration *bc = activeBc(this);
|
||||
if (bc) {
|
||||
BuildDirParameters parameters(bc);
|
||||
m_buildDirManager.setParametersAndRequestParse(parameters,
|
||||
BuildDirManager::REPARSE_CHECK_CONFIGURATION,
|
||||
BuildDirManager::REPARSE_CHECK_CONFIGURATION);
|
||||
}
|
||||
}
|
||||
|
||||
void CMakeProject::runCMakeAndScanProjectTree()
|
||||
{
|
||||
if (isParsing())
|
||||
if (!m_treeScanner.isFinished())
|
||||
return;
|
||||
|
||||
startParsingProject(static_cast<DataCollectionAction>(PARSE | SCAN));
|
||||
}
|
||||
|
||||
void CMakeProject::startParsingProject(const CMakeProject::DataCollectionAction action)
|
||||
{
|
||||
const bool runParse = action & PARSE;
|
||||
const bool runScan = action & SCAN;
|
||||
|
||||
CMakeBuildConfiguration *bc = activeTarget()
|
||||
? qobject_cast<CMakeBuildConfiguration *>(activeTarget()->activeBuildConfiguration())
|
||||
: nullptr;
|
||||
if (!bc)
|
||||
return;
|
||||
|
||||
if (!m_treeScanner.isFinished() || m_waitingForScan)
|
||||
return;
|
||||
|
||||
emitParsingStarted();
|
||||
|
||||
m_waitingForParse = runParse;
|
||||
m_waitingForScan = runScan;
|
||||
m_combinedScanAndParseResult = true;
|
||||
|
||||
if (runParse)
|
||||
bc->runCMake();
|
||||
|
||||
if (runScan) {
|
||||
m_treeScanner.asyncScanForFiles(projectDirectory());
|
||||
Core::ProgressManager::addTask(m_treeScanner.future(),
|
||||
tr("Scan \"%1\" project tree").arg(displayName()),
|
||||
"CMake.Scan.Tree");
|
||||
}
|
||||
m_waitingForScan = true;
|
||||
runCMake();
|
||||
}
|
||||
|
||||
void CMakeProject::buildCMakeTarget(const QString &buildTarget)
|
||||
{
|
||||
QTC_ASSERT(!buildTarget.isEmpty(), return);
|
||||
Target *t = activeTarget();
|
||||
auto bc = qobject_cast<CMakeBuildConfiguration *>(t ? t->activeBuildConfiguration() : nullptr);
|
||||
CMakeBuildConfiguration *bc = activeBc(this);
|
||||
if (bc)
|
||||
bc->buildTarget(buildTarget);
|
||||
}
|
||||
@@ -322,15 +421,60 @@ ProjectImporter *CMakeProject::projectImporter() const
|
||||
return m_projectImporter.get();
|
||||
}
|
||||
|
||||
bool CMakeProject::persistCMakeState()
|
||||
{
|
||||
return m_buildDirManager.persistCMakeState();
|
||||
}
|
||||
|
||||
void CMakeProject::clearCMakeCache()
|
||||
{
|
||||
m_buildDirManager.clearCache();
|
||||
}
|
||||
|
||||
QList<CMakeBuildTarget> CMakeProject::buildTargets() const
|
||||
{
|
||||
CMakeBuildConfiguration *bc = nullptr;
|
||||
if (activeTarget())
|
||||
bc = qobject_cast<CMakeBuildConfiguration *>(activeTarget()->activeBuildConfiguration());
|
||||
CMakeBuildConfiguration *bc = activeBc(this);
|
||||
|
||||
return bc ? bc->buildTargets() : QList<CMakeBuildTarget>();
|
||||
}
|
||||
|
||||
void CMakeProject::handleReparseRequest(int reparseParameters)
|
||||
{
|
||||
QTC_ASSERT(!(reparseParameters & BuildDirManager::REPARSE_FAIL), return);
|
||||
if (reparseParameters & BuildDirManager::REPARSE_IGNORE)
|
||||
return;
|
||||
|
||||
m_delayedParsingTimer.setInterval((reparseParameters & BuildDirManager::REPARSE_URGENT) ? 0 : 1000);
|
||||
m_delayedParsingTimer.start();
|
||||
m_delayedParsingParameters = m_delayedParsingParameters | reparseParameters;
|
||||
}
|
||||
|
||||
void CMakeProject::startParsing(int reparseParameters)
|
||||
{
|
||||
m_delayedParsingParameters = BuildDirManager::REPARSE_DEFAULT;
|
||||
|
||||
QTC_ASSERT((reparseParameters & BuildDirManager::REPARSE_FAIL) == 0, return);
|
||||
if (reparseParameters & BuildDirManager::REPARSE_IGNORE)
|
||||
return;
|
||||
|
||||
QTC_ASSERT(activeBc(this), return);
|
||||
|
||||
emitParsingStarted();
|
||||
|
||||
m_waitingForParse = true;
|
||||
m_combinedScanAndParseResult = true;
|
||||
|
||||
if (m_waitingForScan) {
|
||||
QTC_CHECK(m_treeScanner.isFinished());
|
||||
m_treeScanner.asyncScanForFiles(projectDirectory());
|
||||
Core::ProgressManager::addTask(m_treeScanner.future(),
|
||||
tr("Scan \"%1\" project tree").arg(displayName()),
|
||||
"CMake.Scan.Tree");
|
||||
}
|
||||
|
||||
m_buildDirManager.parse(reparseParameters);
|
||||
}
|
||||
|
||||
QStringList CMakeProject::buildTargetTitles(bool runnable) const
|
||||
{
|
||||
const QList<CMakeBuildTarget> targets
|
||||
@@ -361,33 +505,9 @@ bool CMakeProject::setupTarget(Target *t)
|
||||
if (t->buildConfigurations().isEmpty())
|
||||
return false;
|
||||
t->updateDefaultDeployConfigurations();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CMakeProject::handleActiveProjectConfigurationChanged(ProjectConfiguration *pc)
|
||||
{
|
||||
if (auto bc = qobject_cast<CMakeBuildConfiguration *>(pc)) {
|
||||
if (!bc->isActive())
|
||||
return;
|
||||
} else if (!qobject_cast<Target *>(pc)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Target *t : targets()) {
|
||||
for (BuildConfiguration *bc : t->buildConfigurations()) {
|
||||
auto i = qobject_cast<CMakeBuildConfiguration *>(bc);
|
||||
QTC_ASSERT(i, continue);
|
||||
if (i->isActive()) {
|
||||
m_waitingForParse = true;
|
||||
i->maybeForceReparse();
|
||||
} else {
|
||||
i->resetData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CMakeProject::handleTreeScanningFinished()
|
||||
{
|
||||
QTC_CHECK(m_waitingForScan);
|
||||
@@ -395,8 +515,7 @@ void CMakeProject::handleTreeScanningFinished()
|
||||
qDeleteAll(m_allFiles);
|
||||
m_allFiles = Utils::transform(m_treeScanner.release(), [](const FileNode *fn) { return fn; });
|
||||
|
||||
auto t = activeTarget();
|
||||
auto bc = qobject_cast<CMakeBuildConfiguration*>(t ? t->activeBuildConfiguration() : nullptr);
|
||||
CMakeBuildConfiguration *bc = activeBc(this);
|
||||
QTC_ASSERT(bc, return);
|
||||
|
||||
m_combinedScanAndParseResult = m_combinedScanAndParseResult && true;
|
||||
@@ -407,7 +526,7 @@ void CMakeProject::handleTreeScanningFinished()
|
||||
|
||||
void CMakeProject::handleParsingSuccess(CMakeBuildConfiguration *bc)
|
||||
{
|
||||
QTC_CHECK(m_waitingForParse);
|
||||
QTC_ASSERT(m_waitingForParse, return);
|
||||
|
||||
if (!bc || !bc->isActive())
|
||||
return;
|
||||
@@ -626,18 +745,4 @@ void CMakeProject::createGeneratedCodeModelSupport()
|
||||
CppTools::GeneratedCodeModelSupport::update(m_extraCompilers);
|
||||
}
|
||||
|
||||
void CMakeBuildTarget::clear()
|
||||
{
|
||||
executable.clear();
|
||||
makeCommand.clear();
|
||||
workingDirectory.clear();
|
||||
sourceDirectory.clear();
|
||||
title.clear();
|
||||
targetType = UtilityType;
|
||||
includeFiles.clear();
|
||||
compilerOptions.clear();
|
||||
macros.clear();
|
||||
files.clear();
|
||||
}
|
||||
|
||||
} // namespace CMakeProjectManager
|
||||
|
||||
Reference in New Issue
Block a user